diff options
Diffstat (limited to 'src/main/java/kubatech/api')
9 files changed, 1 insertions, 820 deletions
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 <https://www.gnu.org/licenses/>. - * 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 <https://www.gnu.org/licenses/>. - * 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.<Boolean>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 <https://www.gnu.org/licenses/>. - * 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<Integer, Integer> damages; - public boolean lootable = false; - public boolean playerOnly = false; - - private MobDrop() {} - - public MobDrop(ItemStack stack, DropType type, int chance, Integer enchantable, HashMap<Integer, Integer> 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 <https://www.gnu.org/licenses/>. - * 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<CustomTileEntityPacket, IMessage> { - - @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 <https://www.gnu.org/licenses/>. - * 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<String> mobsToLoad = new HashSet<>(); - public final HashMap<String, OverridesConfig.MobOverride> 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<LoadConfigPacket, IMessage> { - - @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 <https://www.gnu.org/licenses/>. - * 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 <https://www.gnu.org/licenses/>. - * 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<T, U, V> { - - void accept(T t, U u, V v); - } - - private static final HashMap<String, String> classNamesToModIDs = new HashMap<>(); - private static final Map.Entry<String, String> 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<ModContainer> modlist = (ArrayList<ModContainer>) ((ArrayList<ModContainer>) 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<ModContainer> modlist = (ArrayList<ModContainer>) ((ArrayList<ModContainer>) 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; - } - } } |