QωQ Library
QωQ Library is a library modification that greatly simplifies the process of subscribing to events in Fabric. It offers an intuitive way to register various objects, including items and other game elements.
Basic Features
With QωQ Library, object registration becomes simple and concise. Here's how to register a new item:
public static final Registration<Item> ITEMS = new Registration<>(Registry.ITEM, MOD_ID);
public static final Item EXAMPLE_ITEM = ITEMS.register("example_item", () -> new Item(new Item.Settings()));
Important: Don't forget to add the following line to your mod's main class:
@Override
public void onInitialize() {
ItemInit.ITEMS.register();
}
Event Management
The library offers a convenient event subscription system. Create an event handling class as follows:
@ModEvent
public class OnEventHandle {
@SubscribeEvent
public static void onEvent(IEvent event) {
// Your event handling code
}
}
To activate the event system, you need to tell the program where your event classes are located. Add to the main class:
@Override
public void onInitialize() {
ItemInit.ITEMS.register();
EventLoader.initEvent("org.abstruck.qwq.init.event");
}
Note: If your event classes are located in the std.init.event package, they will be subscribed automatically.
Important Warning
NEVER PLACE CLASSES WITH @Mixin ANNOTATION IN THIS FOLDER!
Creating Custom Events
In cases where the library's standard events don't cover your needs, you can create custom events. Here's an example of a custom event handling what happens after breaking a block:
public class AfterBreakEvent implements IEvent {
private final World world;
private final PlayerEntity player;
private final BlockPos pos;
private final BlockState state;
private final BlockEntity blockEntity;
private final ItemStack stack;
public AfterBreakEvent(World world, PlayerEntity player, BlockPos pos,
BlockState state, @Nullable BlockEntity blockEntity, ItemStack stack) {
this.world = world;
this.player = player;
this.pos = pos;
this.state = state;
this.blockEntity = blockEntity;
this.stack = stack;
}
public PlayerEntity getPlayer() {
return player;
}
public BlockPos getPos() {
return pos;
}
public BlockState getState() {
return state;
}
public World getWorld() {
return world;
}
public BlockEntity getBlockEntity() {
return blockEntity;
}
public ItemStack getStack() {
return stack;
}
}
To activate the custom event, you need to implement a Mixin:
@Mixin(Block.class)
public abstract class BlockMixin {
@Inject(method = "afterBreak", at = @At("RETURN"))
public void afterBreak(World world, PlayerEntity player, BlockPos pos, BlockState state,
BlockEntity blockEntity, ItemStack stack, CallbackInfo ci) {
EventManager.onEventAction(() -> new AfterBreakEvent(world, player, pos, state, blockEntity, stack));
}
}