QωQ Library 图标

QωQ Library

作者:rebot | 分类:模组

价格:0 墨喵币 下载量:0 点赞:0 版本 1.2
本资源为搬运资源,原资源地址: https://modrinth.com/mod/qwq-library
资源信息

Minecraft 版本: 1.18.2

平台: fabric

标签: library

资源介绍

issues
forks
stars
license
QωQ Library
This is a library which can subscribe events simply.
It offers a way to Register Objects like items, the following example shows:

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()));

Don't forget to add it into your Main Class:

@Override
public void onInitialize() {
  ItemInit.ITEMS.register();
}

If you want to Subscribe an event, do it like this:

@ModEvent
public class OnEventHandle {
    @SubscribeEvent
    public static void onEvent(IEvent event){
        //todo
    }
}

However, you must tell the program where did you put the class.
In this example, it just like this:

@Override
public void onInitialize() {
  ItemInit.ITEMS.register();
  EventLoader.initEvent("org.abstruck.qwq.init.event");
}

But, if you put your classes in std.init.event, it will be subscribed directly.
WARNING: DO NOT PUT CLASSES WITH @Mixin IN THIS FLODER!!!

Maybe sometimes you can't find an event you want in the library, you can custom a one:

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(){
            reutrn state;
        }

        public World getWorld() {
            return world;
        }

        public BlockEntity getBlockEntity() {
            return blockEntity;
        }

        public ItemStack getStack() {
            return stack;
        }
    }

And don't forget to 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));
    }
}
下载太慢?试试 墨喵加速站,支持 Modrinth 和外网直链高速下载! 用的人越多,下载的越快!
下载与版本
评论(0)
登录 后发表评论。

暂无评论,抢个沙发吧~

举报此资源

请登录后举报

🔥 相关推荐
Nwoof's Wynn Shader

价格:0 墨喵币
下载量:0

查看详情
RusmayARTs

价格:0 墨喵币
下载量:0

查看详情
Squarby's daggers

价格:0 墨喵币
下载量:0

查看详情
SweetMail

价格:0 墨喵币
下载量:0

查看详情