From 5d1286092eac1545f819babbee27244504a212f0 Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Tue, 23 Aug 2022 00:17:48 +0200 Subject: Add Config to override mob drops + some fixes (#8) * Add overrides * GTNHCoreMod custom drops integration * Update buildscript * Bump * EEC blacklist * NEI info * Loops optimization * Warn when 0% loots are detected * Detect looting drops * No * Super rare drops * Keep the same naming * Crash * Fix meta * maybe * Run at least twice * Fix stupid TF Lich boss * Comments * Fix EEC blacklist --- src/main/java/kubatech/api/mobhandler/MobDrop.java | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/main/java/kubatech/api/mobhandler/MobDrop.java (limited to 'src/main/java/kubatech/api/mobhandler') diff --git a/src/main/java/kubatech/api/mobhandler/MobDrop.java b/src/main/java/kubatech/api/mobhandler/MobDrop.java new file mode 100644 index 0000000000..76942b3148 --- /dev/null +++ b/src/main/java/kubatech/api/mobhandler/MobDrop.java @@ -0,0 +1,99 @@ +package kubatech.api.mobhandler; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.util.HashMap; +import kubatech.api.ConstructableItemStack; +import kubatech.api.utils.GSONUtils; +import net.minecraft.item.ItemStack; + +public class MobDrop { + public enum DropType { + Normal, + Rare, + Additional, + Infernal; + private static final DropType[] values = values(); + + public static DropType get(int ordinal) { + return values[ordinal]; + } + } + + @GSONUtils.SkipGSON + public ItemStack stack; + + public ConstructableItemStack reconstructableStack; + public DropType type; + public int chance; + public Integer enchantable; + public HashMap damages; + public boolean lootable = false; + public boolean playerOnly = false; + + private MobDrop() {} + + public MobDrop( + ItemStack stack, + DropType type, + int chance, + Integer enchantable, + HashMap damages, + boolean lootable, + boolean playerOnly) { + this.stack = stack; + this.reconstructableStack = new ConstructableItemStack(stack); + this.type = type; + this.chance = chance; + this.enchantable = enchantable; + this.damages = damages; + this.lootable = lootable; + this.playerOnly = playerOnly; + } + + public void reconstructStack() { + this.stack = reconstructableStack.construct(); + } + + private static final ByteBuf BufHelper = Unpooled.buffer(); + + public void writeToByteBuf(ByteBuf byteBuf) { + BufHelper.clear(); + reconstructableStack.writeToByteBuf(BufHelper); + BufHelper.writeInt(type.ordinal()); + BufHelper.writeInt(chance); + BufHelper.writeBoolean(enchantable != null); + if (enchantable != null) BufHelper.writeInt(enchantable); + BufHelper.writeBoolean(damages != null); + if (damages != null) { + BufHelper.writeInt(damages.size()); + damages.forEach((k, v) -> { + BufHelper.writeInt(k); + BufHelper.writeInt(v); + }); + } + BufHelper.writeBoolean(lootable); + BufHelper.writeBoolean(playerOnly); + byteBuf.writeInt(BufHelper.readableBytes()); + byteBuf.writeBytes(BufHelper); + } + + public static MobDrop readFromByteBuf(ByteBuf byteBuf) { + MobDrop mobDrop = new MobDrop(); + int size = byteBuf.readInt(); + mobDrop.reconstructableStack = ConstructableItemStack.readFromByteBuf(byteBuf); + mobDrop.type = DropType.get(byteBuf.readInt()); + mobDrop.chance = byteBuf.readInt(); + if (byteBuf.readBoolean()) mobDrop.enchantable = byteBuf.readInt(); + else mobDrop.enchantable = null; + if (byteBuf.readBoolean()) { + mobDrop.damages = new HashMap<>(); + int damagessize = byteBuf.readInt(); + for (int i = 0; i < damagessize; i++) mobDrop.damages.put(byteBuf.readInt(), byteBuf.readInt()); + } else mobDrop.damages = null; + mobDrop.lootable = byteBuf.readBoolean(); + mobDrop.playerOnly = byteBuf.readBoolean(); + mobDrop.reconstructStack(); + return mobDrop; + } +} -- cgit