From 705dec10c37a7f878f11aad11ea4615a7c08ec00 Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Thu, 22 Jun 2023 23:48:40 +0200 Subject: Remove Mobs Info NEI page from KubaTech (#82) * Add Mobs Info * Use MobsInfo * Update dependencies.gradle * Update repositories.gradle * Update GT_MetaTileEntity_ExtremeExterminationChamber.java * Update dependencies.gradle --- src/main/java/kubatech/ClientProxy.java | 2 - src/main/java/kubatech/CommonProxy.java | 2 + src/main/java/kubatech/FMLEventHandler.java | 2 +- .../java/kubatech/api/ConstructableItemStack.java | 122 -- .../java/kubatech/api/helpers/EnderIOHelper.java | 42 - src/main/java/kubatech/api/mobhandler/MobDrop.java | 118 -- .../api/network/CustomTileEntityPacket.java | 155 --- .../kubatech/api/network/LoadConfigPacket.java | 94 -- .../tileentity/CustomTileEntityPacketHandler.java | 2 +- src/main/java/kubatech/api/utils/ItemID.java | 104 -- src/main/java/kubatech/api/utils/MobUtils.java | 81 -- src/main/java/kubatech/api/utils/ModUtils.java | 103 -- .../kubatech/client/effect/EntityRenderer.java | 3 +- src/main/java/kubatech/commands/CommandConfig.java | 6 +- .../java/kubatech/commands/CommandCustomDrops.java | 67 - .../java/kubatech/commands/CommandHandler.java | 2 +- src/main/java/kubatech/commands/CommandHelp.java | 2 +- src/main/java/kubatech/commands/CommandTea.java | 2 +- src/main/java/kubatech/config/Config.java | 49 - src/main/java/kubatech/config/OverridesConfig.java | 246 ---- src/main/java/kubatech/kubatech.java | 5 +- .../java/kubatech/loaders/MobHandlerLoader.java | 258 ++++ .../java/kubatech/loaders/MobRecipeLoader.java | 1326 -------------------- src/main/java/kubatech/loaders/RecipeLoader.java | 3 - src/main/java/kubatech/loaders/TCLoader.java | 7 +- src/main/java/kubatech/mixin/Mixin.java | 11 +- .../mixins/minecraft/EnchantmentHelperMixin.java | 40 - src/main/java/kubatech/nei/IMCForNEI.java | 5 +- src/main/java/kubatech/nei/Mob_Handler.java | 615 --------- src/main/java/kubatech/nei/NEI_Config.java | 5 - .../kubatech/network/CustomTileEntityPacket.java | 155 +++ .../java/kubatech/network/LoadConfigPacket.java | 52 + ...MetaTileEntity_ExtremeExterminationChamber.java | 23 +- 33 files changed, 500 insertions(+), 3209 deletions(-) delete mode 100644 src/main/java/kubatech/api/ConstructableItemStack.java delete mode 100644 src/main/java/kubatech/api/helpers/EnderIOHelper.java delete mode 100644 src/main/java/kubatech/api/mobhandler/MobDrop.java delete mode 100644 src/main/java/kubatech/api/network/CustomTileEntityPacket.java delete mode 100644 src/main/java/kubatech/api/network/LoadConfigPacket.java delete mode 100644 src/main/java/kubatech/api/utils/ItemID.java delete mode 100644 src/main/java/kubatech/api/utils/MobUtils.java delete mode 100644 src/main/java/kubatech/commands/CommandCustomDrops.java delete mode 100644 src/main/java/kubatech/config/OverridesConfig.java create mode 100644 src/main/java/kubatech/loaders/MobHandlerLoader.java delete mode 100644 src/main/java/kubatech/loaders/MobRecipeLoader.java delete mode 100644 src/main/java/kubatech/mixin/mixins/minecraft/EnchantmentHelperMixin.java delete mode 100644 src/main/java/kubatech/nei/Mob_Handler.java create mode 100644 src/main/java/kubatech/network/CustomTileEntityPacket.java create mode 100644 src/main/java/kubatech/network/LoadConfigPacket.java (limited to 'src/main/java/kubatech') diff --git a/src/main/java/kubatech/ClientProxy.java b/src/main/java/kubatech/ClientProxy.java index 99e9661e33..4d53d945e4 100644 --- a/src/main/java/kubatech/ClientProxy.java +++ b/src/main/java/kubatech/ClientProxy.java @@ -30,7 +30,6 @@ import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.event.FMLServerStoppedEvent; import cpw.mods.fml.common.event.FMLServerStoppingEvent; import kubatech.api.utils.ModUtils; -import kubatech.loaders.MobRecipeLoader; import kubatech.nei.IMCForNEI; @SuppressWarnings("unused") @@ -72,6 +71,5 @@ public class ClientProxy extends CommonProxy { public void loadComplete(FMLLoadCompleteEvent event) { super.loadComplete(event); - MobRecipeLoader.generateMobRecipeMap(); } } diff --git a/src/main/java/kubatech/CommonProxy.java b/src/main/java/kubatech/CommonProxy.java index 267efdab21..6d54bbf326 100644 --- a/src/main/java/kubatech/CommonProxy.java +++ b/src/main/java/kubatech/CommonProxy.java @@ -39,6 +39,7 @@ import kubatech.api.LoaderReference; import kubatech.commands.CommandHandler; import kubatech.config.Config; import kubatech.loaders.MTLoader; +import kubatech.loaders.MobHandlerLoader; import kubatech.loaders.RecipeLoader; import kubatech.loaders.TCLoader; import kubatech.savedata.PlayerDataManager; @@ -56,6 +57,7 @@ public class CommonProxy { MinecraftForge.EVENT_BUS.register(new PlayerDataManager()); registerItems(); registerBlocks(); + MobHandlerLoader.init(); } public void init(FMLInitializationEvent event) { diff --git a/src/main/java/kubatech/FMLEventHandler.java b/src/main/java/kubatech/FMLEventHandler.java index 27ff42615c..e4d216bde9 100644 --- a/src/main/java/kubatech/FMLEventHandler.java +++ b/src/main/java/kubatech/FMLEventHandler.java @@ -25,7 +25,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.PlayerEvent; import kubatech.api.helpers.UUIDFinder; -import kubatech.api.network.LoadConfigPacket; +import kubatech.network.LoadConfigPacket; import kubatech.savedata.PlayerDataManager; public class FMLEventHandler { diff --git a/src/main/java/kubatech/api/ConstructableItemStack.java b/src/main/java/kubatech/api/ConstructableItemStack.java deleted file mode 100644 index 3e82f64958..0000000000 --- a/src/main/java/kubatech/api/ConstructableItemStack.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * spotless:off - * KubaTech - Gregtech Addon - * Copyright (C) 2022 - 2023 kuba6000 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - * spotless:on - */ - -package kubatech.api; - -import java.nio.charset.StandardCharsets; - -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTSizeTracker; -import net.minecraft.nbt.NBTTagCompound; - -import cpw.mods.fml.common.registry.GameRegistry; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; - -public class ConstructableItemStack { - - public final GameRegistry.UniqueIdentifier itemIdentifier; - public final int meta; - public final int size; - public final NBTTagCompound tagCompound; - - private ConstructableItemStack(GameRegistry.UniqueIdentifier itemIdentifier, int meta, int size, - NBTTagCompound tagCompound) { - this.itemIdentifier = itemIdentifier; - this.meta = meta; - this.size = size; - this.tagCompound = tagCompound; - } - - public ConstructableItemStack(ItemStack stack) { - itemIdentifier = GameRegistry.findUniqueIdentifierFor(stack.getItem()); - meta = stack.getItemDamage(); - size = stack.stackSize; - tagCompound = stack.stackTagCompound; - } - - public ItemStack construct() { - if (itemIdentifier == null) return null; - Item it = GameRegistry.findItem(itemIdentifier.modId, itemIdentifier.name); - if (it == null) return null; - ItemStack stack = new ItemStack(it, size, meta); - stack.stackTagCompound = tagCompound; - return stack; - } - - public boolean isSame(ConstructableItemStack stack, boolean ignoreSize) { - if (!stack.itemIdentifier.modId.equals(itemIdentifier.modId)) return false; - if (!stack.itemIdentifier.name.equals(itemIdentifier.name)) return false; - return ignoreSize || stack.size == size; - } - - private static final ByteBuf BufHelper = Unpooled.buffer(); - - public void writeToByteBuf(ByteBuf byteBuf) { - BufHelper.clear(); - byte[] bytes = itemIdentifier.modId.getBytes(StandardCharsets.UTF_8); - BufHelper.writeInt(bytes.length); - BufHelper.writeBytes(bytes); - bytes = itemIdentifier.name.getBytes(StandardCharsets.UTF_8); - BufHelper.writeInt(bytes.length); - BufHelper.writeBytes(bytes); - BufHelper.writeInt(meta); - BufHelper.writeInt(size); - BufHelper.writeBoolean(tagCompound != null); - if (tagCompound != null) { - try { - bytes = CompressedStreamTools.compress(tagCompound); - } catch (Exception ignored) { - bytes = new byte[0]; - } - BufHelper.writeInt(bytes.length); - BufHelper.writeBytes(bytes); - } - byteBuf.writeInt(BufHelper.readableBytes()); - byteBuf.writeBytes(BufHelper); - } - - public static ConstructableItemStack readFromByteBuf(ByteBuf byteBuf) { - int size = byteBuf.readInt(); - byte[] bytes = new byte[byteBuf.readInt()]; - byteBuf.readBytes(bytes); - String modid = new String(bytes, StandardCharsets.UTF_8); - bytes = new byte[byteBuf.readInt()]; - byteBuf.readBytes(bytes); - String name = new String(bytes, StandardCharsets.UTF_8); - int meta = byteBuf.readInt(); - int stacksize = byteBuf.readInt(); - NBTTagCompound nbtTagCompound = null; - if (byteBuf.readBoolean()) { - bytes = new byte[byteBuf.readInt()]; - byteBuf.readBytes(bytes); - try { - nbtTagCompound = CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(2097152L)); - } catch (Exception ignored) {} - } - return new ConstructableItemStack( - new GameRegistry.UniqueIdentifier(modid + ":" + name), - meta, - stacksize, - nbtTagCompound); - } -} diff --git a/src/main/java/kubatech/api/helpers/EnderIOHelper.java b/src/main/java/kubatech/api/helpers/EnderIOHelper.java deleted file mode 100644 index 63da31e76e..0000000000 --- a/src/main/java/kubatech/api/helpers/EnderIOHelper.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * spotless:off - * KubaTech - Gregtech Addon - * Copyright (C) 2022 - 2023 kuba6000 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - * spotless:on - */ - -package kubatech.api.helpers; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; -import net.minecraft.entity.boss.IBossDisplayData; - -import crazypants.enderio.EnderIO; -import kubatech.api.LoaderReference; - -public class EnderIOHelper { - - public static boolean canEntityBeCapturedWithSoulVial(Entity entity, String entityID) { - if (!LoaderReference.EnderIO) return true; - if (ReflectionHelper.callMethod(EnderIO.itemSoulVessel, "isBlackListed", false, entityID)) - return false; - return crazypants.enderio.config.Config.soulVesselCapturesBosses || !(entity instanceof IBossDisplayData); - } - - public static boolean canEntityBeCapturedWithSoulVial(Entity entity) { - return canEntityBeCapturedWithSoulVial(entity, EntityList.getEntityString(entity)); - } -} diff --git a/src/main/java/kubatech/api/mobhandler/MobDrop.java b/src/main/java/kubatech/api/mobhandler/MobDrop.java deleted file mode 100644 index 9b8b9cd51c..0000000000 --- a/src/main/java/kubatech/api/mobhandler/MobDrop.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * spotless:off - * KubaTech - Gregtech Addon - * Copyright (C) 2022 - 2023 kuba6000 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - * spotless:on - */ - -package kubatech.api.mobhandler; - -import java.util.HashMap; - -import net.minecraft.item.ItemStack; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import kubatech.api.ConstructableItemStack; -import kubatech.api.utils.GSONUtils; - -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; - } -} diff --git a/src/main/java/kubatech/api/network/CustomTileEntityPacket.java b/src/main/java/kubatech/api/network/CustomTileEntityPacket.java deleted file mode 100644 index 67a310ecf5..0000000000 --- a/src/main/java/kubatech/api/network/CustomTileEntityPacket.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * spotless:off - * KubaTech - Gregtech Addon - * Copyright (C) 2022 - 2023 kuba6000 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - * spotless:on - */ - -package kubatech.api.network; - -import java.nio.charset.StandardCharsets; - -import net.minecraft.client.Minecraft; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; - -import cpw.mods.fml.common.network.NetworkRegistry; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import kubatech.api.tileentity.CustomTileEntityPacketHandler; -import kubatech.api.utils.ModUtils; -import kubatech.kubatech; - -public class CustomTileEntityPacket implements IMessage { - - public int w, x, y, z; - public final ByteBuf customdata = Unpooled.buffer(); - - @SuppressWarnings("unused") - public CustomTileEntityPacket() {} - - public CustomTileEntityPacket(TileEntity te, byte[] customdata) { - this.w = te.getWorldObj().provider.dimensionId; - this.x = te.xCoord; - this.y = te.yCoord; - this.z = te.zCoord; - if (customdata != null && customdata.length > 0) this.customdata.writeBytes(customdata); - } - - public void sendToAllAround(int range) { - kubatech.NETWORK.sendToAllAround(this, new NetworkRegistry.TargetPoint(w, x, y, z, range)); - } - - // Helper methods - - public void resetHelperData() { - customdata.clear(); - } - - public void addData(byte[] data) { - customdata.writeBytes(data); - } - - public void addData(byte data) { - customdata.writeByte(data); - } - - public void addData(int data) { - customdata.writeInt(data); - } - - public void addData(String data) { - byte[] bytes = data.getBytes(StandardCharsets.UTF_8); - addData(bytes.length); - addData(bytes); - } - - public void addData(boolean data) { - customdata.writeBoolean(data); - } - - public void getData(byte[] bytes) { - customdata.readBytes(bytes); - } - - public byte[] getData(int len) { - byte[] bytes = new byte[len]; - getData(bytes); - return bytes; - } - - public int getDataInt() { - return customdata.readInt(); - } - - public String getDataString() { - return new String(getData(getDataInt()), StandardCharsets.UTF_8); - } - - public boolean getDataBoolean() { - return customdata.readBoolean(); - } - - @Override - public void fromBytes(ByteBuf buf) { - w = buf.readInt(); - x = buf.readInt(); - y = buf.readInt(); - z = buf.readInt(); - customdata.clear(); - buf.readBytes(customdata, buf.readInt()); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(w); - buf.writeInt(x); - buf.writeInt(y); - buf.writeInt(z); - buf.writeInt(customdata.readableBytes()); - buf.writeBytes(customdata); - } - - public static class Handler implements IMessageHandler { - - @Override - public IMessage onMessage(CustomTileEntityPacket message, MessageContext ctx) { - if (!ModUtils.isClientThreaded()) return null; - Minecraft mc = Minecraft.getMinecraft(); - if (mc == null) return null; - if (mc.thePlayer == null) return null; - World w = mc.thePlayer.getEntityWorld(); - if (w == null) return null; - if (message.w != w.provider.dimensionId) return null; - TileEntity e = w.getTileEntity(message.x, message.y, message.z); - if (e == null || e.isInvalid()) return null; - if (e instanceof IGregTechTileEntity && !((IGregTechTileEntity) e).isInvalidTileEntity()) { - IMetaTileEntity mte = ((IGregTechTileEntity) e).getMetaTileEntity(); - if (mte == null) return null; - if (!(mte instanceof CustomTileEntityPacketHandler)) return null; - ((CustomTileEntityPacketHandler) mte).HandleCustomPacket(message); - return null; - } else if (!(e instanceof CustomTileEntityPacketHandler)) return null; - ((CustomTileEntityPacketHandler) e).HandleCustomPacket(message); - return null; - } - } -} diff --git a/src/main/java/kubatech/api/network/LoadConfigPacket.java b/src/main/java/kubatech/api/network/LoadConfigPacket.java deleted file mode 100644 index be3d0b803c..0000000000 --- a/src/main/java/kubatech/api/network/LoadConfigPacket.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * spotless:off - * KubaTech - Gregtech Addon - * Copyright (C) 2022 - 2023 kuba6000 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - * spotless:on - */ - -package kubatech.api.network; - -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.HashSet; - -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import io.netty.buffer.ByteBuf; -import kubatech.config.Config; -import kubatech.config.OverridesConfig; -import kubatech.kubatech; -import kubatech.loaders.MobRecipeLoader; - -public class LoadConfigPacket implements IMessage { - - public static final LoadConfigPacket instance = new LoadConfigPacket(); - - public final HashSet mobsToLoad = new HashSet<>(); - public final HashMap mobsOverrides = new HashMap<>(); - - @Override - public void fromBytes(ByteBuf buf) { - if (!buf.readBoolean()) mobsToLoad.clear(); - else { - mobsToLoad.clear(); - int mobssize = buf.readInt(); - for (int i = 0; i < mobssize; i++) { - byte[] sbytes = new byte[buf.readInt()]; - buf.readBytes(sbytes); - mobsToLoad.add(new String(sbytes, StandardCharsets.UTF_8)); - } - int overridessize = buf.readInt(); - for (int i = 0; i < overridessize; i++) { - byte[] sbytes = new byte[buf.readInt()]; - buf.readBytes(sbytes); - mobsOverrides - .put(new String(sbytes, StandardCharsets.UTF_8), OverridesConfig.MobOverride.readFromByteBuf(buf)); - } - } - } - - @Override - public void toBytes(ByteBuf buf) { - if (!Config.MobHandler.mobHandlerEnabled) buf.writeBoolean(false); - else { - buf.writeBoolean(true); - buf.writeInt(mobsToLoad.size()); - mobsToLoad.forEach(s -> { - byte[] sbytes = s.getBytes(StandardCharsets.UTF_8); - buf.writeInt(sbytes.length); - buf.writeBytes(sbytes); - }); - buf.writeInt(mobsOverrides.size()); - mobsOverrides.forEach((k, v) -> { - byte[] sbytes = k.getBytes(StandardCharsets.UTF_8); - buf.writeInt(sbytes.length); - buf.writeBytes(sbytes); - v.writeToByteBuf(buf); - }); - } - } - - public static class Handler implements IMessageHandler { - - @Override - public IMessage onMessage(LoadConfigPacket message, MessageContext ctx) { - kubatech.info("Received Mob Handler config, parsing"); - MobRecipeLoader.processMobRecipeMap(message.mobsToLoad, message.mobsOverrides); - return null; - } - } -} diff --git a/src/main/java/kubatech/api/tileentity/CustomTileEntityPacketHandler.java b/src/main/java/kubatech/api/tileentity/CustomTileEntityPacketHandler.java index 82343dd4ea..98de36150f 100644 --- a/src/main/java/kubatech/api/tileentity/CustomTileEntityPacketHandler.java +++ b/src/main/java/kubatech/api/tileentity/CustomTileEntityPacketHandler.java @@ -20,7 +20,7 @@ package kubatech.api.tileentity; -import kubatech.api.network.CustomTileEntityPacket; +import kubatech.network.CustomTileEntityPacket; public interface CustomTileEntityPacketHandler { diff --git a/src/main/java/kubatech/api/utils/ItemID.java b/src/main/java/kubatech/api/utils/ItemID.java deleted file mode 100644 index 819b08e572..0000000000 --- a/src/main/java/kubatech/api/utils/ItemID.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * spotless:off - * KubaTech - Gregtech Addon - * Copyright (C) 2022 - 2023 kuba6000 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - * spotless:on - */ - -package kubatech.api.utils; - -import java.util.Objects; - -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -public class ItemID { - - private final Item item; - private final int count; - private final int meta; - private final NBTTagCompound tag; - private final boolean ignorecount; - private final boolean ignoremeta; - private final boolean ignorenbt; - - public static ItemID create(ItemStack stack) { - return new ItemID(stack, true, true, true, true); // ignore count by default - } - - public static ItemID create(ItemStack stack, boolean ignorecount) { - return new ItemID(stack, ignorecount, false, false, true); - } - - public static ItemID create(ItemStack stack, boolean ignorecount, boolean ignoremeta) { - return new ItemID(stack, ignorecount, ignoremeta, false, true); - } - - public static ItemID create(ItemStack stack, boolean ignorecount, boolean ignoremeta, boolean ignorenbt) { - return new ItemID(stack, ignorecount, ignoremeta, ignorenbt, true); - } - - public static ItemID create_NoCopy(ItemStack stack) { - return new ItemID(stack, true, false, false, false); // ignore count by default - } - - public static ItemID create_NoCopy(ItemStack stack, boolean ignorecount) { - return new ItemID(stack, ignorecount, false, false, false); - } - - public static ItemID create_NoCopy(ItemStack stack, boolean ignorecount, boolean ignoremeta) { - return new ItemID(stack, ignorecount, ignoremeta, false, false); - } - - public static ItemID create_NoCopy(ItemStack stack, boolean ignorecount, boolean ignoremeta, boolean ignorenbt) { - return new ItemID(stack, ignorecount, ignoremeta, ignorenbt, false); - } - - private ItemID(ItemStack stack, boolean ignorecount, boolean ignoremeta, boolean ignorenbt, boolean createcopy) { - this.ignorecount = ignorecount; - this.ignoremeta = ignoremeta; - this.ignorenbt = ignorenbt; - item = stack.getItem(); - count = ignorecount ? 0 : stack.stackSize; - meta = ignoremeta ? 0 : stack.getItemDamage(); - tag = ignorenbt ? null : (createcopy ? (NBTTagCompound) stack.stackTagCompound.copy() : stack.stackTagCompound); - } - - @Override - public int hashCode() { - return Objects.hash(item, count, meta, tag); - } - - @Override - public boolean equals(Object obj) { - if (obj == null) return false; - if (obj == this) return true; - if (obj instanceof ItemID) return obj.hashCode() == this.hashCode(); - if (obj instanceof ItemStack) { - if (!item.equals(((ItemStack) obj).getItem())) return false; - if (!ignorecount) if (count != ((ItemStack) obj).stackSize) return false; - if (!ignoremeta) if (meta != ((ItemStack) obj).getItemDamage()) return false; - if (!ignorenbt) { - if (tag == null) - return ((ItemStack) obj).stackTagCompound == null || ((ItemStack) obj).stackTagCompound.hasNoTags(); - return tag.equals(((ItemStack) obj).stackTagCompound); - } - return true; - } - return false; - } -} diff --git a/src/main/java/kubatech/api/utils/MobUtils.java b/src/main/java/kubatech/api/utils/MobUtils.java deleted file mode 100644 index d3ec59757a..0000000000 --- a/src/main/java/kubatech/api/utils/MobUtils.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * spotless:off - * KubaTech - Gregtech Addon - * Copyright (C) 2022 - 2023 kuba6000 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - * spotless:on - */ - -package kubatech.api.utils; - -import net.minecraft.client.model.ModelBase; -import net.minecraft.client.model.ModelBox; -import net.minecraft.client.model.ModelRenderer; -import net.minecraft.client.renderer.entity.Render; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.client.renderer.entity.RendererLivingEntity; -import net.minecraft.entity.EntityLiving; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import kubatech.mixin.mixins.minecraft.RendererLivingEntityAccessor; - -public class MobUtils { - - @SideOnly(Side.CLIENT) - public static float getDesiredScale(EntityLiving e, float desiredHeight) { - return getDesiredScale(getMobHeight(e), desiredHeight); - } - - @SideOnly(Side.CLIENT) - public static float getDesiredScale(float entityHeight, float desiredHeight) { - return desiredHeight / entityHeight; - } - - @SideOnly(Side.CLIENT) - public static float getMobHeight(EntityLiving e) { - try { - float eheight = e.height; - float ewidth = e.width; - Render r = RenderManager.instance.getEntityRenderObject(e); - if (r instanceof RendererLivingEntity) { - ModelBase mainModel = ((RendererLivingEntityAccessor) r).getMainModel(); - for (Object box : mainModel.boxList) { - if (box instanceof ModelRenderer) { - float minY = 999f; - float minX = 999f; - float maxY = -999f; - float maxX = -999f; - for (Object cube : ((ModelRenderer) box).cubeList) { - if (cube instanceof ModelBox) { - if (minY > ((ModelBox) cube).posY1) minY = ((ModelBox) cube).posY1; - if (minX > ((ModelBox) cube).posX1) minX = ((ModelBox) cube).posX1; - if (maxY < ((ModelBox) cube).posY2) maxY = ((ModelBox) cube).posY2; - if (maxX < ((ModelBox) cube).posX2) maxX = ((ModelBox) cube).posX2; - } - } - float cubeheight = (maxY - minY) / 10f; - float cubewidth = (maxX - minX) / 10f; - if (eheight < cubeheight) eheight = cubeheight; - if (ewidth < cubewidth) ewidth = cubewidth; - } - } - } - return eheight; - } catch (Exception ex) { - return 1f; - } - } -} diff --git a/src/main/java/kubatech/api/utils/ModUtils.java b/src/main/java/kubatech/api/utils/ModUtils.java index 61352cce9d..28165adacf 100644 --- a/src/main/java/kubatech/api/utils/ModUtils.java +++ b/src/main/java/kubatech/api/utils/ModUtils.java @@ -20,21 +20,9 @@ package kubatech.api.utils; -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.bind.DatatypeConverter; - import net.minecraft.launchwrapper.Launch; import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.ModContainer; import kubatech.kubatech; public class ModUtils { @@ -48,95 +36,4 @@ public class ModUtils { .getEffectiveSide() .isClient(); } - - @FunctionalInterface - public interface TriConsumer { - - void accept(T t, U u, V v); - } - - private static final HashMap classNamesToModIDs = new HashMap<>(); - private static final Map.Entry emptyEntry = new AbstractMap.SimpleEntry<>("", ""); - - public static String getModNameFromClassName(String classname) { - if (classNamesToModIDs.size() == 0) { - classNamesToModIDs.put("net.minecraft", "Minecraft"); - Loader.instance() - .getActiveModList() - .forEach(m -> { - Object Mod = m.getMod(); - if (Mod != null) { - Package modPackage = Mod.getClass() - .getPackage(); - if (modPackage == null) { // HOW CAN THIS EVEN HAPPEN ?! - kubatech.warn("Mod " + m.getModId() + " package is not loaded yet!"); - return; - } - classNamesToModIDs.put(modPackage.getName(), m.getName()); - } - }); - } - return classNamesToModIDs.entrySet() - .stream() - .filter(e -> classname.startsWith(e.getKey())) - .findAny() - .orElse(emptyEntry) - .getValue(); - } - - private static String modListVersion = null; - - public static String getModListVersion() { - if (modListVersion != null) return modListVersion; - @SuppressWarnings("unchecked") - ArrayList modlist = (ArrayList) ((ArrayList) Loader.instance() - .getActiveModList()).clone(); - String sortedList = modlist.stream() - .filter(m -> m.getMod() != null) - .sorted(Comparator.comparing(ModContainer::getModId)) - .collect( - StringBuilder::new, - (a, b) -> a.append(b.getModId()) - .append(b.getVersion()), - (a, b) -> a.append(", ") - .append(b)) - .toString(); - try { - MessageDigest md = MessageDigest.getInstance("MD5"); - modListVersion = DatatypeConverter.printHexBinary(md.digest(sortedList.getBytes(StandardCharsets.UTF_8))) - .toUpperCase(); - return modListVersion; - } catch (Exception e) { - modListVersion = sortedList; - return sortedList; - } - } - - private static String modListVersionIgnoringModVersions = null; - - public static String getModListVersionIgnoringModVersions() { - if (modListVersionIgnoringModVersions != null) return modListVersionIgnoringModVersions; - @SuppressWarnings("unchecked") - ArrayList modlist = (ArrayList) ((ArrayList) Loader.instance() - .getActiveModList()).clone(); - String sortedList = modlist.stream() - .filter(m -> m.getMod() != null) - .sorted(Comparator.comparing(ModContainer::getModId)) - .collect( - StringBuilder::new, - (a, b) -> a.append(b.getModId()), - (a, b) -> a.append(", ") - .append(b)) - .toString(); - try { - MessageDigest md = MessageDigest.getInstance("MD5"); - modListVersionIgnoringModVersions = DatatypeConverter - .printHexBinary(md.digest(sortedList.getBytes(StandardCharsets.UTF_8))) - .toUpperCase(); - return modListVersionIgnoringModVersions; - } catch (Exception e) { - modListVersionIgnoringModVersions = sortedList; - return sortedList; - } - } } diff --git a/src/main/java/kubatech/client/effect/EntityRenderer.java b/src/main/java/kubatech/client/effect/EntityRenderer.java index 0691dc07ce..247b6ba788 100644 --- a/src/main/java/kubatech/client/effect/EntityRenderer.java +++ b/src/main/java/kubatech/client/effect/EntityRenderer.java @@ -41,10 +41,11 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import org.lwjgl.util.glu.GLU; +import com.kuba6000.mobsinfo.api.utils.MobUtils; + import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import kubatech.Tags; -import kubatech.api.utils.MobUtils; import kubatech.config.Config; @SideOnly(Side.CLIENT) diff --git a/src/main/java/kubatech/commands/CommandConfig.java b/src/main/java/kubatech/commands/CommandConfig.java index cf43bc88ba..04d4420314 100644 --- a/src/main/java/kubatech/commands/CommandConfig.java +++ b/src/main/java/kubatech/commands/CommandConfig.java @@ -31,10 +31,9 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.util.ChatComponentText; import net.minecraft.util.StatCollector; -import kubatech.api.network.LoadConfigPacket; import kubatech.config.Config; import kubatech.kubatech; -import kubatech.loaders.MobRecipeLoader; +import kubatech.network.LoadConfigPacket; @CommandHandler.ChildCommand public class CommandConfig extends CommandBase { @@ -48,7 +47,7 @@ public class CommandConfig extends CommandBase { final String key; Translations() { - key = "command.config." + this.name() + key = "kubatech.command.config." + this.name() .toLowerCase(); } @@ -93,7 +92,6 @@ public class CommandConfig extends CommandBase { return; } Config.synchronizeConfiguration(); - MobRecipeLoader.processMobRecipeMap(); MinecraftServer.getServer() .getConfigurationManager().playerEntityList.forEach(p -> { if (!(p instanceof EntityPlayerMP)) return; diff --git a/src/main/java/kubatech/commands/CommandCustomDrops.java b/src/main/java/kubatech/commands/CommandCustomDrops.java deleted file mode 100644 index 80148eb796..0000000000 --- a/src/main/java/kubatech/commands/CommandCustomDrops.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * spotless:off - * KubaTech - Gregtech Addon - * Copyright (C) 2022 - 2023 kuba6000 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - * spotless:on - */ - -package kubatech.commands; - -import java.io.File; - -import net.minecraft.command.CommandBase; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; - -import kubatech.api.utils.ModUtils; -import kubatech.loaders.MobRecipeLoader; - -@CommandHandler.ChildCommand -public class CommandCustomDrops extends CommandBase { - - @Override - public String getCommandName() { - return "customdrops"; - } - - @Override - public String getCommandUsage(ICommandSender p_71518_1_) { - return "customdrops"; - } - - @Override - public int getRequiredPermissionLevel() { - return 4; - } - - @Override - public void processCommand(ICommandSender p_71515_1_, String[] p_71515_2_) { - - if (!ModUtils.isClientSided) { - p_71515_1_ - .addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "This command is single-player only!")); - return; - } - - File f = MobRecipeLoader.makeCustomDrops(); - - if (f == null) { - p_71515_1_.addChatMessage( - new ChatComponentText(EnumChatFormatting.RED + "There was an error! Look in the console")); - } else p_71515_1_.addChatMessage(new ChatComponentText(f.getAbsolutePath())); - } -} diff --git a/src/main/java/kubatech/commands/CommandHandler.java b/src/main/java/kubatech/commands/CommandHandler.java index 89f1db7429..599d690f21 100644 --- a/src/main/java/kubatech/commands/CommandHandler.java +++ b/src/main/java/kubatech/commands/CommandHandler.java @@ -56,7 +56,7 @@ public class CommandHandler extends CommandBase { final String key; Translations() { - key = "commandhandler." + this.name() + key = "kubatech.commandhandler." + this.name() .toLowerCase(); } diff --git a/src/main/java/kubatech/commands/CommandHelp.java b/src/main/java/kubatech/commands/CommandHelp.java index d7e9fbee59..49a31bc829 100644 --- a/src/main/java/kubatech/commands/CommandHelp.java +++ b/src/main/java/kubatech/commands/CommandHelp.java @@ -39,7 +39,7 @@ public class CommandHelp extends CommandBase { final String key; Translations() { - key = "command.help." + this.name() + key = "kubatech.command.help." + this.name() .toLowerCase(); } diff --git a/src/main/java/kubatech/commands/CommandTea.java b/src/main/java/kubatech/commands/CommandTea.java index 64412f8ef3..c37fabab81 100644 --- a/src/main/java/kubatech/commands/CommandTea.java +++ b/src/main/java/kubatech/commands/CommandTea.java @@ -53,7 +53,7 @@ public class CommandTea extends CommandBase { final String key; Translations() { - key = "command.tea." + this.name() + key = "kubatech.command.tea." + this.name() .toLowerCase(); } diff --git a/src/main/java/kubatech/config/Config.java b/src/main/java/kubatech/config/Config.java index 6508063faf..1976e76949 100644 --- a/src/main/java/kubatech/config/Config.java +++ b/src/main/java/kubatech/config/Config.java @@ -51,59 +51,10 @@ public class Config { public static class MobHandler { - public static boolean mobHandlerEnabled = true; - - public enum _CacheRegenerationTrigger { - - Never, - ModAdditionRemoval, - ModAdditionRemovalChange, - Always; - - public static _CacheRegenerationTrigger get(int oridinal) { - return values()[oridinal]; - } - } - - public static _CacheRegenerationTrigger regenerationTrigger = _CacheRegenerationTrigger.ModAdditionRemovalChange; - public static boolean includeEmptyMobs = true; - public static String[] mobBlacklist; public static double playerOnlyDropsModifier = .1d; private static void load(Configuration configuration) { Category category = Category.MOB_HANDLER; - mobHandlerEnabled = configuration - .get(category.get(), "Enabled", true, "Enable \"Mob Drops\" NEI page and Extreme Extermination Chamber") - .getBoolean(); - StringBuilder c = new StringBuilder("When will cache regeneration trigger? "); - for (_CacheRegenerationTrigger value : _CacheRegenerationTrigger.values()) c.append(value.ordinal()) - .append(" - ") - .append(value.name()) - .append(", "); - regenerationTrigger = _CacheRegenerationTrigger.get( - configuration - .get( - category.get(), - "CacheRegenerationTrigger", - _CacheRegenerationTrigger.ModAdditionRemovalChange.ordinal(), - c.toString()) - .getInt()); - includeEmptyMobs = configuration - .get(category.get(), "IncludeEmptyMobs", true, "Include mobs that have no drops in NEI") - .getBoolean(); - mobBlacklist = configuration - .get( - category.get(), - "MobBlacklist", - new String[] { "Giant", "Thaumcraft.TravelingTrunk", "chisel.snowman", "OpenBlocks.Luggage", - "OpenBlocks.MiniMe", "SpecialMobs.SpecialCreeper", "SpecialMobs.SpecialZombie", - "SpecialMobs.SpecialPigZombie", "SpecialMobs.SpecialSlime", "SpecialMobs.SpecialSkeleton", - "SpecialMobs.SpecialEnderman", "SpecialMobs.SpecialCaveSpider", "SpecialMobs.SpecialGhast", - "SpecialMobs.SpecialWitch", "SpecialMobs.SpecialSpider", "TwilightForest.HydraHead", - "TwilightForest.RovingCube", "TwilightForest.Harbinger Cube", "TwilightForest.Adherent", - "SpecialMobs.SpecialSilverfish", }, - "These mobs will be skipped when generating recipe map") - .getStringList(); playerOnlyDropsModifier = configuration .get( category.get(), diff --git a/src/main/java/kubatech/config/OverridesConfig.java b/src/main/java/kubatech/config/OverridesConfig.java deleted file mode 100644 index 6547854557..0000000000 --- a/src/main/java/kubatech/config/OverridesConfig.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * spotless:off - * KubaTech - Gregtech Addon - * Copyright (C) 2022 - 2023 kuba6000 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - * spotless:on - */ - -package kubatech.config; - -import java.io.File; -import java.io.Reader; -import java.io.Writer; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import net.minecraft.entity.EntityList; -import net.minecraft.entity.EntityLiving; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.JsonToNBT; -import net.minecraft.nbt.NBTTagCompound; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.dreammaster.main.MainRegistry; -import com.dreammaster.modcustomdrops.CustomDrops; -import com.google.common.io.Files; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; - -import cpw.mods.fml.common.registry.GameRegistry; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import kubatech.Tags; -import kubatech.api.ConstructableItemStack; -import kubatech.api.LoaderReference; -import kubatech.api.helpers.ReflectionHelper; -import kubatech.api.mobhandler.MobDrop; -import kubatech.api.utils.GSONUtils; - -public class OverridesConfig { - - private static final Logger LOG = LogManager.getLogger(Tags.MODID + "[Config-Overrides]"); - - public static class MobDropSimplified { - - @GSONUtils.SkipGSON - ItemStack stack; - - ConstructableItemStack reconstructableStack; - MobDrop.DropType type; - - private MobDropSimplified() {} - - public MobDropSimplified(ItemStack stack, MobDrop.DropType type) { - reconstructableStack = new ConstructableItemStack(stack); - this.type = type; - } - - public void reconstructStack() { - stack = reconstructableStack.construct(); - } - - public boolean isMatching(MobDrop drop) { - return reconstructableStack.isSame(drop.reconstructableStack, true); - } - - private static final ByteBuf BufHelper = Unpooled.buffer(); - - public void writeToByteBuf(ByteBuf byteBuf) { - BufHelper.clear(); - reconstructableStack.writeToByteBuf(BufHelper); - BufHelper.writeInt(type.ordinal()); - byteBuf.writeInt(BufHelper.readableBytes()); - byteBuf.writeBytes(BufHelper); - } - - public static MobDropSimplified readFromByteBuf(ByteBuf byteBuf) { - MobDropSimplified mobDropSimplified = new MobDropSimplified(); - int size = byteBuf.readInt(); - mobDropSimplified.reconstructableStack = ConstructableItemStack.readFromByteBuf(byteBuf); - mobDropSimplified.type = MobDrop.DropType.get(byteBuf.readInt()); - mobDropSimplified.reconstructStack(); - return mobDropSimplified; - } - } - - public static class MobOverride { - - public boolean removeAll = false; - public final List additions = new ArrayList<>(); - public final List removals = new ArrayList<>(); - - private static final ByteBuf BufHelper = Unpooled.buffer(); - - public void writeToByteBuf(ByteBuf byteBuf) { - BufHelper.clear(); - BufHelper.writeBoolean(removeAll); - BufHelper.writeInt(additions.size()); - additions.forEach(drop -> drop.writeToByteBuf(BufHelper)); - BufHelper.writeInt(removals.size()); - removals.forEach(drop -> drop.writeToByteBuf(BufHelper)); - byteBuf.writeInt(BufHelper.readableBytes()); - byteBuf.writeBytes(BufHelper); - } - - public static MobOverride readFromByteBuf(ByteBuf byteBuf) { - int size = byteBuf.readInt(); - MobOverride mobOverride = new MobOverride(); - mobOverride.removeAll = byteBuf.readBoolean(); - int additionssize = byteBuf.readInt(); - for (int i = 0; i < additionssize; i++) mobOverride.additions.add(MobDrop.readFromByteBuf(byteBuf)); - int removalssize = byteBuf.readInt(); - for (int i = 0; i < removalssize; i++) mobOverride.removals.add(MobDropSimplified.readFromByteBuf(byteBuf)); - return mobOverride; - } - } - - public static Map overrides = new HashMap<>(); - private static File overrideFile = null; - - private static final Gson gson = GSONUtils.GSON_BUILDER_PRETTY.create(); - - @SuppressWarnings("UnstableApiUsage") - public static void LoadConfig() { - LOG.info("Loading Config"); - if (overrideFile == null) overrideFile = Config.getConfigFile("MobOverrides.json"); - if (!overrideFile.exists()) writeExampleFile(); - Reader reader = null; - try { - reader = Files.newReader(overrideFile, StandardCharsets.UTF_8); - overrides = gson.fromJson(reader, new TypeToken>() {}.getType()); - overrides.remove("ExampleMob"); - overrides.values() - .forEach(o -> o.additions.forEach(MobDrop::reconstructStack)); - if (LoaderReference.GTNHCoreMod) { - LOG.info("Detected GTNH Core Mod, parsing custom drops from there."); - CustomDrops coredrops = ReflectionHelper - .getField(MainRegistry.Module_CustomDrops, "_mCustomDrops", null); - if (coredrops != null) { - @SuppressWarnings("unchecked") - ArrayList customdrops = (ArrayList) ((ArrayList) coredrops - .getCustomDrops()).clone(); - for (CustomDrops.CustomDrop customdrop : customdrops) { - try { - Class eclass = Class.forName(customdrop.getEntityName()); - if (!EntityLiving.class.isAssignableFrom(eclass)) continue; - String ename = (String) EntityList.classToStringMapping.get(eclass); - if (ename == null) continue; - MobOverride override = overrides.computeIfAbsent(ename, k -> new MobOverride()); - for (CustomDrops.CustomDrop.Drop drop : customdrop.getDrops()) { - String[] parts = drop.getItemName() - .split(":"); - ItemStack stack = GameRegistry.findItemStack(parts[0], parts[1], 1); - if (stack == null) continue; - if (parts.length > 2) stack.setItemDamage(Integer.parseInt(parts[2])); - String pNBT = ReflectionHelper.getField(drop, "mTag", null); - if (pNBT != null && !pNBT.isEmpty()) { - try { - stack.stackTagCompound = (NBTTagCompound) JsonToNBT.func_150315_a(pNBT); - } catch (Exception ignored) {} - } - int chance = drop.getChance() * 100; - int amount = drop.getAmount(); - if (drop.getIsRandomAmount()) { - // average chance formula - // chance *= ((((amount * (amount + 1d)) / 2d)) + 1d) / (amount + 1d); - chance *= (2d + (amount * amount) + amount) / (2d * (amount + 1d)); - amount = 1; - if (chance > 10000) { - int div = (int) Math.ceil(chance / 10000d); - amount *= div; - chance /= div; - } - } - stack.stackSize = amount; - // Drops from coremod are player only - override.additions - .add(new MobDrop(stack, MobDrop.DropType.Normal, chance, null, null, false, true)); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - if (reader != null) try { - reader.close(); - } catch (Exception ignored) {} - } - } - - @SuppressWarnings("UnstableApiUsage") - private static void writeExampleFile() { - LOG.info("No config has been detected, writing an example one"); - Writer writer = null; - try { - writer = Files.newWriter(overrideFile, StandardCharsets.UTF_8); - Map example = new HashMap<>(1); - MobOverride ex1 = new MobOverride(); - ex1.removals.add(new MobDropSimplified(new ItemStack(Items.rotten_flesh, 1), MobDrop.DropType.Normal)); - HashMap exdamages = new HashMap<>(3); - exdamages.put(1, 1); - exdamages.put(2, 5); - exdamages.put(3, 10); - ex1.additions.add( - new MobDrop( - new ItemStack(Items.diamond_sword), - MobDrop.DropType.Rare, - 500, - 20, - exdamages, - true, - false)); - example.put("ExampleMob", ex1); - gson.toJson(example, writer); - writer.flush(); - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - if (writer != null) try { - writer.close(); - } catch (Exception ignored) {} - } - } -} diff --git a/src/main/java/kubatech/kubatech.java b/src/main/java/kubatech/kubatech.java index 6cb6bd299c..5bc38d189e 100644 --- a/src/main/java/kubatech/kubatech.java +++ b/src/main/java/kubatech/kubatech.java @@ -49,8 +49,8 @@ import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; import cpw.mods.fml.relauncher.Side; import kubatech.api.enums.ItemList; import kubatech.api.helpers.ReflectionHelper; -import kubatech.api.network.CustomTileEntityPacket; -import kubatech.api.network.LoadConfigPacket; +import kubatech.network.CustomTileEntityPacket; +import kubatech.network.LoadConfigPacket; @SuppressWarnings("unused") @Mod( @@ -60,6 +60,7 @@ import kubatech.api.network.LoadConfigPacket; acceptedMinecraftVersions = "[1.7.10]", dependencies = "required-after: gregtech; " + "required-after: gtnhmixins@[2.0.1,); " + "required-after: modularui; " + + "required-after: mobsinfo; " + "after: EnderIO; " + "after: AWWayofTime; " + "after: ExtraUtilities; " diff --git a/src/main/java/kubatech/loaders/MobHandlerLoader.java b/src/main/java/kubatech/loaders/MobHandlerLoader.java new file mode 100644 index 0000000000..2ebff9afaf --- /dev/null +++ b/src/main/java/kubatech/loaders/MobHandlerLoader.java @@ -0,0 +1,258 @@ +package kubatech.loaders; + +import static kubatech.tileentity.gregtech.multiblock.GT_MetaTileEntity_ExtremeExterminationChamber.DIAMOND_SPIKES_DAMAGE; +import static kubatech.tileentity.gregtech.multiblock.GT_MetaTileEntity_ExtremeExterminationChamber.MOB_SPAWN_INTERVAL; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLiving; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.MinecraftForge; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.dreammaster.main.MainRegistry; +import com.dreammaster.modcustomdrops.CustomDrops; +import com.kuba6000.mobsinfo.api.MobDrop; +import com.kuba6000.mobsinfo.api.MobOverride; +import com.kuba6000.mobsinfo.api.MobRecipe; +import com.kuba6000.mobsinfo.api.event.MobNEIRegistrationEvent; +import com.kuba6000.mobsinfo.api.event.PostMobRegistrationEvent; +import com.kuba6000.mobsinfo.api.event.PostMobsOverridesLoadEvent; +import com.kuba6000.mobsinfo.api.event.PreMobsRegistrationEvent; + +import atomicstryker.infernalmobs.common.InfernalMobsCore; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.util.GT_Utility; +import kubatech.Tags; +import kubatech.api.LoaderReference; +import kubatech.api.helpers.ReflectionHelper; +import kubatech.config.Config; +import kubatech.tileentity.gregtech.multiblock.GT_MetaTileEntity_ExtremeExterminationChamber; + +public class MobHandlerLoader { + + private static final Logger LOG = LogManager.getLogger(Tags.MODID + "[Mob Handler Loader]"); + + private static MobHandlerLoader instance = null; + + public static void init() { + instance = new MobHandlerLoader(); + MinecraftForge.EVENT_BUS.register(instance); + } + + public static Map recipeMap = new HashMap<>(); + + public static class MobEECRecipe { + + public final List mOutputs; + + public final MobRecipe recipe; + + public final int mEUt = 2000; + public final int mDuration; + + public MobEECRecipe(List transformedDrops, MobRecipe recipe) { + this.mOutputs = transformedDrops; + this.recipe = recipe; + mDuration = Math.max(MOB_SPAWN_INTERVAL, (int) ((recipe.maxEntityHealth / DIAMOND_SPIKES_DAMAGE) * 10d)); + } + + public ItemStack[] generateOutputs(Random rnd, GT_MetaTileEntity_ExtremeExterminationChamber MTE, + double attackDamage, int lootinglevel, boolean preferInfernalDrops) { + MTE.lEUt = mEUt; + MTE.mMaxProgresstime = Math.max(MOB_SPAWN_INTERVAL, (int) ((recipe.maxEntityHealth / attackDamage) * 10d)); + ArrayList stacks = new ArrayList<>(this.mOutputs.size()); + for (MobDrop o : this.mOutputs) { + int chance = o.chance; + if (o.playerOnly) { + chance = (int) ((double) chance * Config.MobHandler.playerOnlyDropsModifier); + if (chance < 1) chance = 1; + } + int amount = o.stack.stackSize; + if (o.lootable && lootinglevel > 0) { + chance += lootinglevel * 5000; + if (chance > 10000) { +