From 75df670aae4815faf5ba98e197c2546a64ae1b82 Mon Sep 17 00:00:00 2001 From: Kogepan229 Date: Sun, 25 Jan 2026 21:27:23 +0900 Subject: [PATCH] Update ThE compat --- .../common/tile/TileLevelMaintainer.java | 42 ++--- .../crossmod/thaumcraft/AspectRender.java | 38 ----- .../crossmod/thaumcraft/AspectUtil.java | 154 ------------------ .../ThaumicEnergisticsCrafting.java | 67 ++------ .../glodblock/github/proxy/CommonProxy.java | 4 - 5 files changed, 28 insertions(+), 277 deletions(-) delete mode 100644 src/main/java/com/glodblock/github/crossmod/thaumcraft/AspectRender.java delete mode 100644 src/main/java/com/glodblock/github/crossmod/thaumcraft/AspectUtil.java diff --git a/src/main/java/com/glodblock/github/common/tile/TileLevelMaintainer.java b/src/main/java/com/glodblock/github/common/tile/TileLevelMaintainer.java index 9f6a4aeb..bf91e8c2 100644 --- a/src/main/java/com/glodblock/github/common/tile/TileLevelMaintainer.java +++ b/src/main/java/com/glodblock/github/common/tile/TileLevelMaintainer.java @@ -18,7 +18,6 @@ import org.jetbrains.annotations.Nullable; import com.glodblock.github.common.Config; import com.glodblock.github.common.item.ItemFluidDrop; import com.glodblock.github.crossmod.thaumcraft.ThaumicEnergisticsCrafting; -import com.glodblock.github.util.ModAndClassUtil; import com.google.common.collect.ImmutableSet; import appeng.api.AEApi; @@ -47,10 +46,8 @@ import appeng.api.networking.ticking.TickRateModulation; import appeng.api.networking.ticking.TickingRequest; import appeng.api.storage.IMEMonitor; import appeng.api.storage.StorageName; -import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEStack; -import appeng.api.storage.data.IItemList; import appeng.core.AELog; import appeng.me.GridAccessException; import appeng.tile.TileEvent; @@ -168,8 +165,6 @@ public class TileLevelMaintainer extends AENetworkTile try { final ICraftingGrid craftingGrid = getProxy().getCrafting(); final IGrid grid = getProxy().getGrid(); - final IItemList invItems = getProxy().getStorage().getItemInventory().getStorageList(); - final IItemList invFluid = getProxy().getStorage().getFluidInventory().getStorageList(); // Check there are available crafting CPUs before doing any work. // This hopefully stops level maintainers busy-looping calculating @@ -202,32 +197,17 @@ public class TileLevelMaintainer extends AENetworkTile continue; } - IAEStack aeItem = null; - IAEStack craftItem = requests[i].stack.copy(); craftItem.setStackSize(batchSize); + IMEMonitor monitor = getProxy().getStorage().getMEMonitor(craftItem.getStackType()); + if (monitor == null) continue; - if (craftItem instanceof IAEItemStack ais) { - if (ModAndClassUtil.ThE && ThaumicEnergisticsCrafting.isAspectStack(ais.getItemStack())) { - aeItem = ThaumicEnergisticsCrafting.convertAspectStack(ais); - } else { - aeItem = invItems.findPrecise(ais); - } - } else if (craftItem instanceof IAEFluidStack afs) { - aeItem = invFluid.findPrecise(afs); - } + IAEStack stackInStorage = monitor.getStorageList().findPrecise(craftItem); - long stackSize = aeItem == null ? 0 : aeItem.getStackSize(); - - if (ModAndClassUtil.ThE) { - if (aeItem instanceof IAEItemStack ais - && ThaumicEnergisticsCrafting.isAspectStack(ais.getItemStack())) { - stackSize = ThaumicEnergisticsCrafting.getEssentiaAmount(ais, grid); - } - } + long stackSize = stackInStorage == null ? 0 : stackInStorage.getStackSize(); boolean isDone = this.isDone(i); - boolean isCraftable = aeItem != null && aeItem.isCraftable(); + boolean isCraftable = stackInStorage != null && stackInStorage.isCraftable(); boolean shouldCraft = isCraftable && stackSize < quantity; if (isDone) { @@ -246,11 +226,11 @@ public class TileLevelMaintainer extends AENetworkTile continue; } - if (craftingGrid.canEmitFor(aeItem)) { + if (craftingGrid.canEmitFor(stackInStorage)) { continue; } - if (craftingGrid.isRequesting(aeItem)) { + if (craftingGrid.isRequesting(stackInStorage)) { continue; } @@ -650,6 +630,10 @@ public class TileLevelMaintainer extends AENetworkTile if (stack == null) { throw new IllegalArgumentException("ItemStack cannot be null!"); } + + // Migrate old aspect stack + stack = ThaumicEnergisticsCrafting.convertItemAspectStack(stack); + quantity = tag.getLong(NBT_QUANTITY); batchSize = tag.getLong(NBT_BATCH); enable = tag.getBoolean(NBT_ENABLE); @@ -666,6 +650,10 @@ public class TileLevelMaintainer extends AENetworkTile public void loadFromNBT(NBTTagCompound tag) { stack = Platform.readStackNBT(tag.getCompoundTag(NBT_STACK), true); + + // Migrate old aspect stack + stack = ThaumicEnergisticsCrafting.convertItemAspectStack(stack); + quantity = tag.getLong(NBT_QUANTITY); batchSize = tag.getLong(NBT_BATCH); enable = tag.getBoolean(NBT_ENABLE); diff --git a/src/main/java/com/glodblock/github/crossmod/thaumcraft/AspectRender.java b/src/main/java/com/glodblock/github/crossmod/thaumcraft/AspectRender.java deleted file mode 100644 index 46260a09..00000000 --- a/src/main/java/com/glodblock/github/crossmod/thaumcraft/AspectRender.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.glodblock.github.crossmod.thaumcraft; - -import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.ResourceLocation; - -import org.lwjgl.opengl.GL11; - -import com.glodblock.github.util.RenderUtil; - -import thaumcraft.api.aspects.Aspect; -import thaumcraft.client.lib.UtilsFX; - -public class AspectRender { - - public static final ResourceLocation UNKNOWN_TEXTURE = new ResourceLocation( - "thaumcraft", - "textures/aspects/_unknown.png"); - - public static void drawAspect(EntityPlayer player, int posX, int posY, float zLevel, Aspect aspect, long amount) { - if (aspect == null || amount <= 0) { - return; - } - if (AspectUtil.isPlayerDiscoveredAspect(player, aspect)) { - UtilsFX.drawTag(posX, posY, aspect, 0, 0, zLevel); - } else { - Minecraft.getMinecraft().renderEngine.bindTexture(UNKNOWN_TEXTURE); - RenderUtil.setGLColorFromInt(aspect.getColor()); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - UtilsFX.drawTexturedQuadFull(posX, posY, zLevel); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_BLEND); - } - } - -} diff --git a/src/main/java/com/glodblock/github/crossmod/thaumcraft/AspectUtil.java b/src/main/java/com/glodblock/github/crossmod/thaumcraft/AspectUtil.java deleted file mode 100644 index 74560a9c..00000000 --- a/src/main/java/com/glodblock/github/crossmod/thaumcraft/AspectUtil.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.glodblock.github.crossmod.thaumcraft; - -import java.util.Objects; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidStack; - -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.MutablePair; - -import appeng.api.storage.data.IAEFluidStack; -import appeng.util.item.AEFluidStack; -import cpw.mods.fml.common.Optional; -import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.aspects.IEssentiaContainerItem; -import thaumcraft.common.Thaumcraft; -import thaumicenergistics.api.ThEApi; -import thaumicenergistics.api.storage.IAspectStack; -import thaumicenergistics.common.fluids.GaseousEssentia; -import thaumicenergistics.common.integration.tc.EssentiaItemContainerHelper; -import thaumicenergistics.common.storage.AspectStack; - -public class AspectUtil { - - public static final EssentiaItemContainerHelper HELPER = EssentiaItemContainerHelper.INSTANCE; - public static int R = 128; - - @Optional.Method(modid = "thaumicenergistics") - public static void init() { - R = ThEApi.instance().config().conversionMultiplier(); - } - - public static boolean isPlayerDiscoveredAspect(final EntityPlayer player, final Aspect aspect) { - if (player != null && aspect != null) { - return Thaumcraft.proxy.getPlayerKnowledge().hasDiscoveredAspect(player.getCommandSenderName(), aspect); - } - return false; - } - - public static boolean isEssentiaGas(Fluid fluid) { - return fluid instanceof GaseousEssentia; - } - - public static boolean isEssentiaGas(FluidStack fluid) { - return fluid != null && fluid.getFluid() instanceof GaseousEssentia; - } - - public static boolean isEssentiaGas(IAEFluidStack fluid) { - return fluid != null && fluid.getFluid() instanceof GaseousEssentia; - } - - public static Aspect getAspectFromGas(FluidStack fluid) { - if (!isEssentiaGas(fluid)) { - return null; - } - GaseousEssentia gas = (GaseousEssentia) fluid.getFluid(); - return gas.getAspect(); - } - - public static Aspect getAspectFromJar(ItemStack stack) { - if (isEssentiaContainer(stack)) { - return HELPER.getAspectInContainer(stack); - } - return null; - } - - public static Aspect getAspectFromGas(IAEFluidStack fluid) { - if (isEssentiaGas(fluid)) { - return null; - } - GaseousEssentia gas = (GaseousEssentia) fluid.getFluid(); - return gas.getAspect(); - } - - public static FluidStack getGasFromAspect(IAspectStack aspectStack) { - if (aspectStack == null || aspectStack.isEmpty()) return null; - return new FluidStack( - GaseousEssentia.getGasFromAspect(aspectStack.getAspect()), - (int) aspectStack.getStackSize() * R); - } - - public static boolean isEssentiaContainer(ItemStack stack) { - return HELPER.getItemType(stack) != EssentiaItemContainerHelper.AspectItemType.Invalid - && HELPER.getItemType(stack) != EssentiaItemContainerHelper.AspectItemType.ItemAspect; - } - - public static AEFluidStack getAEGasFromContainer(ItemStack stack) { - if (isEssentiaContainer(stack) && !isEmptyEssentiaContainer(stack)) { - IAspectStack aspectStack = HELPER.getAspectStackFromContainer(stack); - aspectStack.setStackSize(stack.stackSize * aspectStack.getStackSize()); - FluidStack gas = getGasFromAspect(aspectStack); - return AEFluidStack.create(gas); - } - return null; - } - - public static boolean isEmptyEssentiaContainer(ItemStack stack) { - return HELPER.isContainerEmpty(stack) && isEssentiaContainer(stack); - } - - public static ItemStack setAspectAmount(ItemStack itemStack, int amount, Aspect aspect) { - if (isEssentiaContainer(itemStack)) { - IEssentiaContainerItem container = (IEssentiaContainerItem) itemStack.getItem(); - assert container != null; - container.getAspects(itemStack).aspects.put(aspect, amount); - return itemStack; - } - return null; - } - - public static MutablePair fillEssentiaFromGas(ItemStack itemStack, FluidStack fluid) { - if (isEssentiaContainer(itemStack) && isEssentiaGas(fluid)) { - if (itemStack.stackSize != 1) { - return null; - } - Aspect aspect = getAspectFromGas(fluid); - int amount = fluid.amount / R; - EssentiaItemContainerHelper.AspectItemType iType = HELPER.getItemType(itemStack); - if (iType == EssentiaItemContainerHelper.AspectItemType.JarLabel) { - ItemStack label = itemStack.copy(); - HELPER.setLabelAspect(label, aspect); - } - int cap = HELPER.getContainerCapacity(itemStack); - int tryFill = Math.min(cap, amount); - ImmutablePair result = HELPER - .injectIntoContainer(itemStack, new AspectStack(aspect, tryFill)); - return result != null ? new MutablePair<>(result.left * R, result.right) : null; - } - return null; - } - - public static MutablePair drainEssentiaFromGas(ItemStack itemStack, FluidStack fluid) { - if (isEssentiaContainer(itemStack) && isEssentiaGas(fluid)) { - Aspect aspect = getAspectFromGas(fluid); - int amount = fluid.amount / R; - IAspectStack contents = HELPER.getAspectStackFromContainer(itemStack); - int drained; - ItemStack stack = null; - if (contents == null || !Objects.equals(contents.getAspect(), aspect)) { - drained = 0; - } else { - ImmutablePair result = HELPER - .extractFromContainer(itemStack, new AspectStack(aspect, amount)); - drained = result == null ? 0 : result.left; - stack = result == null ? null : result.right; - } - return stack == null ? null : new MutablePair<>(drained * R, stack); - } - return null; - } - -} diff --git a/src/main/java/com/glodblock/github/crossmod/thaumcraft/ThaumicEnergisticsCrafting.java b/src/main/java/com/glodblock/github/crossmod/thaumcraft/ThaumicEnergisticsCrafting.java index 7e2510d9..ccb3d833 100644 --- a/src/main/java/com/glodblock/github/crossmod/thaumcraft/ThaumicEnergisticsCrafting.java +++ b/src/main/java/com/glodblock/github/crossmod/thaumcraft/ThaumicEnergisticsCrafting.java @@ -1,7 +1,5 @@ package com.glodblock.github.crossmod.thaumcraft; -import java.util.Objects; - import javax.annotation.Nullable; import net.minecraft.item.Item; @@ -11,14 +9,13 @@ import net.minecraft.nbt.NBTTagList; import com.glodblock.github.util.ModAndClassUtil; -import appeng.api.networking.IGrid; import appeng.api.storage.data.IAEItemStack; -import appeng.util.item.AEItemStack; +import appeng.api.storage.data.IAEStack; import cpw.mods.fml.common.Optional.Method; import cpw.mods.fml.common.registry.GameRegistry; import thaumcraft.api.aspects.Aspect; -import thaumicenergistics.api.grid.IEssentiaGrid; import thaumicenergistics.common.items.ItemCraftingAspect; +import thaumicenergistics.common.storage.AEEssentiaStack; public class ThaumicEnergisticsCrafting { @@ -39,6 +36,17 @@ public class ThaumicEnergisticsCrafting { return stack.getItem() == neiAddonAspect || stack.getItem() == thaumicEnergisticsAspect; } + public static IAEStack convertItemAspectStack(IAEStack stack) { + if (stack instanceof IAEItemStack ais && isAspectStack(ais.getItemStack())) { + Aspect aspect = getAspect(ais.getItemStack()); + if (aspect == null) return stack; + + return new AEEssentiaStack(aspect, stack.getStackSize()); + } else { + return stack; + } + } + @Method(modid = "thaumicenergistics") private static @Nullable Aspect getAspect(ItemStack stack) { if (stack == null) return null; @@ -59,53 +67,4 @@ public class ThaumicEnergisticsCrafting { return null; } - - @Method(modid = "thaumicenergistics") - private static ItemStack getAspectStack(Aspect aspect, int stackSize) { - return ItemCraftingAspect.createStackForAspect(aspect, stackSize); - } - - /** - * Converts an aspect stack into a thaumic energistics stack. - */ - public static IAEItemStack convertAspectStack(IAEItemStack stack) { - if (ModAndClassUtil.ThE) { - return convertAspectStackImpl(stack); - } else { - return stack; - } - } - - @Method(modid = "thaumicenergistics") - private static IAEItemStack convertAspectStackImpl(IAEItemStack stack) { - if (stack == null) return null; - - Aspect aspect = getAspect(stack.getItemStack()); - - if (aspect == null) return stack; - - return Objects.requireNonNull(AEItemStack.create(getAspectStack(aspect, 1))).setStackSize(stack.getStackSize()); - } - - /** - * Gets the amount of essentia stored in a grid for a given aspect preview. - */ - public static long getEssentiaAmount(IAEItemStack stack, IGrid grid) { - if (ModAndClassUtil.ThE) { - return getEssentiaAmountImpl(stack, grid); - } else { - return 0; - } - } - - @Method(modid = "thaumicenergistics") - private static long getEssentiaAmountImpl(IAEItemStack stack, IGrid grid) { - Aspect aspect = getAspect(stack.getItemStack()); - - if (aspect == null) return 0; - - IEssentiaGrid essentiaGrid = grid.getCache(IEssentiaGrid.class); - - return essentiaGrid.getEssentiaAmount(aspect); - } } diff --git a/src/main/java/com/glodblock/github/proxy/CommonProxy.java b/src/main/java/com/glodblock/github/proxy/CommonProxy.java index 2c387855..8567b234 100644 --- a/src/main/java/com/glodblock/github/proxy/CommonProxy.java +++ b/src/main/java/com/glodblock/github/proxy/CommonProxy.java @@ -15,7 +15,6 @@ import com.glodblock.github.common.parts.PartFluidInterface; import com.glodblock.github.common.parts.PartFluidP2PInterface; import com.glodblock.github.common.tile.TileFluidInterface; import com.glodblock.github.common.tile.TileWalrus; -import com.glodblock.github.crossmod.thaumcraft.AspectUtil; import com.glodblock.github.crossmod.thaumcraft.ThaumicEnergisticsCrafting; import com.glodblock.github.inventory.external.AEFluidInterfaceHandler; import com.glodblock.github.inventory.item.WirelessMagnet; @@ -89,9 +88,6 @@ public class CommonProxy { public void init(FMLInitializationEvent event) { this.registerMovables(); - if (ModAndClassUtil.ThE) { - AspectUtil.init(); - } } public void postInit(FMLPostInitializationEvent event) {