From 9b5d86f4cdc16e33a594d48744fd21be8f4530ec Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sat, 3 Jul 2021 14:57:49 +0800 Subject: Remove unnecessary redstone state query for covers Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/api/util/GT_CoverBehavior.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_CoverBehavior.java b/src/main/java/gregtech/api/util/GT_CoverBehavior.java index ebd3a98d55..14c8cc1308 100644 --- a/src/main/java/gregtech/api/util/GT_CoverBehavior.java +++ b/src/main/java/gregtech/api/util/GT_CoverBehavior.java @@ -18,6 +18,10 @@ public abstract class GT_CoverBehavior { public EntityPlayer lastPlayer = null; + public boolean isRedstoneSensitive(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { + return true; + } + /** * Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time. */ -- cgit From 6f8016367d6f278f7a39206ff7f9dc73c719c807 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sat, 10 Jul 2021 11:21:34 +0800 Subject: Extended GUI fluid manipulation support to GT_MetaTileEntity_BasicTank --- .../api/gui/GT_Container_BasicMachine.java | 150 +------------- .../gregtech/api/gui/GT_Container_BasicTank.java | 226 +++++++++++++++++++++ .../GT_MetaTileEntity_BasicMachine.java | 2 +- .../GT_MetaTileEntity_BasicTank.java | 2 +- src/main/java/gregtech/api/util/GT_Utility.java | 6 +- .../render/GT_FluidDisplayStackRenderer.java | 2 +- 6 files changed, 243 insertions(+), 145 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java b/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java index 28fd2983f4..5d2a9321c4 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java +++ b/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java @@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -11,7 +12,6 @@ import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.IFluidContainerItem; import static gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine.OTHER_SLOT_COUNT; @@ -195,154 +195,22 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { if (mTileEntity.getMetaTileEntity() == null) return null; machine.mItemTransfer = !machine.mItemTransfer; return null; - case 2: - if (aMouseclick > 1) - return null; - tResultStack = pickupFluid(machine.getDrainableStack(), aPlayer, aMouseclick == 0); - if (machine.getDrainableStack() != null && machine.getDrainableStack().amount == 0) - machine.setDrainableStack(null); - return tResultStack; default: - if (aSlotIndex == OTHER_SLOT_COUNT + 1 + machine.mInputSlotCount + machine.mOutputItems.length) { - if (aMouseclick > 1) - return null; - // input fluid slot - ItemStack tStackHeld = aPlayer.inventory.getItemStack(); - ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld); - if (tStackSizedOne == null || tStackHeld.stackSize == 0) return null; - FluidStack tInputFluid = machine.getFillableStack(); - FluidStack tFluidHeld = GT_Utility.getFluidForFilledItem(tStackSizedOne, true); - if (tFluidHeld != null && tFluidHeld.amount <= 0) - tFluidHeld = null; - if (tInputFluid == null) { - if (tFluidHeld == null) - // both null -> no op - return null; - return fillFluid(machine, aPlayer, tFluidHeld, aMouseclick == 0); - } else { - if (tFluidHeld != null && tInputFluid.amount < machine.getCapacity()) { - // both nonnull and have space left for filling. - // actually both pickup and fill is reasonable, but I'll go with fill here - return fillFluid(machine, aPlayer, tFluidHeld, aMouseclick == 0); - } else { - tResultStack = pickupFluid(tInputFluid, aPlayer, aMouseclick == 0); - if (tInputFluid.amount == 0) - machine.setFillableStack(null); - return tResultStack; - } + if (aSlotIndex == OTHER_SLOT_COUNT + 1 + machine.mInputSlotCount + machine.mOutputItems.length && aMouseclick < 2) { + if (mTileEntity.isClientSide()) { + // see parent class slotClick for an explanation on why doing this + GT_MetaTileEntity_BasicTank tTank = (GT_MetaTileEntity_BasicTank) mTileEntity.getMetaTileEntity(); + tTank.setFillableStack(GT_Utility.getFluidFromDisplayStack(tTank.getStackInSlot(2))); } + GT_MetaTileEntity_BasicTank tTank = (GT_MetaTileEntity_BasicTank) mTileEntity.getMetaTileEntity(); + IFluidAccess tFillableAccess = IFluidAccess.from(tTank, true); + return handleFluidSlotClick(tFillableAccess, aPlayer, aMouseclick == 0, true, true); } else { return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); } } } - private ItemStack pickupFluid(FluidStack aTankStack, EntityPlayer aPlayer, boolean aProcessFullStack) { - if (aTankStack == null) return null; - ItemStack tStackHeld = aPlayer.inventory.getItemStack(); - ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld); - if (tStackSizedOne == null || tStackHeld.stackSize == 0) return null; - int tOriginalFluidAmount = aTankStack.amount; - ItemStack tFilled = GT_Utility.fillFluidContainer(aTankStack, tStackSizedOne, true, false); - if (tFilled == null && tStackSizedOne.getItem() instanceof IFluidContainerItem) { - IFluidContainerItem tContainerItem = (IFluidContainerItem) tStackSizedOne.getItem(); - int tFilledAmount = tContainerItem.fill(tStackSizedOne, aTankStack, true); - if (tFilledAmount > 0) { - tFilled = tStackSizedOne; - aTankStack.amount -= tFilledAmount; - } - } - if (tFilled != null) { - if (aProcessFullStack) { - int tFilledAmount = tOriginalFluidAmount - aTankStack.amount; - /* - work out how many more items we can fill - one cell is already used, so account for that - the round down behavior will left over a fraction of a cell worth of fluid - the user then get to decide what to do with it - it will not be too fancy if it spills out partially filled cells - */ - int tAdditionalParallel = Math.min(tStackHeld.stackSize - 1, aTankStack.amount / tFilledAmount); - aTankStack.amount -= tFilledAmount * tAdditionalParallel; - tFilled.stackSize += tAdditionalParallel; - } - replaceCursorItemStack(aPlayer, tFilled); - } - return tFilled; - } - - private ItemStack fillFluid(GT_MetaTileEntity_BasicMachine aMachine, EntityPlayer aPlayer, FluidStack aFluidHeld, boolean aProcessFullStack) { - // we are not using aMachine.fill() here any more, so we need to check for fluid type here ourselves - if (aMachine.getFillableStack() != null && !aMachine.getFillableStack().isFluidEqual(aFluidHeld)) - return null; - ItemStack tStackHeld = aPlayer.inventory.getItemStack(); - ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld); - if (tStackSizedOne == null) - return null; - - int tFreeSpace = aMachine.getCapacity() - (aMachine.getFillableStack() != null ? aMachine.getFillableStack().amount : 0); - if (tFreeSpace <= 0) - // no space left - return null; - - // find out how much fluid can be taken - // some cells cannot be partially filled - ItemStack tStackEmptied = null; - int tAmountTaken = 0; - if (tFreeSpace >= aFluidHeld.amount) { - // fully accepted - try take it from item now - // IFluidContainerItem is intentionally not checked here. it will be checked later - tStackEmptied = GT_Utility.getContainerForFilledItem(tStackSizedOne, false); - tAmountTaken = aFluidHeld.amount; - } - if (tStackEmptied == null && tStackSizedOne.getItem() instanceof IFluidContainerItem) { - // either partially accepted, or is IFluidContainerItem - IFluidContainerItem container = (IFluidContainerItem) tStackSizedOne.getItem(); - FluidStack tDrained = container.drain(tStackSizedOne, tFreeSpace, true); - if (tDrained != null && tDrained.amount > 0) { - // something is actually drained - change the cell and drop it to player - tStackEmptied = tStackSizedOne; - tAmountTaken = tDrained.amount; - } - } - if (tStackEmptied == null) - // somehow the cell refuse to give out that amount of fluid, no op then - return null; - - // find out how many fill can we do - // same round down behavior as above - // however here the fluid stack is not changed at all, so the exact code will slightly differ - int tParallel = aProcessFullStack ? Math.min(tFreeSpace / tAmountTaken, tStackHeld.stackSize) : 1; - if (aMachine.getFillableStack() == null) { - FluidStack tNewFillableStack = aFluidHeld.copy(); - tNewFillableStack.amount = tAmountTaken * tParallel; - aMachine.setFillableStack(tNewFillableStack); - } else { - aMachine.getFillableStack().amount += tAmountTaken * tParallel; - } - tStackEmptied.stackSize = tParallel; - replaceCursorItemStack(aPlayer, tStackEmptied); - return tStackEmptied; - } - - private void replaceCursorItemStack(EntityPlayer aPlayer, ItemStack tStackResult) { - int tStackResultMaxStackSize = tStackResult.getMaxStackSize(); - while (tStackResult.stackSize > tStackResultMaxStackSize) { - aPlayer.inventory.getItemStack().stackSize -= tStackResultMaxStackSize; - GT_Utility.addItemToPlayerInventory(aPlayer, tStackResult.splitStack(tStackResultMaxStackSize)); - } - if (aPlayer.inventory.getItemStack().stackSize == tStackResult.stackSize) { - // every cell is mutated. it could just stay on the cursor. - aPlayer.inventory.setItemStack(tStackResult); - } else { - // some cells not mutated. The mutated cells must go into the inventory - // or drop into the world if there isn't enough space. - ItemStack tStackHeld = aPlayer.inventory.getItemStack(); - tStackHeld.stackSize -= tStackResult.stackSize; - GT_Utility.addItemToPlayerInventory(aPlayer, tStackResult); - } - } - @Override public void detectAndSendChanges() { super.detectAndSendChanges(); diff --git a/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java b/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java index c80874eef4..0ce9ab9232 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java +++ b/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java @@ -4,9 +4,15 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; +import gregtech.api.util.GT_Utility; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidContainerItem; /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! @@ -28,6 +34,189 @@ public class GT_Container_BasicTank extends GT_ContainerMetaTile_Machine { addSlotToContainer(new GT_Slot_Render(mTileEntity, 2, 59, 42)); } + @Override + public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { + if (aSlotIndex == 2 && aMouseclick < 2) { + if (mTileEntity.isClientSide()) { + /* + * While a logical client don't really need to process fluid cells upon click (it could have just wait + * for server side to send the result), doing so would result in every fluid interaction having a + * noticeable delay between clicking and changes happening even on single player. + * I'd imagine this delay to get only more severe when playing MP over ethernet, which would have much more latency + * than a memory connection + */ + GT_MetaTileEntity_BasicTank tTank = (GT_MetaTileEntity_BasicTank) mTileEntity.getMetaTileEntity(); + tTank.setDrainableStack(GT_Utility.getFluidFromDisplayStack(tTank.getStackInSlot(2))); + } + GT_MetaTileEntity_BasicTank tTank = (GT_MetaTileEntity_BasicTank) mTileEntity.getMetaTileEntity(); + IFluidAccess tDrainableAccess = IFluidAccess.from(tTank, false); + return handleFluidSlotClick(tDrainableAccess, aPlayer, aMouseclick == 0, true, !tTank.isDrainableStackSeparate()); + } + if (mTileEntity.isServerSide()) { + aPlayer.addChatComponentMessage(new ChatComponentText(String.format("Slot Index: %d, aMouseClick: %d, Shift Hold: %d", aShifthold, aMouseclick, aShifthold))); + } + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + /** + * Expected to be called on client side only. Load fluid stacks from fluid display items as they were not sent + * over the network. + * Override this if you have more than one fluid display stack. This implementation will set drainable stack according to items + * in slot indexed 2. + * + */ + protected void syncFluidFromFluidDisplayItems() { + GT_MetaTileEntity_BasicTank tTank = (GT_MetaTileEntity_BasicTank) mTileEntity.getMetaTileEntity(); + tTank.setDrainableStack(GT_Utility.getFluidFromDisplayStack(tTank.getStackInSlot(2))); + } + + protected static ItemStack handleFluidSlotClick(IFluidAccess aFluidAccess, EntityPlayer aPlayer, boolean aProcessFullStack, boolean aCanDrain, boolean aCanFill) { + ItemStack tStackHeld = aPlayer.inventory.getItemStack(); + ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld); + if (tStackSizedOne == null || tStackHeld.stackSize == 0) return null; + FluidStack tInputFluid = aFluidAccess.get(); + FluidStack tFluidHeld = GT_Utility.getFluidForFilledItem(tStackSizedOne, true); + if (tFluidHeld != null && tFluidHeld.amount <= 0) + tFluidHeld = null; + if (tInputFluid == null) { + // tank empty, consider fill only from now on + if (!aCanFill) + // cannot fill and nothing to take, bail out + return null; + if (tFluidHeld == null) + // no fluid to fill + return null; + return fillFluid(aFluidAccess, aPlayer, tFluidHeld, aProcessFullStack); + } + // tank not empty, both action possible + if (tFluidHeld != null && tInputFluid.amount < aFluidAccess.getCapacity()) { + // both nonnull and have space left for filling. + if (aCanFill) + // actually both pickup and fill is reasonable, but I'll go with fill here + return fillFluid(aFluidAccess, aPlayer, tFluidHeld, aProcessFullStack); + if (!aCanDrain) + // cannot take AND cannot fill, why make this call then? + return null; + // the slot does not allow filling, so try take some + return drainFluid(aFluidAccess.get(), aPlayer, aProcessFullStack); + } else { + // cannot fill and there is something to take + if (!aCanDrain) + // but the slot does not allow taking, so bail out + return null; + ItemStack tResultStack = drainFluid(tInputFluid, aPlayer, aProcessFullStack); + if (tInputFluid.amount == 0) + aFluidAccess.set(null); + return tResultStack; + } + } + + protected static ItemStack drainFluid(FluidStack aTankStack, EntityPlayer aPlayer, boolean aProcessFullStack) { + if (aTankStack == null) return null; + ItemStack tStackHeld = aPlayer.inventory.getItemStack(); + ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld); + if (tStackSizedOne == null || tStackHeld.stackSize == 0) return null; + int tOriginalFluidAmount = aTankStack.amount; + ItemStack tFilled = GT_Utility.fillFluidContainer(aTankStack, tStackSizedOne, true, false); + if (tFilled == null && tStackSizedOne.getItem() instanceof IFluidContainerItem) { + IFluidContainerItem tContainerItem = (IFluidContainerItem) tStackSizedOne.getItem(); + int tFilledAmount = tContainerItem.fill(tStackSizedOne, aTankStack, true); + if (tFilledAmount > 0) { + tFilled = tStackSizedOne; + aTankStack.amount -= tFilledAmount; + } + } + if (tFilled != null) { + if (aProcessFullStack) { + int tFilledAmount = tOriginalFluidAmount - aTankStack.amount; + /* + work out how many more items we can fill + one cell is already used, so account for that + the round down behavior will left over a fraction of a cell worth of fluid + the user then get to decide what to do with it + it will not be too fancy if it spills out partially filled cells + */ + int tAdditionalParallel = Math.min(tStackHeld.stackSize - 1, aTankStack.amount / tFilledAmount); + aTankStack.amount -= tFilledAmount * tAdditionalParallel; + tFilled.stackSize += tAdditionalParallel; + } + replaceCursorItemStack(aPlayer, tFilled); + } + return tFilled; + } + + protected static ItemStack fillFluid(IFluidAccess aFluidAccess, EntityPlayer aPlayer, FluidStack aFluidHeld, boolean aProcessFullStack) { + // we are not using aMachine.fill() here any more, so we need to check for fluid type here ourselves + if (aFluidAccess.get() != null && !aFluidAccess.get().isFluidEqual(aFluidHeld)) + return null; + ItemStack tStackHeld = aPlayer.inventory.getItemStack(); + ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld); + if (tStackSizedOne == null) + return null; + + int tFreeSpace = aFluidAccess.getCapacity() - (aFluidAccess.get() != null ? aFluidAccess.get().amount : 0); + if (tFreeSpace <= 0) + // no space left + return null; + + // find out how much fluid can be taken + // some cells cannot be partially filled + ItemStack tStackEmptied = null; + int tAmountTaken = 0; + if (tFreeSpace >= aFluidHeld.amount) { + // fully accepted - try take it from item now + // IFluidContainerItem is intentionally not checked here. it will be checked later + tStackEmptied = GT_Utility.getContainerForFilledItem(tStackSizedOne, false); + tAmountTaken = aFluidHeld.amount; + } + if (tStackEmptied == null && tStackSizedOne.getItem() instanceof IFluidContainerItem) { + // either partially accepted, or is IFluidContainerItem + IFluidContainerItem container = (IFluidContainerItem) tStackSizedOne.getItem(); + FluidStack tDrained = container.drain(tStackSizedOne, tFreeSpace, true); + if (tDrained != null && tDrained.amount > 0) { + // something is actually drained - change the cell and drop it to player + tStackEmptied = tStackSizedOne; + tAmountTaken = tDrained.amount; + } + } + if (tStackEmptied == null) + // somehow the cell refuse to give out that amount of fluid, no op then + return null; + + // find out how many fill can we do + // same round down behavior as above + // however here the fluid stack is not changed at all, so the exact code will slightly differ + int tParallel = aProcessFullStack ? Math.min(tFreeSpace / tAmountTaken, tStackHeld.stackSize) : 1; + if (aFluidAccess.get() == null) { + FluidStack tNewFillableStack = aFluidHeld.copy(); + tNewFillableStack.amount = tAmountTaken * tParallel; + aFluidAccess.set(tNewFillableStack); + } else { + aFluidAccess.get().amount += tAmountTaken * tParallel; + } + tStackEmptied.stackSize = tParallel; + replaceCursorItemStack(aPlayer, tStackEmptied); + return tStackEmptied; + } + + private static void replaceCursorItemStack(EntityPlayer aPlayer, ItemStack tStackResult) { + int tStackResultMaxStackSize = tStackResult.getMaxStackSize(); + while (tStackResult.stackSize > tStackResultMaxStackSize) { + aPlayer.inventory.getItemStack().stackSize -= tStackResultMaxStackSize; + GT_Utility.addItemToPlayerInventory(aPlayer, tStackResult.splitStack(tStackResultMaxStackSize)); + } + if (aPlayer.inventory.getItemStack().stackSize == tStackResult.stackSize) { + // every cell is mutated. it could just stay on the cursor. + aPlayer.inventory.setItemStack(tStackResult); + } else { + // some cells not mutated. The mutated cells must go into the inventory + // or drop into the world if there isn't enough space. + ItemStack tStackHeld = aPlayer.inventory.getItemStack(); + tStackHeld.stackSize -= tStackResult.stackSize; + GT_Utility.addItemToPlayerInventory(aPlayer, tStackResult); + } + } + @Override public void detectAndSendChanges() { super.detectAndSendChanges(); @@ -66,4 +255,41 @@ public class GT_Container_BasicTank extends GT_ContainerMetaTile_Machine { public int getShiftClickSlotCount() { return 1; } + + protected interface IFluidAccess { + void set(FluidStack stack); + FluidStack get(); + int getCapacity(); + static IFluidAccess from(GT_MetaTileEntity_BasicTank aTank, boolean aIsFillableStack) { + return new BasicTankFluidAccess(aTank, aIsFillableStack); + } + } + + static class BasicTankFluidAccess implements IFluidAccess { + private final GT_MetaTileEntity_BasicTank mTank; + private final boolean mIsFillableStack; + + public BasicTankFluidAccess(GT_MetaTileEntity_BasicTank aTank, boolean aIsFillableStack) { + this.mTank = aTank; + this.mIsFillableStack = aIsFillableStack; + } + + @Override + public void set(FluidStack stack) { + if (mIsFillableStack) + mTank.setFillableStack(stack); + else + mTank.setDrainableStack(stack); + } + + @Override + public FluidStack get() { + return mIsFillableStack ? mTank.getFillableStack() : mTank.getDrainableStack(); + } + + @Override + public int getCapacity() { + return mTank.getCapacity(); + } + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java index 834344d2d2..29fe6ec387 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java @@ -594,7 +594,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B if (ItemList.Display_Fluid.isStackEqual(mInventory[tDisplayStackSlot], true, true)) mInventory[tDisplayStackSlot] = null; } else { - mInventory[tDisplayStackSlot] = GT_Utility.getFluidDisplayStack(getFillableStack(), displaysStackSize()); + mInventory[tDisplayStackSlot] = GT_Utility.getFluidDisplayStack(getFillableStack(), true, !displaysStackSize()); } } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java index 6a65eaf5d8..7b99d78009 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java @@ -198,7 +198,7 @@ public abstract class GT_MetaTileEntity_BasicTank extends GT_MetaTileEntity_Tier if (ItemList.Display_Fluid.isStackEqual(mInventory[getStackDisplaySlot()], true, true)) mInventory[getStackDisplaySlot()] = null; } else { - mInventory[getStackDisplaySlot()] = GT_Utility.getFluidDisplayStack(getDisplayedFluid(), displaysStackSize()); + mInventory[getStackDisplaySlot()] = GT_Utility.getFluidDisplayStack(getDisplayedFluid(), true, !displaysStackSize()); } } } diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 8cbb44fe07..a404d8c561 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -108,7 +108,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -999,6 +998,10 @@ public class GT_Utility { } public static ItemStack getFluidDisplayStack(FluidStack aFluid, boolean aUseStackSize) { + return getFluidDisplayStack(aFluid, aUseStackSize, false); + } + + public static ItemStack getFluidDisplayStack(FluidStack aFluid, boolean aUseStackSize, boolean aHideStackSize) { if (aFluid == null || aFluid.getFluid() == null) return null; int tmp = 0; try { @@ -1011,6 +1014,7 @@ public class GT_Utility { tNBT.setLong("mFluidDisplayAmount", aUseStackSize ? aFluid.amount : 0); tNBT.setLong("mFluidDisplayHeat", aFluid.getFluid().getTemperature(aFluid)); tNBT.setBoolean("mFluidState", aFluid.getFluid().isGaseous(aFluid)); + tNBT.setBoolean("mHideStackSize", aHideStackSize); rStack.setTagCompound(tNBT); return rStack; } diff --git a/src/main/java/gregtech/common/render/GT_FluidDisplayStackRenderer.java b/src/main/java/gregtech/common/render/GT_FluidDisplayStackRenderer.java index ef5d8287ba..c4e23eab6e 100644 --- a/src/main/java/gregtech/common/render/GT_FluidDisplayStackRenderer.java +++ b/src/main/java/gregtech/common/render/GT_FluidDisplayStackRenderer.java @@ -67,7 +67,7 @@ public class GT_FluidDisplayStackRenderer implements IItemRenderer { // Render Fluid amount text long fluidAmount = item.getTagCompound().getLong("mFluidDisplayAmount"); - if (fluidAmount > 0L) { + if (fluidAmount > 0L && !item.getTagCompound().getBoolean("mHideStackSize")) { String amountString; if (fluidAmount < 10000) { -- cgit From 8000dcecab1d731893b0be4637fc3316ca2d1550 Mon Sep 17 00:00:00 2001 From: GlodBlock <60341015+GlodBlock@users.noreply.github.com> Date: Sat, 10 Jul 2021 13:25:03 +0800 Subject: fix recipe check --- src/main/java/gregtech/api/util/GT_Recipe.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index aa54b55277..315d70a522 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -388,13 +388,18 @@ public class GT_Recipe implements Comparable { if (mInputs.length > 0 && aInputs == null) return false; + HashSet isUsed = new HashSet<>(); + for (ItemStack tStack : mInputs) { ItemStack unified_tStack = GT_OreDictUnificator.get_nocopy(true, tStack); if (unified_tStack != null) { amt = tStack.stackSize; boolean temp = true; + int it = 0; for (ItemStack aStack : aInputs) { - if (GT_OreDictUnificator.isInputStackEqual(aStack, unified_tStack)) { + it ++; + if (GT_OreDictUnificator.isInputStackEqual(aStack, unified_tStack) && !isUsed.contains(it)) { + isUsed.add(it); if (GTppRecipeHelper) {//remove once the fix is out if (GT_Utility.areStacksEqual(aStack, Ic2Items.FluidCell.copy(), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataStick.get(1L), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataOrb.get(1L), true)) { if (!GT_Utility.areStacksEqual(aStack, tStack, false)) -- cgit From 9f7fd2675139d4a575b6a1dc2fa1b472800a0757 Mon Sep 17 00:00:00 2001 From: TimeConqueror Date: Thu, 15 Jul 2021 02:23:32 +0300 Subject: Optimized Replacing Vanilla Materials code, removed uselessly-repeated operations --- .../gregtech/api/util/GT_RecipeRegistrator.java | 150 +++++++++++---------- src/main/java/gregtech/api/util/GT_Utility.java | 7 + 2 files changed, 84 insertions(+), 73 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java b/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java index 0868ff41c8..34cf7ca80e 100644 --- a/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java +++ b/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java @@ -1,5 +1,6 @@ package gregtech.api.util; +import com.google.common.base.Stopwatch; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.*; @@ -28,52 +29,52 @@ public class GT_RecipeRegistrator { public static final List sRodMaterialList = new ArrayList(); private static final ItemStack sMt1 = new ItemStack(Blocks.dirt, 1, 0), sMt2 = new ItemStack(Blocks.dirt, 1, 0); private static final String s_H = "h", s_F = "f", s_I = "I", s_P = "P", s_R = "R"; - private static final ItemStack[][] - sShapes1 = new ItemStack[][]{ - {sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1, null}, - {sMt1, null, sMt1, sMt1, null, sMt1, sMt1, sMt1, sMt1}, - {null, sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1}, - {sMt1, sMt1, sMt1, sMt1, null, sMt1, null, null, null}, - {sMt1, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1}, - {sMt1, sMt1, sMt1, sMt1, null, sMt1, sMt1, null, sMt1}, - {null, null, null, sMt1, null, sMt1, sMt1, null, sMt1}, - {null, sMt1, null, null, sMt1, null, null, sMt2, null}, - {sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2, null}, - {null, sMt1, null, null, sMt2, null, null, sMt2, null}, - {sMt1, sMt1, null, sMt1, sMt2, null, null, sMt2, null}, - {null, sMt1, sMt1, null, sMt2, sMt1, null, sMt2, null}, - {sMt1, sMt1, null, null, sMt2, null, null, sMt2, null}, - {null, sMt1, sMt1, null, sMt2, null, null, sMt2, null}, - {null, sMt1, null, sMt1, null, null, null, sMt1, sMt2}, - {null, sMt1, null, null, null, sMt1, sMt2, sMt1, null}, - {null, sMt1, null, sMt1, null, sMt1, null, null, sMt2}, - {null, sMt1, null, sMt1, null, sMt1, sMt2, null, null}, - {null, sMt2, null, null, sMt1, null, null, sMt1, null}, - {null, sMt2, null, null, sMt2, null, sMt1, sMt1, sMt1}, - {null, sMt2, null, null, sMt2, null, null, sMt1, null}, - {null, sMt2, null, sMt1, sMt2, null, sMt1, sMt1, null}, - {null, sMt2, null, null, sMt2, sMt1, null, sMt1, sMt1}, - {null, sMt2, null, null, sMt2, null, sMt1, sMt1, null}, - {sMt1, null, null, null, sMt2, null, null, null, sMt2}, - {null, null, sMt1, null, sMt2, null, sMt2, null, null}, - {sMt1, null, null, null, sMt2, null, null, null, null}, - {null, null, sMt1, null, sMt2, null, null, null, null}, - {sMt1, sMt2, null, null, null, null, null, null, null}, - {sMt2, sMt1, null, null, null, null, null, null, null}, - {sMt1, null, null, sMt2, null, null, null, null, null}, - {sMt2, null, null, sMt1, null, null, null, null, null}, - {sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, null, sMt2, null}, - {sMt1, sMt1, null, sMt1, sMt1, sMt2, sMt1, sMt1, null}, - {null, sMt1, sMt1, sMt2, sMt1, sMt1, null, sMt1, sMt1}, - {null, sMt2, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1}, - {sMt1, sMt1, sMt1, sMt1, sMt2, sMt1, null, sMt2, null}, - {sMt1, sMt1, null, sMt1, sMt2, sMt2, sMt1, sMt1, null}, - {null, sMt1, sMt1, sMt2, sMt2, sMt1, null, sMt1, sMt1}, - {null, sMt2, null, sMt1, sMt2, sMt1, sMt1, sMt1, sMt1}, - {sMt1, null, null, null, sMt1, null, null, null, null}, - {null, sMt1, null, sMt1, null, null, null, null, null}, - {sMt1, sMt1, null, sMt2, null, sMt1, sMt2, null, null}, - {null, sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2} + private static final RecipeShape[] + sShapes = new RecipeShape[]{ + new RecipeShape(sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1, null), + new RecipeShape(sMt1, null, sMt1, sMt1, null, sMt1, sMt1, sMt1, sMt1), + new RecipeShape(null, sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1), + new RecipeShape(sMt1, sMt1, sMt1, sMt1, null, sMt1, null, null, null), + new RecipeShape(sMt1, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1), + new RecipeShape(sMt1, sMt1, sMt1, sMt1, null, sMt1, sMt1, null, sMt1), + new RecipeShape(null, null, null, sMt1, null, sMt1, sMt1, null, sMt1), + new RecipeShape(null, sMt1, null, null, sMt1, null, null, sMt2, null), + new RecipeShape(sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2, null), + new RecipeShape(null, sMt1, null, null, sMt2, null, null, sMt2, null), + new RecipeShape(sMt1, sMt1, null, sMt1, sMt2, null, null, sMt2, null), + new RecipeShape(null, sMt1, sMt1, null, sMt2, sMt1, null, sMt2, null), + new RecipeShape(sMt1, sMt1, null, null, sMt2, null, null, sMt2, null), + new RecipeShape(null, sMt1, sMt1, null, sMt2, null, null, sMt2, null), + new RecipeShape(null, sMt1, null, sMt1, null, null, null, sMt1, sMt2), + new RecipeShape(null, sMt1, null, null, null, sMt1, sMt2, sMt1, null), + new RecipeShape(null, sMt1, null, sMt1, null, sMt1, null, null, sMt2), + new RecipeShape(null, sMt1, null, sMt1, null, sMt1, sMt2, null, null), + new RecipeShape(null, sMt2, null, null, sMt1, null, null, sMt1, null), + new RecipeShape(null, sMt2, null, null, sMt2, null, sMt1, sMt1, sMt1), + new RecipeShape(null, sMt2, null, null, sMt2, null, null, sMt1, null), + new RecipeShape(null, sMt2, null, sMt1, sMt2, null, sMt1, sMt1, null), + new RecipeShape(null, sMt2, null, null, sMt2, sMt1, null, sMt1, sMt1), + new RecipeShape(null, sMt2, null, null, sMt2, null, sMt1, sMt1, null), + new RecipeShape(sMt1, null, null, null, sMt2, null, null, null, sMt2), + new RecipeShape(null, null, sMt1, null, sMt2, null, sMt2, null, null), + new RecipeShape(sMt1, null, null, null, sMt2, null, null, null, null), + new RecipeShape(null, null, sMt1, null, sMt2, null, null, null, null), + new RecipeShape(sMt1, sMt2, null, null, null, null, null, null, null), + new RecipeShape(sMt2, sMt1, null, null, null, null, null, null, null), + new RecipeShape(sMt1, null, null, sMt2, null, null, null, null, null), + new RecipeShape(sMt2, null, null, sMt1, null, null, null, null, null), + new RecipeShape(sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, null, sMt2, null), + new RecipeShape(sMt1, sMt1, null, sMt1, sMt1, sMt2, sMt1, sMt1, null), + new RecipeShape(null, sMt1, sMt1, sMt2, sMt1, sMt1, null, sMt1, sMt1), + new RecipeShape(null, sMt2, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1), + new RecipeShape(sMt1, sMt1, sMt1, sMt1, sMt2, sMt1, null, sMt2, null), + new RecipeShape(sMt1, sMt1, null, sMt1, sMt2, sMt2, sMt1, sMt1, null), + new RecipeShape(null, sMt1, sMt1, sMt2, sMt2, sMt1, null, sMt1, sMt1), + new RecipeShape(null, sMt2, null, sMt1, sMt2, sMt1, sMt1, sMt1, sMt1), + new RecipeShape(sMt1, null, null, null, sMt1, null, null, null, null), + new RecipeShape(null, sMt1, null, sMt1, null, null, null, null, null), + new RecipeShape(sMt1, sMt1, null, sMt2, null, sMt1, sMt2, null, null), + new RecipeShape(null, sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2) }; private static final String[][] sShapesA = new String[][]{ null, @@ -307,10 +308,7 @@ public class GT_RecipeRegistrator { */ public static synchronized void registerUsagesForMaterials(String aPlate, boolean aRecipeReplacing, ItemStack... aMats) { for (ItemStack aMat : aMats) { - if (aMat == null) - continue; - - aMat = GT_Utility.copy(aMat); + aMat = GT_Utility.copyOrNull(aMat); if (aMat == null) continue; @@ -327,20 +325,17 @@ public class GT_RecipeRegistrator { sMt2.stackSize = 1; Items.feather.setDamage(sMt2, 0); - for (ItemStack[] tRecipe : sShapes1) { - int tAmount1 = 0; - for (ItemStack tMat : tRecipe) { - if (tMat == sMt1) tAmount1++; - } - if (aItemData != null && aItemData.hasValidPrefixMaterialData()) - for (ItemStack tCrafted : GT_ModHandler.getRecipeOutputsBuffered(tRecipe)) { - GT_OreDictUnificator.addItemData(tCrafted, new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tAmount1)); -// GT_Log.out.println("###################################################################################"); -// GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aPlate); -// GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aMat.getUnlocalizedName()); -// GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aMat.getDisplayName()); -// GT_Log.out.println("###################################################################################"); + if(aItemData != null && aItemData.hasValidPrefixMaterialData()) { + for (RecipeShape tRecipe : sShapes) { + for (ItemStack tCrafted : GT_ModHandler.getRecipeOutputsBuffered(tRecipe.shape)) { + GT_OreDictUnificator.addItemData(tCrafted, new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tRecipe.amount1)); + // GT_Log.out.println("###################################################################################"); + // GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aPlate); + // GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aMat.getUnlocalizedName()); + // GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aMat.getDisplayName()); + // GT_Log.out.println("###################################################################################"); } + } } registerStickStuff(aPlate, aItemData, aRecipeReplacing); } @@ -355,22 +350,17 @@ public class GT_RecipeRegistrator { sMt2.stackSize = 1; Items.feather.setDamage(sMt2, Items.feather.getDamage(tMt2)); - for (int i = 0; i < sShapes1.length; i++) { - ItemStack[] tRecipe = sShapes1[i]; + for (int i = 0; i < sShapes.length; i++) { + RecipeShape tRecipe = sShapes[i]; - int tAmount1 = 0, tAmount2 = 0; - for (ItemStack tMat : tRecipe) { - if (tMat == sMt1) tAmount1++; - if (tMat == sMt2) tAmount2++; - } - for (ItemStack tCrafted : GT_ModHandler.getVanillyToolRecipeOutputs(tRecipe)) { + for (ItemStack tCrafted : GT_ModHandler.getVanillyToolRecipeOutputs(tRecipe.shape)) { if (aItemData != null && aItemData.hasValidPrefixMaterialData()) - GT_OreDictUnificator.addItemData(tCrafted, new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tAmount1, new MaterialStack(tMaterial, OrePrefixes.stick.mMaterialAmount * tAmount2))); + GT_OreDictUnificator.addItemData(tCrafted, new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tRecipe.amount1, new MaterialStack(tMaterial, OrePrefixes.stick.mMaterialAmount * tRecipe.amount2))); if (aRecipeReplacing && aPlate != null && sShapesA[i] != null && sShapesA[i].length > 1) { assert aItemData != null; if (GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.recipereplacements, aItemData.mMaterial.mMaterial + "." + sShapesA[i][0], true)) { - if (null != (tStack = GT_ModHandler.removeRecipe(tRecipe))) { + if (null != (tStack = GT_ModHandler.removeRecipe(tRecipe.shape))) { // GT_Log.out.println("###################################################################################"); // GT_Log.out.println("registerStickStuff used aPlate: "+aPlate); // GT_Log.out.println("###################################################################################"); @@ -398,4 +388,18 @@ public class GT_RecipeRegistrator { return Arrays.stream(VANILLA_MATS).anyMatch(mat -> mat == materials); } + private static class RecipeShape { + private final ItemStack[] shape; + private int amount1; + private int amount2; + + public RecipeShape(ItemStack... shape) { + this.shape = shape; + + for (ItemStack stack : shape) { + if(stack == sMt1) this.amount1++; + if(stack == sMt2) this.amount2++; + } + } + } } diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 8cbb44fe07..8e283956cb 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -90,6 +90,7 @@ import net.minecraftforge.fluids.IFluidContainerItem; import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.oredict.OreDictionary; +import javax.annotation.Nullable; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -1651,6 +1652,12 @@ public class GT_Utility { return null; } + @Nullable + public static ItemStack copyOrNull(@Nullable ItemStack stack) { + if (isStackValid(stack)) return stack.copy(); + return null; + } + public static ItemStack copyAmount(long aAmount, Object... aStacks) { ItemStack rStack = copy(aStacks); if (isStackInvalid(rStack)) return null; -- cgit From 77f22e029303ba48f9aabad32367e500bdcefee3 Mon Sep 17 00:00:00 2001 From: TimeConqueror Date: Thu, 15 Jul 2021 02:53:54 +0300 Subject: Removed useless array creation in most #copy methods by changing them to #copyOrNull variant with single parameter. --- src/main/java/gregtech/api/gui/GT_Container.java | 8 +-- .../api/metatileentity/MetaPipeEntity.java | 2 +- .../api/metatileentity/MetaTileEntity.java | 2 +- .../GT_MetaTileEntity_BasicGenerator.java | 2 +- .../GT_MetaTileEntity_BasicMachine.java | 2 +- .../GT_MetaTileEntity_MultiBlockBase.java | 2 +- src/main/java/gregtech/api/util/GT_BaseCrop.java | 10 ++-- src/main/java/gregtech/api/util/GT_FoodStat.java | 4 +- src/main/java/gregtech/api/util/GT_ModHandler.java | 57 +++++++++++----------- .../gregtech/api/util/GT_OreDictUnificator.java | 8 +-- src/main/java/gregtech/api/util/GT_Recipe.java | 18 +++---- src/main/java/gregtech/api/util/GT_Utility.java | 14 +++--- .../java/gregtech/common/GT_ThaumcraftCompat.java | 4 +- .../gregtech/common/entities/GT_Entity_Arrow.java | 2 +- .../common/gui/GT_Container_Regulator.java | 2 +- .../common/items/behaviors/Behaviour_DataOrb.java | 2 +- .../items/behaviors/Behaviour_Sonictron.java | 2 +- .../machines/basic/GT_MetaTileEntity_Scanner.java | 4 +- .../multi/GT_MetaTileEntity_DrillerBase.java | 2 +- .../GT_MetaTileEntity_PrimitiveBlastFurnace.java | 2 +- .../loaders/oreprocessing/ProcessingLog.java | 8 +-- .../java/gregtech/nei/GT_NEI_AssLineHandler.java | 6 +-- .../java/gregtech/nei/GT_NEI_DefaultHandler.java | 6 +-- 23 files changed, 86 insertions(+), 83 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/gui/GT_Container.java b/src/main/java/gregtech/api/gui/GT_Container.java index 608c6015d5..e00759bf24 100644 --- a/src/main/java/gregtech/api/gui/GT_Container.java +++ b/src/main/java/gregtech/api/gui/GT_Container.java @@ -142,7 +142,7 @@ public class GT_Container extends Container { if (aSlot != null && aSlot.canTakeStack(aPlayer)) { tTempStack = this.transferStackInSlot(aPlayer, aSlotIndex); if (tTempStack != null) { - rStack = GT_Utility.copy(tTempStack); + rStack = GT_Utility.copyOrNull(tTempStack); if (aSlot.getStack() != null && aSlot.getStack().getItem() == tTempStack.getItem()) { slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); } @@ -157,7 +157,7 @@ public class GT_Container extends Container { tTempStack = aSlot.getStack(); ItemStack var13 = aPlayerInventory.getItemStack(); if (tTempStack != null) { - rStack = GT_Utility.copy(tTempStack); + rStack = GT_Utility.copyOrNull(tTempStack); } if (tTempStack == null) { if (var13 != null && aSlot.isItemValid(var13)) { @@ -253,7 +253,7 @@ public class GT_Container extends Container { } else if (aShifthold == 3 && aPlayer.capabilities.isCreativeMode && aPlayerInventory.getItemStack() == null && aSlotIndex >= 0) { aSlot = (Slot) this.inventorySlots.get(aSlotIndex); if (aSlot != null && aSlot.getHasStack()) { - tTempStack = GT_Utility.copy(aSlot.getStack()); + tTempStack = GT_Utility.copyOrNull(aSlot.getStack()); tTempStack.stackSize = tTempStack.getMaxStackSize(); aPlayerInventory.setItemStack(tTempStack); } @@ -271,7 +271,7 @@ public class GT_Container extends Container { //null checks and checks if the item can be stacked (maxStackSize > 1) if (getSlotCount() > 0 && slotObject != null && slotObject.getHasStack() && !(slotObject instanceof GT_Slot_Holo)) { ItemStack stackInSlot = slotObject.getStack(); - stack = GT_Utility.copy(stackInSlot); + stack = GT_Utility.copyOrNull(stackInSlot); //TileEntity -> Player if (aSlotIndex < getAllSlotCount()) { diff --git a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java index 601b6fb4f9..1070c97364 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java @@ -503,7 +503,7 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { @Override public ItemStack decrStackSize(int aIndex, int aAmount) { - ItemStack tStack = getStackInSlot(aIndex), rStack = GT_Utility.copy(tStack); + ItemStack tStack = getStackInSlot(aIndex), rStack = GT_Utility.copyOrNull(tStack); if (tStack != null) { if (tStack.stackSize <= aAmount) { if (setStackToZeroInsteadOfNull(aIndex)) tStack.stackSize = 0; diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index 87eee3e6ac..d9f90b06b7 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -696,7 +696,7 @@ public abstract class MetaTileEntity implements IMetaTileEntity { @Override public ItemStack decrStackSize(int aIndex, int aAmount) { - ItemStack tStack = getStackInSlot(aIndex), rStack = GT_Utility.copy(tStack); + ItemStack tStack = getStackInSlot(aIndex), rStack = GT_Utility.copyOrNull(tStack); if (tStack != null) { if (tStack.stackSize <= aAmount) { if (setStackToZeroInsteadOfNull(aIndex)) tStack.stackSize = 0; diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java index ccc0fc0af4..9bbfbf0a3a 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java @@ -303,7 +303,7 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity public ItemStack getEmptyContainer(ItemStack aStack) { if (GT_Utility.isStackInvalid(aStack) || getRecipes() == null) return null; GT_Recipe tFuel = getRecipes().findRecipe(getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack); - if (tFuel != null) return GT_Utility.copy(tFuel.getOutput(0)); + if (tFuel != null) return GT_Utility.copyOrNull(tFuel.getOutput(0)); return GT_Utility.getContainerItem(aStack, true); } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java index 834344d2d2..5698eabc76 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java @@ -549,7 +549,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B for (int i = getInputSlot(), j = i + mInputSlotCount; i < j; i++) if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; for (int i = 0; i < mOutputItems.length; i++) { - mOutputItems[i] = GT_Utility.copy(mOutputItems[i]); + mOutputItems[i] = GT_Utility.copyOrNull(mOutputItems[i]); if (mOutputItems[i] != null && mOutputItems[i].stackSize > 64) mOutputItems[i].stackSize = 64; mOutputItems[i] = GT_OreDictUnificator.get(true, mOutputItems[i]); diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index 193b9d482c..0de4dfecbb 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -741,7 +741,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { public boolean addOutput(ItemStack aStack) { if (GT_Utility.isStackInvalid(aStack)) return false; - aStack = GT_Utility.copy(aStack); + aStack = GT_Utility.copyOrNull(aStack); for (GT_MetaTileEntity_Hatch_OutputBus tHatch : mOutputBusses) { if (isValidMetaTileEntity(tHatch) && tHatch.storeAll(aStack)) { return true; diff --git a/src/main/java/gregtech/api/util/GT_BaseCrop.java b/src/main/java/gregtech/api/util/GT_BaseCrop.java index c06bf82b89..97f8db0547 100644 --- a/src/main/java/gregtech/api/util/GT_BaseCrop.java +++ b/src/main/java/gregtech/api/util/GT_BaseCrop.java @@ -68,7 +68,7 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo { aID = GT_Config.addIDConfig(ConfigCategories.IDs.crops, mName.replaceAll(" ", "_"), aID); if (aDiscoveredBy != null && !aDiscoveredBy.equals(E)) mDiscoveredBy = aDiscoveredBy; if (aDrop != null && aID > 0 && aID < 256) { - mDrop = GT_Utility.copy(aDrop); + mDrop = GT_Utility.copyOrNull(aDrop); mSpecialDrops = aSpecialDrops; mTier = Math.max(1, aTier); mMaxSize = Math.max(3, aMaxSize); @@ -177,9 +177,9 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo { public ItemStack getGain(ICropTile aCrop) { int tDrop = 0; if (mSpecialDrops != null && (tDrop = java.util.concurrent.ThreadLocalRandom.current().nextInt(0, (mSpecialDrops.length*2) + 2)) < mSpecialDrops.length && mSpecialDrops[tDrop] != null) { - return GT_Utility.copy(mSpecialDrops[tDrop]); + return GT_Utility.copyOrNull(mSpecialDrops[tDrop]); } - return GT_Utility.copy(mDrop); + return GT_Utility.copyOrNull(mDrop); } @Override @@ -247,9 +247,9 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo { @Override public ItemStack getDisplayItem() { if (mSpecialDrops != null && mSpecialDrops[mSpecialDrops.length - 1] != null) { - return GT_Utility.copy(mSpecialDrops[mSpecialDrops.length - 1]); + return GT_Utility.copyOrNull(mSpecialDrops[mSpecialDrops.length - 1]); } - return GT_Utility.copy(mDrop); + return GT_Utility.copyOrNull(mDrop); } } diff --git a/src/main/java/gregtech/api/util/GT_FoodStat.java b/src/main/java/gregtech/api/util/GT_FoodStat.java index ce89881a5b..193977476a 100644 --- a/src/main/java/gregtech/api/util/GT_FoodStat.java +++ b/src/main/java/gregtech/api/util/GT_FoodStat.java @@ -36,7 +36,7 @@ public class GT_FoodStat implements IFoodStat { mSaturation = aSaturation; mAction = aAction == null ? EnumAction.eat : aAction; mPotionEffects = aPotionEffects; - mEmptyContainer = GT_Utility.copy(aEmptyContainer); + mEmptyContainer = GT_Utility.copyOrNull(aEmptyContainer); mInvisibleParticles = aInvisibleParticles; mAlwaysEdible = aAlwaysEdible; mIsRotten = aIsRotten; @@ -65,7 +65,7 @@ public class GT_FoodStat implements IFoodStat { @Override public void onEaten(GT_MetaBase_Item aItem, ItemStack aStack, EntityPlayer aPlayer) { aStack.stackSize--; - ItemStack tStack = GT_OreDictUnificator.get(GT_Utility.copy(mEmptyContainer)); + ItemStack tStack = GT_OreDictUnificator.get(GT_Utility.copyOrNull(mEmptyContainer)); if (tStack != null && !aPlayer.inventory.addItemStackToInventory(tStack)) aPlayer.dropPlayerItemWithRandomChoice(tStack, true); diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java index f82b0ecb7e..7e66e6cc2a 100644 --- a/src/main/java/gregtech/api/util/GT_ModHandler.java +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -460,8 +460,8 @@ public class GT_ModHandler { aChance = (float) GregTech_API.sRecipeFile.get(ConfigCategories.Machines.scrapboxdrops, aOutput, aChance); if (aChance <= 0) return false; try { - GT_Utility.callMethod(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), "addDrop", true, false, true, GT_Utility.copy(aOutput), aChance); - GT_Utility.callMethod(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), "addRecipe", true, true, false, GT_Utility.copy(aOutput), aChance); + GT_Utility.callMethod(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), "addDrop", true, false, true, GT_Utility.copyOrNull(aOutput), aChance); + GT_Utility.callMethod(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), "addRecipe", true, true, false, GT_Utility.copyOrNull(aOutput), aChance); } catch (Throwable e) {/*Do nothing*/} return true; } @@ -484,7 +484,7 @@ public class GT_ModHandler { aOutput = GT_OreDictUnificator.get(true, aOutput); if (aInput == null || aOutput == null || GT_Utility.getContainerItem(aInput, false) != null) return false; if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.smelting, aInput, true)) return false; - FurnaceRecipes.smelting().func_151394_a(aInput, GT_Utility.copy(aOutput), 0.0F); + FurnaceRecipes.smelting().func_151394_a(aInput, GT_Utility.copyOrNull(aOutput), 0.0F); return true; } @@ -562,8 +562,8 @@ public class GT_ModHandler { aOutput = GT_OreDictUnificator.get(true, aOutput); if (aInput == null || aOutput == null || aTime <= 0) return false; if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.rcblastfurnace, aInput, true)) return false; - aInput = GT_Utility.copy(aInput); - aOutput = GT_Utility.copy(aOutput); + aInput = GT_Utility.copyOrNull(aInput); + aOutput = GT_Utility.copyOrNull(aOutput); try { mods.railcraft.api.crafting.RailcraftCraftingManager.blastFurnace.addRecipe(aInput, true, false, aTime, aOutput); } catch (Throwable e) { @@ -614,28 +614,28 @@ public class GT_ModHandler { if (Materials.Wood.contains(aOutput1)) { if (aEnableTEMachineRecipes && GregTech_API.sRecipeFile.get(ConfigCategories.Machines.pulverization, aInput, true)) { if (aOutput2 == null) - ThermalExpansion.addSawmillRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1)); + ThermalExpansion.addSawmillRecipe(32000, GT_Utility.copyOrNull(aInput), GT_Utility.copyOrNull(aOutput1)); else - ThermalExpansion.addSawmillRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1), GT_Utility.copy(aOutput2), aChance2 <= 0 ? 10 : aChance2); + ThermalExpansion.addSawmillRecipe(32000, GT_Utility.copyOrNull(aInput), GT_Utility.copyOrNull(aOutput1), GT_Utility.copyOrNull(aOutput2), aChance2 <= 0 ? 10 : aChance2); } } else { if (GregTech_API.sRecipeFile.get(ConfigCategories.Machines.rockcrushing, aInput, true)) { try { if (GT_Utility.getBlockFromStack(aInput) != Blocks.obsidian && GT_Utility.getBlockFromStack(aInput) != Blocks.gravel) { mods.railcraft.api.crafting.IRockCrusherRecipe tRecipe = mods.railcraft.api.crafting.RailcraftCraftingManager.rockCrusher.createNewRecipe(GT_Utility.copyAmount(1, aInput), aInput.getItemDamage() != W, false); - tRecipe.addOutput(GT_Utility.copy(aOutput1), 1.0F / aInput.stackSize); + tRecipe.addOutput(GT_Utility.copyOrNull(aOutput1), 1.0F / aInput.stackSize); if (aOutput2 != null) - tRecipe.addOutput(GT_Utility.copy(aOutput2), (0.01F * (aChance2 <= 0 ? 10 : aChance2)) / aInput.stackSize); + tRecipe.addOutput(GT_Utility.copyOrNull(aOutput2), (0.01F * (aChance2 <= 0 ? 10 : aChance2)) / aInput.stackSize); if (aOutput3 != null) - tRecipe.addOutput(GT_Utility.copy(aOutput3), (0.01F * (aChance3 <= 0 ? 10 : aChance3)) / aInput.stackSize); + tRecipe.addOutput(GT_Utility.copyOrNull(aOutput3), (0.01F * (aChance3 <= 0 ? 10 : aChance3)) / aInput.stackSize); } } catch (Throwable e) {/*Do nothing*/} } if (aEnableTEMachineRecipes && GregTech_API.sRecipeFile.get(ConfigCategories.Machines.pulverization, aInput, true)) { if (aOutput2 == null) - ThermalExpansion.addPulverizerRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1)); + ThermalExpansion.addPulverizerRecipe(32000, GT_Utility.copyOrNull(aInput), GT_Utility.copyOrNull(aOutput1)); else - ThermalExpansion.addPulverizerRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1), GT_Utility.copy(aOutput2), aChance2 <= 0 ? 10 : aChance2); + ThermalExpansion.addPulverizerRecipe(32000, GT_Utility.copyOrNull(aInput), GT_Utility.copyOrNull(aOutput1), GT_Utility.copyOrNull(aOutput2), aChance2 <= 0 ? 10 : aChance2); } } } @@ -702,7 +702,7 @@ public class GT_ModHandler { if (!GT_Mod.gregtechproxy.mTEMachineRecipes && !GregTech_API.sRecipeFile.get(ConfigCategories.Machines.inductionsmelter, aInput2 == null ? aInput1 : aOutput1, true)) return false; try { - ThermalExpansion.addSmelterRecipe(aEnergy * 10, GT_Utility.copy(aInput1), aInput2 == null ? new ItemStack(Blocks.sand, 1, 0) : aInput2, aOutput1, aOutput2, aChance); + ThermalExpansion.addSmelterRecipe(aEnergy * 10, GT_Utility.copyOrNull(aInput1), aInput2 == null ? new ItemStack(Blocks.sand, 1, 0) : aInput2, aOutput1, aOutput2, aChance); } catch (Throwable e) {/*Do nothing*/} return true; } @@ -713,7 +713,7 @@ public class GT_ModHandler { public static boolean addOreToIngotSmeltingRecipe(ItemStack aInput, ItemStack aOutput) { aOutput = GT_OreDictUnificator.get(true, aOutput); if (aInput == null || aOutput == null) return false; - FurnaceRecipes.smelting().func_151394_a(aInput, GT_Utility.copy(aOutput), 0.0F); + FurnaceRecipes.smelting().func_151394_a(aInput, GT_Utility.copyOrNull(aOutput), 0.0F); return true; } @@ -847,9 +847,9 @@ public class GT_ModHandler { aResult = GT_OreDictUnificator.get(true, aResult); if (aResult == null || aRecipe == null || aResult.stackSize <= 0) return false; try { - mods.railcraft.api.crafting.RailcraftCraftingManager.rollingMachine.getRecipeList().add(new ShapedOreRecipe(GT_Utility.copy(aResult), aRecipe)); + mods.railcraft.api.crafting.RailcraftCraftingManager.rollingMachine.getRecipeList().add(new ShapedOreRecipe(GT_Utility.copyOrNull(aResult), aRecipe)); } catch (Throwable e) { - return addCraftingRecipe(GT_Utility.copy(aResult), aRecipe); + return addCraftingRecipe(GT_Utility.copyOrNull(aResult), aRecipe); } return true; } @@ -1084,8 +1084,9 @@ public class GT_ModHandler { Character chr = (Character) aRecipe[idx]; Object in = aRecipe[idx + 1]; if (in instanceof ItemStack) { - tItemStackMap.put(chr, GT_Utility.copy(in)); - tItemDataMap.put(chr, GT_OreDictUnificator.getItemData((ItemStack) in)); + ItemStack is = (ItemStack) in; + tItemStackMap.put(chr, GT_Utility.copyOrNull(is)); + tItemDataMap.put(chr, GT_OreDictUnificator.getItemData(is)); } else if (in instanceof ItemData) { String tString = in.toString(); switch (tString) { @@ -1184,9 +1185,9 @@ public class GT_ModHandler { if (tThereWasARecipe || !aOnlyAddIfThereIsAnyRecipeOutputtingThis) { if (sBufferCraftingRecipes && aBuffered) - sBufferRecipeList.add(new GT_Shaped_Recipe(GT_Utility.copy(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored)); + sBufferRecipeList.add(new GT_Shaped_Recipe(GT_Utility.copyOrNull(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored)); else - GameRegistry.addRecipe(new GT_Shaped_Recipe(GT_Utility.copy(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored)); + GameRegistry.addRecipe(new GT_Shaped_Recipe(GT_Utility.copyOrNull(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored)); } return true; } @@ -1260,9 +1261,9 @@ public class GT_ModHandler { GT_Utility.updateItemStack(aResult); if (sBufferCraftingRecipes && aBuffered) - sBufferRecipeList.add(new GT_Shapeless_Recipe(GT_Utility.copy(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe)); + sBufferRecipeList.add(new GT_Shapeless_Recipe(GT_Utility.copyOrNull(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe)); else - GameRegistry.addRecipe(new GT_Shapeless_Recipe(GT_Utility.copy(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe)); + GameRegistry.addRecipe(new GT_Shapeless_Recipe(GT_Utility.copyOrNull(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe)); return true; } @@ -1531,7 +1532,7 @@ public class GT_ModHandler { throw new GT_ItsNotMyFaultException("Seems another Mod added a Crafting Recipe with null Output. Tell the Developer of said Mod to fix that."); } else { if (aUncopiedStack) return tOutput; - return GT_Utility.copy(tOutput); + return GT_Utility.copyOrNull(tOutput); } } } @@ -1679,7 +1680,7 @@ public class GT_ModHandler { if (tRecipe instanceof ShapelessRecipes) continue; if (tRecipe instanceof ShapelessOreRecipe) continue; if (tRecipe instanceof IGT_CraftingRecipe) continue; - rList.add(GT_Utility.copy(tOutput)); + rList.add(GT_Utility.copyOrNull(tOutput)); aList.remove(i--); } } @@ -1691,7 +1692,7 @@ public class GT_ModHandler { */ @Deprecated public static ItemStack getMaceratorOutput(ItemStack aInput, boolean aRemoveInput, ItemStack aOutputSlot) { - return GT_Utility.copy(getMachineOutput(aInput, getMaceratorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]); + return GT_Utility.copyOrNull(getMachineOutput(aInput, getMaceratorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]); } /** @@ -1699,7 +1700,7 @@ public class GT_ModHandler { */ @Deprecated public static ItemStack getExtractorOutput(ItemStack aInput, boolean aRemoveInput, ItemStack aOutputSlot) { - return GT_Utility.copy(getMachineOutput(aInput, getExtractorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]); + return GT_Utility.copyOrNull(getMachineOutput(aInput, getExtractorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]); } /** @@ -1707,7 +1708,7 @@ public class GT_ModHandler { */ @Deprecated public static ItemStack getCompressorOutput(ItemStack aInput, boolean aRemoveInput, ItemStack aOutputSlot) { - return GT_Utility.copy(getMachineOutput(aInput, getCompressorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]); + return GT_Utility.copyOrNull(getMachineOutput(aInput, getCompressorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]); } /** @@ -1748,7 +1749,7 @@ public class GT_ModHandler { for (byte i = 0; i < aOutputSlots.length && i < tList.length; i++) { if (tList[i] != null) { if (aOutputSlots[i] == null || (GT_Utility.areStacksEqual(tList[i], aOutputSlots[i]) && tList[i].stackSize + aOutputSlots[i].stackSize <= aOutputSlots[i].getMaxStackSize())) { - rList[i] = GT_Utility.copy(tList[i]); + rList[i] = GT_Utility.copyOrNull(tList[i]); } else { return new ItemStack[aOutputSlots.length]; } diff --git a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java index 98809bbf45..54ef5b2866 100644 --- a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java +++ b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java @@ -123,7 +123,7 @@ public class GT_OreDictUnificator { } public static ItemStack[] setStackArray(boolean aUseBlackList, ItemStack... aStacks) { - for (int i = 0; i < aStacks.length; i++) aStacks[i] = get(aUseBlackList, GT_Utility.copy(aStacks[i])); + for (int i = 0; i < aStacks.length; i++) aStacks[i] = get(aUseBlackList, GT_Utility.copyOrNull(aStacks[i])); return aStacks; } @@ -155,15 +155,15 @@ public class GT_OreDictUnificator { ItemData tPrefixMaterial = getAssociation(aStack); ItemStack rStack = null; if (tPrefixMaterial == null || !tPrefixMaterial.hasValidPrefixMaterialData() || (aUseBlackList && tPrefixMaterial.mBlackListed)) - return GT_Utility.copy(aStack); + return GT_Utility.copyOrNull(aStack); if (aUseBlackList && !GregTech_API.sUnificationEntriesRegistered && isBlacklisted(aStack)) { tPrefixMaterial.mBlackListed = true; - return GT_Utility.copy(aStack); + return GT_Utility.copyOrNull(aStack); } if (tPrefixMaterial.mUnificationTarget == null) tPrefixMaterial.mUnificationTarget = sName2StackMap.get(tPrefixMaterial.toString()); rStack = tPrefixMaterial.mUnificationTarget; - if (GT_Utility.isStackInvalid(rStack)) return GT_Utility.copy(aStack); + if (GT_Utility.isStackInvalid(rStack)) return GT_Utility.copyOrNull(aStack); assert rStack != null; rStack.setTagCompound(aStack.getTagCompound()); return GT_Utility.copyAmount(aStack.stackSize, rStack); diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index aa54b55277..0214eab54b 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -312,12 +312,12 @@ public class GT_Recipe implements Comparable { public ItemStack getRepresentativeInput(int aIndex) { if (aIndex < 0 || aIndex >= mInputs.length) return null; - return GT_Utility.copy(mInputs[aIndex]); + return GT_Utility.copyOrNull(mInputs[aIndex]); } public ItemStack getOutput(int aIndex) { if (aIndex < 0 || aIndex >= mOutputs.length) return null; - return GT_Utility.copy(mOutputs[aIndex]); + return GT_Utility.copyOrNull(mOutputs[aIndex]); } public int getOutputChance(int aIndex) { @@ -1215,7 +1215,7 @@ public class GT_Recipe implements Comparable { public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot, ItemStack... aInputs) { if (aInputs == null || aInputs.length <= 0 || aInputs[0] == null) return null; if (aRecipe != null && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) return aRecipe; - ItemStack tComparedInput = GT_Utility.copy(aInputs[0]); + ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]); ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.compressor.getRecipes(), true, new NBTTagCompound(), null, null, null); return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, null, null, 400, 2, 0) : null; } @@ -1238,7 +1238,7 @@ public class GT_Recipe implements Comparable { public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot, ItemStack... aInputs) { if (aInputs == null || aInputs.length <= 0 || aInputs[0] == null) return null; if (aRecipe != null && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) return aRecipe; - ItemStack tComparedInput = GT_Utility.copy(aInputs[0]); + ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]); ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.extractor.getRecipes(), true, new NBTTagCompound(), null, null, null); return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, null, null, 400, 2, 0) : null; } @@ -1261,7 +1261,7 @@ public class GT_Recipe implements Comparable { public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot, ItemStack... aInputs) { if (aInputs == null || aInputs.length <= 0 || aInputs[0] == null) return null; if (aRecipe != null && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) return aRecipe; - ItemStack tComparedInput = GT_Utility.copy(aInputs[0]); + ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]); ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.centrifuge.getRecipes(), true, new NBTTagCompound(), null, null, null); return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, null, null, 400, 48, 0) : null; } @@ -1285,7 +1285,7 @@ public class GT_Recipe implements Comparable { if (aInputs == null || aInputs.length <= 0 || aInputs[0] == null || aFluids == null || aFluids.length < 1 || !GT_ModHandler.isWater(aFluids[0])) return null; if (aRecipe != null && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) return aRecipe; - ItemStack tComparedInput = GT_Utility.copy(aInputs[0]); + ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]); NBTTagCompound aRecipeMetaData = new NBTTagCompound(); ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.oreWashing.getRecipes(), true, aRecipeMetaData, null, null, null); return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, new FluidStack[]{new FluidStack(aFluids[0].getFluid(), ((NBTTagCompound) aRecipeMetaData.getTag("return")).getInteger("amount"))}, null, 400, 16, 0) : null; @@ -1334,7 +1334,7 @@ public class GT_Recipe implements Comparable { if (D1) GT_Log.err.println("Railcraft Not loaded"); } catch (NullPointerException e) {/**/} - ItemStack tComparedInput = GT_Utility.copy(aInputs[0]); + ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]); ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.macerator.getRecipes(), true, new NBTTagCompound(), null, null, null); return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, null, null, 400, 2, 0) : null; } @@ -1823,13 +1823,13 @@ public class GT_Recipe implements Comparable { if (mOreDictAlt[aIndex] != null && mOreDictAlt[aIndex].length > 0) { ItemStack[] rStacks = new ItemStack[mOreDictAlt[aIndex].length]; for (int i = 0; i < mOreDictAlt[aIndex].length; i++) { - rStacks[i] = GT_Utility.copy(mOreDictAlt[aIndex][i]); + rStacks[i] = GT_Utility.copyOrNull(mOreDictAlt[aIndex][i]); } return rStacks; } } if (aIndex >= mInputs.length) return null; - return GT_Utility.copy(mInputs[aIndex]); + return GT_Utility.copyOrNull(mInputs[aIndex]); } } diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 8e283956cb..8e839c8ba0 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -89,6 +89,8 @@ import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidContainerItem; import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.oredict.OreDictionary; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import javax.annotation.Nullable; import java.lang.reflect.Constructor; @@ -439,7 +441,7 @@ public class GT_Utility { if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlot, (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlot))) { if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) { ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlot).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlot)); - ItemStack rStack = ((IItemDuct) aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copy(tStack)); + ItemStack rStack = ((IItemDuct) aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copyOrNull(tStack)); byte tMovedItemCount = (byte) (tStack.stackSize - (rStack == null ? 0 : rStack.stackSize)); if (tMovedItemCount >= 1/*Math.max(aMinMoveAtOnce, aMinTargetStackSize)*/) { //((cofh.api.transport.IItemConduit)aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copyAmount(tMovedItemCount, tStack), F); @@ -459,7 +461,7 @@ public class GT_Utility { if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlot, (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlot))) { if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) { ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlot).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlot)); - byte tMovedItemCount = (byte) ((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copy(tStack), false, ForgeDirection.getOrientation(aPutTo)); + byte tMovedItemCount = (byte) ((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copyOrNull(tStack), false, ForgeDirection.getOrientation(aPutTo)); if (tMovedItemCount >= Math.max(aMinMoveAtOnce, aMinTargetStackSize)) { tMovedItemCount = (byte) (((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copyAmount(tMovedItemCount, tStack), true, ForgeDirection.getOrientation(aPutTo))); aTileEntity1.decrStackSize(aGrabSlot, tMovedItemCount); @@ -510,7 +512,7 @@ public class GT_Utility { ItemStack tStack1 = aTileEntity1.getStackInSlot(aGrabFrom), tStack2 = aTileEntity2.getStackInSlot(aPutTo), tStack3 = null; if (tStack1 != null) { if (tStack2 != null && !areStacksEqual(tStack1, tStack2)) return 0; - tStack3 = copy(tStack1); + tStack3 = copyOrNull(tStack1); aMaxTargetStackSize = (byte) Math.min(aMaxTargetStackSize, Math.min(tStack3.getMaxStackSize(), Math.min(tStack2 == null ? Integer.MAX_VALUE : tStack2.getMaxStackSize(), aTileEntity2.getInventoryStackLimit()))); tStack3.stackSize = Math.min(tStack3.stackSize, aMaxTargetStackSize - (tStack2 == null ? 0 : tStack2.stackSize)); if (tStack3.stackSize > aMaxMoveAtOnce) tStack3.stackSize = aMaxMoveAtOnce; @@ -519,7 +521,7 @@ public class GT_Utility { aTileEntity1.markDirty(); if (tStack3 != null) { if (tStack2 == null) { - aTileEntity2.setInventorySlotContents(aPutTo, copy(tStack3)); + aTileEntity2.setInventorySlotContents(aPutTo, copyOrNull(tStack3)); } else { tStack2.stackSize += tStack3.stackSize; } @@ -1147,7 +1149,7 @@ public class GT_Utility { if(tOreName.toString().equals("dustAsh")&&tStack[0].getUnlocalizedName().equals("tile.volcanicAsh"))return false; aRecipeList.put(new RecipeInputOreDict(tOreName.toString(), aInput.stackSize), new RecipeOutput(aNBT, tStack)); } else { - aRecipeList.put(new RecipeInputItemStack(copy(aInput), aInput.stackSize), new RecipeOutput(aNBT, tStack)); + aRecipeList.put(new RecipeInputItemStack(copyOrNull(aInput), aInput.stackSize), new RecipeOutput(aNBT, tStack)); } return true; } @@ -1191,7 +1193,7 @@ public class GT_Utility { rStack.setTagCompound(tNBT); GT_Log.out.println("GT_Mod: Added Book to Book List - Mapping: '" + aMapping + "' - Name: '" + aTitle + "' - Author: '" + aAuthor + "'"); GregTech_API.sBookList.put(aMapping, rStack); - return copy(rStack); + return copyOrNull(rStack); } public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength) { diff --git a/src/main/java/gregtech/common/GT_ThaumcraftCompat.java b/src/main/java/gregtech/common/GT_ThaumcraftCompat.java index bc6372e41c..e4472824e7 100644 --- a/src/main/java/gregtech/common/GT_ThaumcraftCompat.java +++ b/src/main/java/gregtech/common/GT_ThaumcraftCompat.java @@ -182,7 +182,7 @@ public class GT_ThaumcraftCompat implements IThaumcraftCompat { if ((GT_Utility.isStringInvalid(aResearch)) || (aInput == null) || (aOutput == null) || (aAspects == null) || (aAspects.isEmpty())) { return null; } - return ThaumcraftApi.addCrucibleRecipe(aResearch, GT_Utility.copy(new Object[]{aOutput}), ((aInput instanceof ItemStack)) || ((aInput instanceof ArrayList)) ? aInput : aInput.toString(), getAspectList(aAspects)); + return ThaumcraftApi.addCrucibleRecipe(aResearch, GT_Utility.copyOrNull(aOutput), ((aInput instanceof ItemStack)) || ((aInput instanceof ArrayList)) ? aInput : aInput.toString(), getAspectList(aAspects)); } @Override @@ -190,7 +190,7 @@ public class GT_ThaumcraftCompat implements IThaumcraftCompat { if ((GT_Utility.isStringInvalid(aResearch)) || (aMainInput == null) || (aSideInputs == null) || (aOutput == null) || (aAspects == null) || (aAspects.isEmpty())) { return null; } - return ThaumcraftApi.addInfusionCraftingRecipe(aResearch, GT_Utility.copy(new Object[]{aOutput}), aInstability, getAspectList(aAspects), aMainInput, aSideInputs); + return ThaumcraftApi.addInfusionCraftingRecipe(aResearch, GT_Utility.copyOrNull(aOutput), aInstability, getAspectList(aAspects), aMainInput, aSideInputs); } @Override diff --git a/src/main/java/gregtech/common/entities/GT_Entity_Arrow.java b/src/main/java/gregtech/common/entities/GT_Entity_Arrow.java index b7c87b4860..7a44ade127 100644 --- a/src/main/java/gregtech/common/entities/GT_Entity_Arrow.java +++ b/src/main/java/gregtech/common/entities/GT_Entity_Arrow.java @@ -345,7 +345,7 @@ public class GT_Entity_Arrow extends EntityArrow { } public ItemStack getArrowItem() { - return GT_Utility.copy(this.mArrow); + return GT_Utility.copyOrNull(this.mArrow); } public void setArrowItem(ItemStack aStack) { diff --git a/src/main/java/gregtech/common/gui/GT_Container_Regulator.java b/src/main/java/gregtech/common/gui/GT_Container_Regulator.java index f432c9b5d5..f50ac2dae3 100644 --- a/src/main/java/gregtech/common/gui/GT_Container_Regulator.java +++ b/src/main/java/gregtech/common/gui/GT_Container_Regulator.java @@ -81,7 +81,7 @@ public class GT_Container_Regulator extends GT_ContainerMetaTile_Machine { if ((aSlotIndex < 19)) { ItemStack tStack = aPlayer.inventory.getItemStack(); if (tStack != null) { - tSlot.putStack(GT_Utility.copy(new Object[]{tStack})); + tSlot.putStack(GT_Utility.copyOrNull(tStack)); } else if (tSlot.getStack() != null) { if (aMouseclick == 0) { tSlot.getStack().stackSize -= (aShifthold == 1 ? 8 : 1); diff --git a/src/main/java/gregtech/common/items/behaviors/Behaviour_DataOrb.java b/src/main/java/gregtech/common/items/behaviors/Behaviour_DataOrb.java index b909593694..a5393cdec5 100644 --- a/src/main/java/gregtech/common/items/behaviors/Behaviour_DataOrb.java +++ b/src/main/java/gregtech/common/items/behaviors/Behaviour_DataOrb.java @@ -14,7 +14,7 @@ public class Behaviour_DataOrb extends Behaviour_None { if (aNewContent[i] == null) { aInventory[i] = null; } else { - aInventory[i] = GT_Utility.copy(new Object[]{aNewContent[i]}); + aInventory[i] = GT_Utility.copyOrNull(aNewContent[i]); } } } diff --git a/src/main/java/gregtech/common/items/behaviors/Behaviour_Sonictron.java b/src/main/java/gregtech/common/items/behaviors/Behaviour_Sonictron.java index a0dea777f7..bcaa8242f3 100644 --- a/src/main/java/gregtech/common/items/behaviors/Behaviour_Sonictron.java +++ b/src/main/java/gregtech/common/items/behaviors/Behaviour_Sonictron.java @@ -90,7 +90,7 @@ public class Behaviour_Sonictron extends Behaviour_None { if (aNewContent[i] == null) { aInventory[i] = null; } else { - aInventory[i] = GT_Utility.copy(aNewContent[i]); + aInventory[i] = GT_Utility.copyOrNull(aNewContent[i]); } } } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Scanner.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Scanner.java index 11430c6862..eba61ad1b1 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Scanner.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Scanner.java @@ -86,7 +86,7 @@ public class GT_MetaTileEntity_Scanner extends GT_MetaTileEntity_BasicMachine { if (tIndividual != null) { if (tIndividual.analyze()) { getFillableStack().amount -= 100; - this.mOutputItems[0] = GT_Utility.copy(aStack); + this.mOutputItems[0] = GT_Utility.copyOrNull(aStack); aStack.stackSize = 0; NBTTagCompound tNBT = new NBTTagCompound(); tIndividual.writeToNBT(tNBT); @@ -97,7 +97,7 @@ public class GT_MetaTileEntity_Scanner extends GT_MetaTileEntity_BasicMachine { return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; return 2; } - this.mOutputItems[0] = GT_Utility.copy(aStack); + this.mOutputItems[0] = GT_Utility.copyOrNull(aStack); aStack.stackSize = 0; this.mMaxProgresstime = 1; this.mEUt = 1; diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java index d7b7e2aa4d..a57a237060 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java @@ -207,7 +207,7 @@ public abstract class GT_MetaTileEntity_DrillerBase extends GT_MetaTileEntity_Mu if (!storedItem.isItemEqual(miningPipe)) continue; if (pipes == null) { - setInventorySlotContents(1, GT_Utility.copy(miningPipe)); + setInventorySlotContents(1, GT_Utility.copyOrNull(miningPipe)); pipes = getStackInSlot(1); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java index f1b304a1b1..eab4e9c896 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java @@ -282,7 +282,7 @@ public abstract class GT_MetaTileEntity_PrimitiveBlastFurnace extends MetaTileEn for (int i = 0; i < limit; i++) { int absi = INPUT_SLOTS + i; if (this.mInventory[absi] == null) { - this.mInventory[absi] = GT_Utility.copy(this.mOutputItems[i]); + this.mInventory[absi] = GT_Utility.copyOrNull(this.mOutputItems[i]); } else if (GT_Utility.areStacksEqual(this.mInventory[absi], this.mOutputItems[i])) { this.mInventory[absi].stackSize = Math.min(this.mInventory[absi].getMaxStackSize(), this.mInventory[absi].stackSize + this.mOutputItems[i].stackSize); diff --git a/src/main/java/gregtech/loaders/oreprocessing/ProcessingLog.java b/src/main/java/gregtech/loaders/oreprocessing/ProcessingLog.java index dfccc35684..fc60328e44 100644 --- a/src/main/java/gregtech/loaders/oreprocessing/ProcessingLog.java +++ b/src/main/java/gregtech/loaders/oreprocessing/ProcessingLog.java @@ -56,9 +56,9 @@ public class ProcessingLog implements gregtech.api.interfaces.IOreRecipeRegistra } else { - ItemStack tPlanks = GT_Utility.copy(tStack); + ItemStack tPlanks = GT_Utility.copyOrNull(tStack); tPlanks.stackSize = (tPlanks.stackSize * 3 / 2); - GT_Values.RA.addCutterRecipe(new ItemStack(aStack.getItem(), 1, i), Materials.Lubricant.getFluid(1L), GT_Utility.copy(tPlanks), GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 1L), 200, 8); + GT_Values.RA.addCutterRecipe(new ItemStack(aStack.getItem(), 1, i), Materials.Lubricant.getFluid(1L), GT_Utility.copyOrNull(tPlanks), GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 1L), 200, 8); GT_Values.RA.addCutterRecipe(new ItemStack(aStack.getItem(), 1, i), GT_Utility.copyAmount(GT_Mod.gregtechproxy.mNerfedWoodPlank ? tStack.stackSize : tStack.stackSize * 5 / 4, tStack), GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 2L), 200, 8); GT_ModHandler.addSawmillRecipe(new ItemStack(aStack.getItem(), 1, i), tPlanks, GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 1L)); GT_ModHandler.removeRecipeDelayed(new ItemStack(aStack.getItem(), 1, i)); @@ -75,9 +75,9 @@ public class ProcessingLog implements gregtech.api.interfaces.IOreRecipeRegistra } ItemStack tStack = GT_ModHandler.getRecipeOutput(GT_Utility.copyAmount(1L, aStack)); if (tStack != null) { - ItemStack tPlanks = GT_Utility.copy(tStack); + ItemStack tPlanks = GT_Utility.copyOrNull(tStack); tPlanks.stackSize = (tPlanks.stackSize * 3 / 2); - GT_Values.RA.addCutterRecipe(GT_Utility.copyAmount(1L, aStack), Materials.Lubricant.getFluid(1L), GT_Utility.copy(tPlanks), GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 1L), 200, 8); + GT_Values.RA.addCutterRecipe(GT_Utility.copyAmount(1L, aStack), Materials.Lubricant.getFluid(1L), GT_Utility.copyOrNull(tPlanks), GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 1L), 200, 8); GT_Values.RA.addCutterRecipe(GT_Utility.copyAmount(1L, aStack), GT_Utility.copyAmount(GT_Mod.gregtechproxy.mNerfedWoodPlank ? tStack.stackSize : tStack.stackSize * 5 / 4, tStack), GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 2L), 200, 8); GT_ModHandler.addSawmillRecipe(GT_Utility.copyAmount(1L, aStack), tPlanks, GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 1L)); GT_ModHandler.removeRecipeDelayed(GT_Utility.copyAmount(1L, aStack)); diff --git a/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java b/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java index 6c315edb42..c692a2dce1 100644 --- a/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java @@ -105,7 +105,7 @@ public class GT_NEI_AssLineHandler extends TemplateRecipeHandler { tResults.add(GT_Utility.getFluidDisplayStack(tFluid, false)); for (FluidContainerRegistry.FluidContainerData tData : FluidContainerRegistry.getRegisteredFluidContainerData()) { if (tData.fluid.isFluidEqual(tFluid)) { - tResults.add(GT_Utility.copy(tData.filledContainer)); + tResults.add(GT_Utility.copyOrNull(tData.filledContainer)); } } } @@ -147,7 +147,7 @@ public class GT_NEI_AssLineHandler extends TemplateRecipeHandler { tInputs.add(GT_Utility.getFluidDisplayStack(tFluid, false)); for (FluidContainerRegistry.FluidContainerData tData : FluidContainerRegistry.getRegisteredFluidContainerData()) { if (tData.fluid.isFluidEqual(tFluid)) { - tInputs.add(GT_Utility.copy(tData.filledContainer)); + tInputs.add(GT_Utility.copyOrNull(tData.filledContainer)); } } } @@ -370,7 +370,7 @@ public class GT_NEI_AssLineHandler extends TemplateRecipeHandler { tDisplayStacks.add(base); } } else { - tDisplayStacks.add(GT_Utility.copy(new Object[]{tStack})); + tDisplayStacks.add(GT_Utility.copyOrNull(tStack)); } } } diff --git a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java index f37eea25e9..a4fc75a24e 100644 --- a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java @@ -102,7 +102,7 @@ public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { tResults.add(GT_Utility.getFluidDisplayStack(tFluid, false)); for (FluidContainerRegistry.FluidContainerData tData : FluidContainerRegistry.getRegisteredFluidContainerData()) { if (tData.fluid.isFluidEqual(tFluid)) { - tResults.add(GT_Utility.copy(tData.filledContainer)); + tResults.add(GT_Utility.copyOrNull(tData.filledContainer)); } } } @@ -136,7 +136,7 @@ public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { tInputs.add(GT_Utility.getFluidDisplayStack(tFluid, false)); for (FluidContainerRegistry.FluidContainerData tData : FluidContainerRegistry.getRegisteredFluidContainerData()) { if (tData.fluid.isFluidEqual(tFluid)) { - tInputs.add(GT_Utility.copy(tData.filledContainer)); + tInputs.add(GT_Utility.copyOrNull(tData.filledContainer)); } } } @@ -385,7 +385,7 @@ public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { tDisplayStacks.add(base); } } else { - tDisplayStacks.add(GT_Utility.copy(tStack)); + tDisplayStacks.add(GT_Utility.copyOrNull(tStack)); } } } -- cgit From 86c442947a6778e66b761cb2cee7a88782eb363a Mon Sep 17 00:00:00 2001 From: TimeConqueror Date: Thu, 15 Jul 2021 18:29:26 +0300 Subject: Removed useless method callings --- src/main/java/gregtech/api/GregTech_API.java | 12 +++++++----- src/main/java/gregtech/api/util/GT_Utility.java | 5 ++++- .../tileentities/machines/basic/GT_MetaTileEntity_Pump.java | 8 ++++---- 3 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/GregTech_API.java b/src/main/java/gregtech/api/GregTech_API.java index ba7e3ab43e..3133536de2 100644 --- a/src/main/java/gregtech/api/GregTech_API.java +++ b/src/main/java/gregtech/api/GregTech_API.java @@ -426,7 +426,7 @@ public class GregTech_API { * @param aMeta the Metadata of the Blocks as Bitmask! -1 or ~0 for all Metavalues */ public static boolean registerMachineBlock(Block aBlock, int aMeta) { - if (GT_Utility.isBlockInvalid(aBlock)) + if (aBlock == null) return false; if (GregTech_API.sThaumcraftCompat != null) GregTech_API.sThaumcraftCompat.registerPortholeBlacklistedBlock(aBlock); @@ -438,7 +438,7 @@ public class GregTech_API { * Like above but with boolean Parameters instead of a BitMask */ public static boolean registerMachineBlock(Block aBlock, boolean... aMeta) { - if (GT_Utility.isBlockInvalid(aBlock) || aMeta == null || aMeta.length == 0) + if (aBlock == null || aMeta == null || aMeta.length == 0) return false; if (GregTech_API.sThaumcraftCompat != null) GregTech_API.sThaumcraftCompat.registerPortholeBlacklistedBlock(aBlock); @@ -452,9 +452,11 @@ public class GregTech_API { * if this Block is a Machine Update Conducting Block */ public static boolean isMachineBlock(Block aBlock, int aMeta) { - if (GT_Utility.isBlockInvalid(aBlock)) - return false; - return (sMachineIDs.containsKey(aBlock) && (sMachineIDs.get(aBlock) & B[aMeta]) != 0); + if (aBlock != null) { + Integer id = sMachineIDs.get(aBlock); + return id != null && (id & B[aMeta]) != 0; + } + return false; } /** diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 8e839c8ba0..165ff71927 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -1286,6 +1286,7 @@ public class GT_Utility { return rList; } + @Deprecated // why do you use Objects? public static Block getBlock(Object aBlock) { return (Block) aBlock; } @@ -1299,12 +1300,14 @@ public class GT_Utility { return Block.getBlockFromItem(item); } + @Deprecated // why do you use Objects? And if you want to check your block to be not null, check it directly! public static boolean isBlockValid(Object aBlock) { return (aBlock instanceof Block); } + @Deprecated // why do you use Objects? And if you want to check your block to be null, check it directly! public static boolean isBlockInvalid(Object aBlock) { - return aBlock == null || !(aBlock instanceof Block); + return !(aBlock instanceof Block); } public static boolean isStringValid(Object aString) { diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Pump.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Pump.java index e1dfc32aba..431241eb84 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Pump.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Pump.java @@ -366,7 +366,7 @@ public class GT_MetaTileEntity_Pump extends GT_MetaTileEntity_Hatch { } private boolean hasValidFluid() { - return (!GT_Utility.isBlockInvalid(this.mPrimaryPumpedBlock) && !GT_Utility.isBlockInvalid(this.mSecondaryPumpedBlock)); + return mPrimaryPumpedBlock != null && mSecondaryPumpedBlock != null; } private boolean moveOneDown() { @@ -522,7 +522,7 @@ public class GT_MetaTileEntity_Pump extends GT_MetaTileEntity_Hatch { return; Block aBlock = getBaseMetaTileEntity().getBlock(aX, aY, aZ); - if (GT_Utility.isBlockValid(aBlock)) { + if (aBlock != null) { if ((aBlock == Blocks.water) || (aBlock == Blocks.flowing_water)) { this.mPrimaryPumpedBlock = Blocks.water; this.mSecondaryPumpedBlock = Blocks.flowing_water; @@ -549,7 +549,7 @@ public class GT_MetaTileEntity_Pump extends GT_MetaTileEntity_Hatch { Block aBlock = getBaseMetaTileEntity().getBlock(aX, aY, aZ); - return GT_Utility.isBlockValid(aBlock) && + return aBlock != null && (aBlock == Blocks.water || aBlock == Blocks.flowing_water || aBlock == Blocks.lava || @@ -565,7 +565,7 @@ public class GT_MetaTileEntity_Pump extends GT_MetaTileEntity_Hatch { Block aBlock = getBaseMetaTileEntity().getBlock(aX, aY, aZ); - if ((GT_Utility.isBlockValid(aBlock)) && ((this.mPrimaryPumpedBlock == aBlock) || (this.mSecondaryPumpedBlock == aBlock))) { + if (aBlock != null && ((this.mPrimaryPumpedBlock == aBlock) || (this.mSecondaryPumpedBlock == aBlock))) { boolean isWaterOrLava = ((this.mPrimaryPumpedBlock == Blocks.water || this.mPrimaryPumpedBlock == Blocks.lava)); if (isWaterOrLava && getBaseMetaTileEntity().getMetaID(aX, aY, aZ) != 0) { -- cgit From 43dbba9c51369dd229f8a0c349c3109d22dbac15 Mon Sep 17 00:00:00 2001 From: GlodBlock <60341015+GlodBlock@users.noreply.github.com> Date: Wed, 21 Jul 2021 23:19:40 +0800 Subject: make it thread safe --- src/main/java/gregtech/api/util/GT_Recipe.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 315d70a522..d970175560 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -23,6 +23,7 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidContainerItem; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import static gregtech.api.enums.GT_Values.*; @@ -388,7 +389,7 @@ public class GT_Recipe implements Comparable { if (mInputs.length > 0 && aInputs == null) return false; - HashSet isUsed = new HashSet<>(); + ConcurrentHashMap isUsed = new ConcurrentHashMap<>(); for (ItemStack tStack : mInputs) { ItemStack unified_tStack = GT_OreDictUnificator.get_nocopy(true, tStack); @@ -398,8 +399,8 @@ public class GT_Recipe implements Comparable { int it = 0; for (ItemStack aStack : aInputs) { it ++; - if (GT_OreDictUnificator.isInputStackEqual(aStack, unified_tStack) && !isUsed.contains(it)) { - isUsed.add(it); + if (GT_OreDictUnificator.isInputStackEqual(aStack, unified_tStack) && !isUsed.containsKey(it)) { + isUsed.put(it, true); if (GTppRecipeHelper) {//remove once the fix is out if (GT_Utility.areStacksEqual(aStack, Ic2Items.FluidCell.copy(), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataStick.get(1L), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataOrb.get(1L), true)) { if (!GT_Utility.areStacksEqual(aStack, tStack, false)) -- cgit From 41044b43def2259f87c1a5e0a3bc67dcfaea52cd Mon Sep 17 00:00:00 2001 From: GlodBlock <60341015+GlodBlock@users.noreply.github.com> Date: Thu, 22 Jul 2021 00:03:26 +0800 Subject: change it into hashset back --- src/main/java/gregtech/api/util/GT_Recipe.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 5db314ed30..5a337922d3 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -366,6 +366,9 @@ public class GT_Recipe implements Comparable { public static boolean GTppRecipeHelper; public boolean isRecipeInputEqual(boolean aDecreaseStacksizeBySuccess, boolean aDontCheckStackSizes, FluidStack[] aFluidInputs, ItemStack... aInputs) { + + HashSet isVisited = new HashSet<>(); + if (mFluidInputs.length > 0 && aFluidInputs == null) return false; int amt; for (FluidStack tFluid : mFluidInputs) @@ -389,8 +392,6 @@ public class GT_Recipe implements Comparable { if (mInputs.length > 0 && aInputs == null) return false; - ConcurrentHashMap isUsed = new ConcurrentHashMap<>(); - for (ItemStack tStack : mInputs) { ItemStack unified_tStack = GT_OreDictUnificator.get_nocopy(true, tStack); if (unified_tStack != null) { @@ -399,8 +400,8 @@ public class GT_Recipe implements Comparable { int it = 0; for (ItemStack aStack : aInputs) { it ++; - if (GT_OreDictUnificator.isInputStackEqual(aStack, unified_tStack) && !isUsed.containsKey(it)) { - isUsed.put(it, true); + if (GT_OreDictUnificator.isInputStackEqual(aStack, unified_tStack) && !isVisited.contains(it)) { + isVisited.add(it); if (GTppRecipeHelper) {//remove once the fix is out if (GT_Utility.areStacksEqual(aStack, Ic2Items.FluidCell.copy(), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataStick.get(1L), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataOrb.get(1L), true)) { if (!GT_Utility.areStacksEqual(aStack, tStack, false)) -- cgit From 7ed5c6119dbe26a6916d6f9b99b8aa87a7b26ee2 Mon Sep 17 00:00:00 2001 From: GlodBlock <60341015+GlodBlock@users.noreply.github.com> Date: Thu, 22 Jul 2021 00:12:23 +0800 Subject: Update GT_Recipe.java --- src/main/java/gregtech/api/util/GT_Recipe.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 5a337922d3..a04df205b7 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -367,8 +367,7 @@ public class GT_Recipe implements Comparable { public boolean isRecipeInputEqual(boolean aDecreaseStacksizeBySuccess, boolean aDontCheckStackSizes, FluidStack[] aFluidInputs, ItemStack... aInputs) { - HashSet isVisited = new HashSet<>(); - + if (mInputs.length > 0 && aInputs == null) return false; if (mFluidInputs.length > 0 && aFluidInputs == null) return false; int amt; for (FluidStack tFluid : mFluidInputs) @@ -390,8 +389,8 @@ public class GT_Recipe implements Comparable { if (temp) return false; } - if (mInputs.length > 0 && aInputs == null) return false; - + HashSet isVisited = new HashSet<>(); + for (ItemStack tStack : mInputs) { ItemStack unified_tStack = GT_OreDictUnificator.get_nocopy(true, tStack); if (unified_tStack != null) { -- cgit From de8829ca474fd3a8e7b3d4c64d5c70b00c8070e0 Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Thu, 29 Jul 2021 19:11:41 -0600 Subject: Oredict clay buckets + fix railcraft item IDs --- build.properties | 2 +- src/main/java/gregtech/api/util/GT_ModHandler.java | 8 ++++---- src/main/java/gregtech/common/GT_Proxy.java | 6 ++++++ .../gregtech/loaders/preload/GT_Loader_OreDictionary.java | 11 ++++++----- 4 files changed, 17 insertions(+), 10 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/build.properties b/build.properties index 14b31b0cc5..a553d39ee7 100644 --- a/build.properties +++ b/build.properties @@ -1,6 +1,6 @@ minecraft.version=1.7.10 forge.version=10.13.4.1614-1.7.10 -gt.version=5.09.37.02 +gt.version=5.09.37.03 ae2.version=rv3-beta-22 applecore.version=1.7.10-1.2.1+107.59407 buildcraft.version=7.1.11 diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java index 7e66e6cc2a..ac9f7bd3d4 100644 --- a/src/main/java/gregtech/api/util/GT_ModHandler.java +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -383,14 +383,14 @@ public class GT_ModHandler { } /** - * Gets an Item from RailCraft + * Gets an Item from the specified mod */ public static ItemStack getModItem(String aModID, String aItem, long aAmount) { return getModItem(aModID, aItem, aAmount, null); } /** - * Gets an Item from RailCraft, and returns a Replacement Item if not possible + * Gets an Item from the specified mod, and returns a Replacement Item if not possible */ public static ItemStack getModItem(String aModID, String aItem, long aAmount, ItemStack aReplacement) { if (GT_Utility.isStringInvalid(aItem) || !GregTech_API.sPreloadStarted) return null; @@ -398,7 +398,7 @@ public class GT_ModHandler { } /** - * Gets an Item from RailCraft, but the Damage Value can be specified + * Gets an Item from the specified mod, but the Damage Value can be specified */ public static ItemStack getModItem(String aModID, String aItem, long aAmount, int aMeta) { ItemStack rStack = getModItem(aModID, aItem, aAmount); @@ -408,7 +408,7 @@ public class GT_ModHandler { } /** - * Gets an Item from RailCraft, but the Damage Value can be specified, and returns a Replacement Item with the same Damage if not possible + * Gets an Item from the specified mod, but the Damage Value can be specified, and returns a Replacement Item with the same Damage if not possible */ public static ItemStack getModItem(String aModID, String aItem, long aAmount, int aMeta, ItemStack aReplacement) { ItemStack rStack = getModItem(aModID, aItem, aAmount, aReplacement); diff --git a/src/main/java/gregtech/common/GT_Proxy.java b/src/main/java/gregtech/common/GT_Proxy.java index e35661a617..6006b77626 100644 --- a/src/main/java/gregtech/common/GT_Proxy.java +++ b/src/main/java/gregtech/common/GT_Proxy.java @@ -553,6 +553,12 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { GT_OreDictUnificator.registerOre("cropGrape", GT_ModHandler.getModItem("magicalcrops", "magicalcrops_CropProduce", 1L, 4)); GT_OreDictUnificator.registerOre("cropTea", GT_ModHandler.getModItem("ganyssurface", "teaLeaves", 1L, 0)); + // Clay buckets, which don't get registered until Iguana Tweaks pre-init + GT_OreDictUnificator.set(OrePrefixes.bucket, Materials.Empty, GT_ModHandler.getModItem("IguanaTweaksTConstruct", "clayBucketFired", 1L, 0)); + GT_OreDictUnificator.set(OrePrefixes.bucket, Materials.Water, GT_ModHandler.getModItem("IguanaTweaksTConstruct", "clayBucketWater", 1L, 0)); + GT_OreDictUnificator.set(OrePrefixes.bucket, Materials.Lava, GT_ModHandler.getModItem("IguanaTweaksTConstruct", "clayBucketLava", 1L, 0)); + GT_OreDictUnificator.set(OrePrefixes.bucket, Materials.Milk, GT_ModHandler.getModItem("IguanaTweaksTConstruct", "clayBucketMilk", 1L, 0)); + // IC2 Hazmat addFullHazmatToIC2Item("hazmatHelmet"); addFullHazmatToIC2Item("hazmatChestplate"); diff --git a/src/main/java/gregtech/loaders/preload/GT_Loader_OreDictionary.java b/src/main/java/gregtech/loaders/preload/GT_Loader_OreDictionary.java index efb54fa25d..7165650072 100644 --- a/src/main/java/gregtech/loaders/preload/GT_Loader_OreDictionary.java +++ b/src/main/java/gregtech/loaders/preload/GT_Loader_OreDictionary.java @@ -31,6 +31,7 @@ public class GT_Loader_OreDictionary implements Runnable { GT_OreDictUnificator.set(OrePrefixes.bucket, Materials.Water, new ItemStack(Items.water_bucket, 1, 0)); GT_OreDictUnificator.set(OrePrefixes.bucket, Materials.Lava, new ItemStack(Items.lava_bucket, 1, 0)); GT_OreDictUnificator.set(OrePrefixes.bucket, Materials.Milk, new ItemStack(Items.milk_bucket, 1, 0)); + // Clay buckets handled in gregtech.common.GT_Proxy.onLoad() as they aren't registered until Iguana Tweaks pre-init. GT_OreDictUnificator.set(OrePrefixes.bottle, Materials.Empty, new ItemStack(Items.glass_bottle, 1, 0)); GT_OreDictUnificator.set(OrePrefixes.bottle, Materials.Water, new ItemStack(Items.potionitem, 1, 0)); @@ -88,16 +89,16 @@ public class GT_Loader_OreDictionary implements Runnable { GT_OreDictUnificator.registerOre(OreDictNames.enderChest, new ItemStack(Blocks.ender_chest, 1)); } GT_OreDictUnificator.registerOre(OreDictNames.craftingAnvil, new ItemStack(Blocks.anvil, 1)); - GT_OreDictUnificator.registerOre(OreDictNames.craftingAnvil, GT_ModHandler.getModItem("Railcraft", "tile.railcraft.anvil", 1L, 0)); + GT_OreDictUnificator.registerOre(OreDictNames.craftingAnvil, GT_ModHandler.getModItem("Railcraft", "anvil", 1L, 0)); GT_OreDictUnificator.registerOre(OreDictNames.craftingIndustrialDiamond, ItemList.IC2_Industrial_Diamond.get(1L)); GT_OreDictUnificator.registerOre(OrePrefixes.dust, Materials.Wood, GT_ModHandler.getModItem("ThermalExpansion", "sawdust", 1L)); GT_OreDictUnificator.registerOre(OrePrefixes.glass, Materials.Reinforced, GT_ModHandler.getIC2Item("reinforcedGlass", 1L)); GT_OreDictUnificator.registerOre(OrePrefixes.glass, Materials.Reinforced, GT_ModHandler.getModItem("ThermalExpansion", "glassHardened", 1L)); - GT_OreDictUnificator.registerOre(OrePrefixes.stone, Materials.Basalt, GT_ModHandler.getModItem("Railcraft", "tile.railcraft.cube", 1L, 6)); - GT_OreDictUnificator.registerOre(OrePrefixes.stone, Materials.Marble, GT_ModHandler.getModItem("Railcraft", "tile.railcraft.cube", 1L, 7)); - GT_OreDictUnificator.registerOre(OrePrefixes.stone, Materials.Basalt, GT_ModHandler.getModItem("Railcraft", "tile.railcraft.brick.abyssal", 1L, 32767)); - GT_OreDictUnificator.registerOre(OrePrefixes.stone, Materials.Marble, GT_ModHandler.getModItem("Railcraft", "tile.railcraft.brick.quarried", 1L, 32767)); + GT_OreDictUnificator.registerOre(OrePrefixes.stone, Materials.Basalt, GT_ModHandler.getModItem("Railcraft", "cube", 1L, 6)); + GT_OreDictUnificator.registerOre(OrePrefixes.stone, Materials.Marble, GT_ModHandler.getModItem("Railcraft", "cube", 1L, 7)); + GT_OreDictUnificator.registerOre(OrePrefixes.stone, Materials.Basalt, GT_ModHandler.getModItem("Railcraft", "brick.abyssal", 1L, 32767)); + GT_OreDictUnificator.registerOre(OrePrefixes.stone, Materials.Marble, GT_ModHandler.getModItem("Railcraft", "brick.quarried", 1L, 32767)); GT_OreDictUnificator.registerOre(OrePrefixes.stone, Materials.Obsidian, new ItemStack(Blocks.obsidian, 1, 32767)); GT_OreDictUnificator.registerOre(OrePrefixes.stone, Materials.Stone, new ItemStack(Blocks.stone, 1, 32767)); GT_OreDictUnificator.registerOre(OrePrefixes.stoneMossy, new ItemStack(Blocks.mossy_cobblestone, 1, 32767)); -- cgit From 546b42d7440839477455b818133d80221c70c582 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sat, 29 May 2021 23:52:15 +0800 Subject: Initial StructureLib integration --- build.gradle | 7 +- build.properties | 1 + src/main/java/gregtech/GT_Mod.java | 1 + .../api/metatileentity/BaseMetaTileEntity.java | 35 ++++- .../GT_MetaTileEntity_EnhancedMultiBlockBase.java | 122 +++++++++++++++++ .../GT_MetaTileEntity_MultiBlockBase.java | 9 +- .../gregtech/api/util/GT_StructureUtility.java | 71 ++++++++++ .../java/gregtech/api/util/IGT_HatchAdder.java | 14 ++ .../GT_MetaTileEntity_AbstractMultiFurnace.java | 72 ++++------ .../GT_MetaTileEntity_ElectricBlastFurnace.java | 146 +++++++++------------ .../multi/GT_MetaTileEntity_MultiFurnace.java | 82 +++++------- src/main/resources/mcmod.info | 3 +- 12 files changed, 368 insertions(+), 195 deletions(-) create mode 100644 src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java create mode 100644 src/main/java/gregtech/api/util/GT_StructureUtility.java create mode 100644 src/main/java/gregtech/api/util/IGT_HatchAdder.java (limited to 'src/main/java/gregtech/api/util') diff --git a/build.gradle b/build.gradle index 8949f060c3..a69dd021b5 100644 --- a/build.gradle +++ b/build.gradle @@ -55,7 +55,7 @@ repositories { } maven { name = "chickenbones" - url = "http://chickenbones.net/maven/" + url = "https://nexus.covers1624.net/repository/maven-hosted/" } maven { name = "ic2, forestry" @@ -84,12 +84,17 @@ repositories { name = 'gtnh_download_source' artifactPattern("http://downloads.gtnewhorizons.com/Mods_for_Jenkins/[module]-[revision].[ext]") } + maven { + name = "jitpack.io" + url = "https://jitpack.io" + } } dependencies { //Hard dep to start (Without this, it wont compile nor start) compile 'com.google.code.findbugs:jsr305:1.3.9' compile "net.industrial-craft:industrialcraft-2:${config.ic2.version}:dev" + compile ("com.github.GTNewHorizons:StructureLib:${config.structurelib.version}:deobf") //Hard dep to compile (Without this, it wont compile, not even as library) api "appeng:appliedenergistics2:${config.ae2.version}:dev" diff --git a/build.properties b/build.properties index 14b31b0cc5..8392f3c2a1 100644 --- a/build.properties +++ b/build.properties @@ -1,6 +1,7 @@ minecraft.version=1.7.10 forge.version=10.13.4.1614-1.7.10 gt.version=5.09.37.02 +structurelib.version=1.0.1 ae2.version=rv3-beta-22 applecore.version=1.7.10-1.2.1+107.59407 buildcraft.version=7.1.11 diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index c601130ab9..d9a8d72ecd 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -74,6 +74,7 @@ import static gregtech.api.enums.GT_Values.MOD_ID_FR; @SuppressWarnings("ALL") @Mod(modid = "gregtech", name = "GregTech", version = "MC1710", useMetadata = false, dependencies = " required-after:IC2;" + + " required-after:structurelib;" + " after:dreamcraft;" + " after:Forestry;" + " after:PFAAGeologica;" + diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 6c43799638..d108236a39 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -8,6 +8,10 @@ import appeng.me.helpers.AENetworkProxy; import appeng.me.helpers.IGridProxyable; import appeng.tile.TileEvent; import appeng.tile.events.TileEventType; +import com.gtnewhorizon.structurelib.alignment.IAlignment; +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; +import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing; import cpw.mods.fml.common.Optional; import gregtech.GT_Mod; import gregtech.api.GregTech_API; @@ -25,11 +29,7 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachin import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; import gregtech.api.net.GT_Packet_TileEntity; import gregtech.api.objects.GT_ItemStack; -import gregtech.api.util.GT_CoverBehavior; -import gregtech.api.util.GT_Log; -import gregtech.api.util.GT_ModHandler; -import gregtech.api.util.GT_OreDictUnificator; -import gregtech.api.util.GT_Utility; +import gregtech.api.util.*; import gregtech.common.GT_Client; import gregtech.common.GT_Pollution; import ic2.api.Direction; @@ -73,7 +73,7 @@ import static gregtech.api.objects.XSTR.XSTR_INSTANCE; @Optional.InterfaceList(value = { @Optional.Interface(iface = "appeng.api.networking.security.IActionHost", modid = "appliedenergistics2", striprefs = true), @Optional.Interface(iface = "appeng.me.helpers.IGridProxyable", modid = "appliedenergistics2", striprefs = true)}) -public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileEntity, IActionHost, IGridProxyable { +public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileEntity, IActionHost, IGridProxyable, IAlignmentProvider { private final GT_CoverBehavior[] mCoverBehaviors = new GT_CoverBehavior[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior}; protected MetaTileEntity mMetaTileEntity; protected long mStoredEnergy = 0, mStoredSteam = 0; @@ -2368,4 +2368,27 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE public void setShutdownStatus(boolean newStatus) { mWasShutdown = newStatus; } + + @Override + public IAlignment getAlignment() { + return getMetaTileEntity() instanceof IAlignmentProvider ? ((IAlignmentProvider) getMetaTileEntity()).getAlignment() : new BasicAlignment(); + } + + private class BasicAlignment implements IAlignment { + + @Override + public ExtendedFacing getExtendedFacing() { + return ExtendedFacing.of(ForgeDirection.getOrientation(getFrontFacing())); + } + + @Override + public void setExtendedFacing(ExtendedFacing alignment) { + setFrontFacing((byte) Math.max(alignment.getDirection().ordinal(), 5)); + } + + @Override + public IAlignmentLimits getAlignmentLimits() { + return (direction, rotation, flip) -> rotation.isNotRotated() && flip.isNotFlipped(); + } + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java new file mode 100644 index 0000000000..7d06378ce1 --- /dev/null +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java @@ -0,0 +1,122 @@ +package gregtech.api.metatileentity.implementations; + +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.alignment.IAlignment; +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; +import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing; +import com.gtnewhorizon.structurelib.alignment.enumerable.Flip; +import com.gtnewhorizon.structurelib.alignment.enumerable.Rotation; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import cpw.mods.fml.common.network.NetworkRegistry; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Enhanced multiblock base class, featuring following improvement over {@link GT_MetaTileEntity_MultiBlockBase} + *

+ * 1. TecTech style declarative structure check utilizing StructureLib. + * 2. Arbitrarily rotating the whole structure, if allowed to. + * + * @param type of this + */ +public abstract class GT_MetaTileEntity_EnhancedMultiBlockBase> extends GT_MetaTileEntity_MultiBlockBase implements IAlignment { + private ExtendedFacing mExtendedFacing; + private final IAlignmentLimits mLimits; + + protected GT_MetaTileEntity_EnhancedMultiBlockBase(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + mLimits = getInitialAlignmentLimits(); + } + + protected GT_MetaTileEntity_EnhancedMultiBlockBase(String aName) { + super(aName); + mLimits = getInitialAlignmentLimits(); + } + + @Override + public ExtendedFacing getExtendedFacing() { + return mExtendedFacing; + } + + @Override + public void setExtendedFacing(ExtendedFacing newExtendedFacing) { + if (mExtendedFacing != newExtendedFacing) { + stopMachine(); + mExtendedFacing = newExtendedFacing; + IGregTechTileEntity base = getBaseMetaTileEntity(); + mMachine = false; + mUpdate = 100; + if (getBaseMetaTileEntity().isServerSide()) { + StructureLibAPI.sendAlignment((IAlignmentProvider) base, + new NetworkRegistry.TargetPoint(base.getWorld().provider.dimensionId, + base.getXCoord(), base.getYCoord(), base.getZCoord(), 512)); + } else { + base.issueTextureUpdate(); + } + } + } + + @Override + public final boolean isFacingValid(byte aFacing) { + return canSetToDirectionAny(ForgeDirection.getOrientation(aFacing)); + } + + @Override + public void onFacingChange() { + toolSetDirection(ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing())); + } + + @Override + public IAlignmentLimits getAlignmentLimits() { + return mLimits; + } + + public abstract IStructureDefinition getStructureDefinition(); + + protected IAlignmentLimits getInitialAlignmentLimits() { + return UNLIMITED; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setByte("mRotation", (byte) mExtendedFacing.getRotation().getIndex()); + aNBT.setByte("mFlip", (byte) mExtendedFacing.getFlip().getIndex()); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mExtendedFacing = ExtendedFacing.of(ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()), + Rotation.byIndex(aNBT.getByte("mRotation")), + Flip.byIndex(aNBT.getByte("mFlip"))); + } + + @Override + public abstract GT_MetaTileEntity_EnhancedMultiBlockBase newMetaEntity(IGregTechTileEntity aTileEntity); + + @SuppressWarnings("unchecked") + private IStructureDefinition> getCastedStructureDefinition() { + return (IStructureDefinition>) getStructureDefinition(); + } + + protected final boolean checkPiece(String piece, int horizontalOffset, int verticalOffset, int depthOffset) { + IGregTechTileEntity tTile = getBaseMetaTileEntity(); + return getCastedStructureDefinition().check(this, piece, tTile.getWorld(), getExtendedFacing(), tTile.getXCoord(), tTile.getYCoord(), tTile.getZCoord(), horizontalOffset, verticalOffset, depthOffset, !mMachine); + } + + protected final boolean buildPiece(String piece, ItemStack trigger, boolean hintOnly, int horizontalOffset, int verticalOffset, int depthOffset) { + IGregTechTileEntity tTile = getBaseMetaTileEntity(); + return getCastedStructureDefinition().buildOrHints(this, trigger, piece, tTile.getWorld(), getExtendedFacing(), tTile.getXCoord(), tTile.getYCoord(), tTile.getZCoord(), horizontalOffset, verticalOffset, depthOffset, hintOnly); + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + if (aBaseMetaTileEntity.isClientSide()) + StructureLibAPI.queryAlignment((IAlignmentProvider) aBaseMetaTileEntity); + } +} diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index 0de4dfecbb..3b1a963c9e 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -26,6 +26,7 @@ import net.minecraftforge.fluids.FluidStack; import org.lwjgl.input.Keyboard; import java.util.ArrayList; +import java.util.List; import static gregtech.api.enums.GT_Values.V; import static gregtech.api.enums.GT_Values.VN; @@ -676,8 +677,8 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { return false; } - private boolean dumpFluid(FluidStack copiedFluidStack, boolean restrictiveHatchesOnly){ - for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) { + protected static boolean dumpFluid(List aOutputHatches, FluidStack copiedFluidStack, boolean restrictiveHatchesOnly){ + for (GT_MetaTileEntity_Hatch_Output tHatch : aOutputHatches) { if (!isValidMetaTileEntity(tHatch) || (restrictiveHatchesOnly && tHatch.mMode == 0)) { continue; } @@ -709,8 +710,8 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { public boolean addOutput(FluidStack aLiquid) { if (aLiquid == null) return false; FluidStack copiedFluidStack = aLiquid.copy(); - if (!dumpFluid(copiedFluidStack, true)){ - dumpFluid(copiedFluidStack, false); + if (!dumpFluid(mOutputHatches, copiedFluidStack, true)){ + dumpFluid(mOutputHatches, copiedFluidStack, false); } return false; } diff --git a/src/main/java/gregtech/api/util/GT_StructureUtility.java b/src/main/java/gregtech/api/util/GT_StructureUtility.java new file mode 100644 index 0000000000..c8d845ec19 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java @@ -0,0 +1,71 @@ +package gregtech.api.util; + +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.structure.IStructureElement; +import com.gtnewhorizon.structurelib.structure.IStructureElementNoPlacement; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class GT_StructureUtility { + private GT_StructureUtility() { + throw new AssertionError("Not instantiable"); + } + + public static IStructureElementNoPlacement ofHatchAdder(IGT_HatchAdder IGT_HatchAdder, int textureIndex, int dots) { + return ofHatchAdder(IGT_HatchAdder, textureIndex, StructureLibAPI.getBlockHint(), dots - 1); + } + + public static IStructureElementNoPlacement ofHatchAdder(IGT_HatchAdder IGT_HatchAdder, int textureIndex, Block hintBlock, int hintMeta) { + if (IGT_HatchAdder == null || hintBlock == null) { + throw new IllegalArgumentException(); + } + return new IStructureElementNoPlacement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + return tileEntity instanceof IGregTechTileEntity && IGT_HatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) textureIndex); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta); + return true; + } + }; + } + + public static IStructureElement ofHatchAdderOptional(IGT_HatchAdder IGT_HatchAdder, int textureIndex, int dots, Block placeCasing, int placeCasingMeta) { + return ofHatchAdderOptional(IGT_HatchAdder, textureIndex, StructureLibAPI.getBlockHint(), dots - 1, placeCasing, placeCasingMeta); + } + + public static IStructureElement ofHatchAdderOptional(IGT_HatchAdder IGT_HatchAdder, int textureIndex, Block hintBlock, int hintMeta, Block placeCasing, int placeCasingMeta) { + if (IGT_HatchAdder == null || hintBlock == null) { + throw new IllegalArgumentException(); + } + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + Block worldBlock = world.getBlock(x, y, z); + return (tileEntity instanceof IGregTechTileEntity && + IGT_HatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) textureIndex)) || + (worldBlock == placeCasing && worldBlock.getDamageValue(world, x, y, z) == placeCasingMeta); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + world.setBlock(x, y, z, placeCasing, placeCasingMeta, 2); + return true; + } + }; + } +} diff --git a/src/main/java/gregtech/api/util/IGT_HatchAdder.java b/src/main/java/gregtech/api/util/IGT_HatchAdder.java new file mode 100644 index 0000000000..be0194fc65 --- /dev/null +++ b/src/main/java/gregtech/api/util/IGT_HatchAdder.java @@ -0,0 +1,14 @@ +package gregtech.api.util; + + +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; + +public interface IGT_HatchAdder { + /** + * Callback to add hatch, needs to check if hatch is valid (and add it) + * @param iGregTechTileEntity hatch + * @param aShort requested texture index, or null if not... + * @return managed to add hatch (structure still valid) + */ + boolean apply(T t,IGregTechTileEntity iGregTechTileEntity, Short aShort); +} diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java index 1ac4df6d73..84203ef849 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java @@ -1,16 +1,16 @@ package gregtech.common.tileentities.machines.multi; -import gregtech.api.GregTech_API; +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.interfaces.IHeatingCoil; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; -public abstract class GT_MetaTileEntity_AbstractMultiFurnace extends GT_MetaTileEntity_MultiBlockBase { +public abstract class GT_MetaTileEntity_AbstractMultiFurnace> extends GT_MetaTileEntity_EnhancedMultiBlockBase { - private static final int CASING_INDEX = 11; + protected HeatingCoilLevel mCoilLevel; protected GT_MetaTileEntity_AbstractMultiFurnace(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); @@ -25,55 +25,21 @@ public abstract class GT_MetaTileEntity_AbstractMultiFurnace extends GT_MetaTile return true; } - @Override - public boolean isFacingValid(byte aFacing) { - return aFacing > 1; - } - - protected HeatingCoilLevel getInitialHeatLevel(IGregTechTileEntity aBaseMetaTileEntity, int xDir, int zDir) { - Block coil = aBaseMetaTileEntity.getBlockOffset(xDir + 1, 1, zDir); - if (!(coil instanceof IHeatingCoil)) - return null; - IHeatingCoil heatingCoil = (IHeatingCoil) coil; - byte tUsedMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + 1, 1, zDir); - return heatingCoil.getCoilHeat(tUsedMeta); - } - - protected boolean checkStructure(HeatingCoilLevel heatingCap, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity){ - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 2; j++) { - if (!checkTopLayer(i, j, xDir, zDir, aBaseMetaTileEntity)) - return false; - - if (!checkBottomLayer(i, j, xDir, zDir, aBaseMetaTileEntity)) - return false; - - if (!checkCoils(heatingCap, i, j, xDir, zDir, aBaseMetaTileEntity)) - return false; - } + protected final boolean addCoil(Block aBlock, int aMeta) { + if (aBlock instanceof IHeatingCoil) { + if (mCoilLevel != null) + return mCoilLevel == ((IHeatingCoil) aBlock).getCoilHeat(aMeta); + mCoilLevel = ((IHeatingCoil) aBlock).getCoilHeat(aMeta); + return true; } - return true; + return false; } - protected abstract boolean checkTopLayer(int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity); - protected abstract boolean checkCoils(HeatingCoilLevel heatingCap, int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity); - - protected boolean checkBottomLayer(int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity){ - if ((xDir + i == 0) && (zDir + j == 0)) - return true; - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, 0, zDir + j); - if (addMaintenanceToMachineList(tTileEntity, CASING_INDEX)) - return true; - if (addInputToMachineList(tTileEntity, CASING_INDEX)) - return true; - if (addOutputToMachineList(tTileEntity, CASING_INDEX)) - return true; - if (addEnergyInputToMachineList(tTileEntity, CASING_INDEX)) - return true; - - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 0, zDir + j) != GregTech_API.sBlockCasings1) - return false; - return aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 0, zDir + j) == CASING_INDEX; + protected boolean addBottomHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + return addMaintenanceToMachineList(aTileEntity, aBaseCasingIndex) || + addInputToMachineList(aTileEntity, aBaseCasingIndex) || + addOutputToMachineList(aTileEntity, aBaseCasingIndex) || + addEnergyInputToMachineList(aTileEntity, aBaseCasingIndex); } @Override @@ -95,4 +61,10 @@ public abstract class GT_MetaTileEntity_AbstractMultiFurnace extends GT_MetaTile public boolean explodesOnComponentBreak(ItemStack aStack) { return false; } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // even though flipping doesn't really change the overall structure, but maybe someone want it somehow + return (direction, rotation, flip) -> direction.offsetY == 0 && rotation.isNotRotated(); + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java index 5e99491c2e..733710e539 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java @@ -1,22 +1,22 @@ package gregtech.common.tileentities.machines.multi; +import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; import gregtech.api.GregTech_API; -import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.enums.Materials; import gregtech.api.gui.GT_GUIContainer_MultiMachine; -import gregtech.api.interfaces.IHeatingCoil; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; import gregtech.api.render.TextureFactory; -import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import net.minecraft.block.Block; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; @@ -25,21 +25,36 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import org.lwjgl.input.Keyboard; +import java.util.ArrayList; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAdder; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; import static gregtech.api.enums.GT_Values.V; import static gregtech.api.enums.GT_Values.VN; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ACTIVE; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ACTIVE_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.casingTexturePages; +import static gregtech.api.enums.Textures.BlockIcons.*; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; -public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_AbstractMultiFurnace { +public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_AbstractMultiFurnace implements IConstructable { private int mHeatingCapacity = 0; - private int controllerY; + private final ArrayList mPollutionOutputHatches = new ArrayList<>(); private final FluidStack[] pollutionFluidStacks = {Materials.CarbonDioxide.getGas(1000), Materials.CarbonMonoxide.getGas(1000), Materials.SulfurDioxide.getGas(1000)}; private static final int CASING_INDEX = 11; + private static final String STRUCTURE_PIECE_MAIN = "main"; + private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ + {"ttt", "tmt", "ttt"}, + {"CCC", "C-C", "CCC",}, + {"CCC", "C-C", "CCC",}, + {"b~b", "bbb", "bbb"} + })) + .addElement('t', ofHatchAdderOptional(GT_MetaTileEntity_ElectricBlastFurnace::addOutputHatchToTopList, CASING_INDEX, 1, GregTech_API.sBlockCasings1, CASING_INDEX)) + .addElement('m', ofHatchAdder(GT_MetaTileEntity_ElectricBlastFurnace::addMufflerToMachineList, CASING_INDEX, 2)) + .addElement('C', ofBlockAdder(GT_MetaTileEntity_ElectricBlastFurnace::addCoil, GregTech_API.sBlockCasings5, 0)) + .addElement('b', ofHatchAdderOptional(GT_MetaTileEntity_ElectricBlastFurnace::addBottomHatch, CASING_INDEX, 3, GregTech_API.sBlockCasings1, CASING_INDEX)) + .build(); public GT_MetaTileEntity_ElectricBlastFurnace(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); @@ -50,7 +65,7 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab } @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + public GT_MetaTileEntity_ElectricBlastFurnace newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_ElectricBlastFurnace(this.mName); } @@ -119,8 +134,8 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab } @Override - public boolean isFacingValid(byte aFacing) { - return aFacing > 1; + public IStructureDefinition getStructureDefinition() { + return STRUCTURE_DEFINITION; } @Override @@ -225,68 +240,33 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab return timesOverclocked; } - private boolean checkMachineFunction(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - controllerY = aBaseMetaTileEntity.getYCoord(); - int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; - - this.mHeatingCapacity = 0; - - replaceDeprecatedCoils(aBaseMetaTileEntity); - HeatingCoilLevel heatingCap = getInitialHeatLevel(aBaseMetaTileEntity, xDir, zDir); - if (heatingCap == null) - return false; - - if (!checkStructure(heatingCap, xDir, zDir, aBaseMetaTileEntity)) - return false; - - this.mHeatingCapacity = (int) heatingCap.getHeat(); - this.mHeatingCapacity += 100 * (GT_Utility.getTier(getMaxInputVoltage()) - 2); - return true; - } - - @Override - protected boolean checkTopLayer(int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity) { - if ((i == 0) && (j == 0)) { - return addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir, 3, zDir), CASING_INDEX); + public boolean addOutputHatchToTopList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) return false; + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) return false; + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + return mPollutionOutputHatches.add((GT_MetaTileEntity_Hatch_Output) aMetaTileEntity); } - if (addOutputToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, 3, zDir + j), CASING_INDEX)) - return true; - - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 3, zDir + j) != GregTech_API.sBlockCasings1) - return false; - - return aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 3, zDir + j) == CASING_INDEX; + return false; } @Override - protected boolean checkCoils(HeatingCoilLevel heatingCap, int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity) { - if ((i == 0) && (j == 0)) { - if (!aBaseMetaTileEntity.getAirOffset(xDir, 1, zDir)) - return false; + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + this.mHeatingCapacity = 0; - return aBaseMetaTileEntity.getAirOffset(xDir, 2, zDir); - } + replaceDeprecatedCoils(aBaseMetaTileEntity); - Block blockLow = aBaseMetaTileEntity.getBlockOffset(xDir + i, 1, zDir + j); - if (!(blockLow instanceof IHeatingCoil)) - return false; + mCoilLevel = null; - Block blockHi = aBaseMetaTileEntity.getBlockOffset(xDir + i, 2, zDir + j); - if (!(blockHi instanceof IHeatingCoil)) + if (!checkPiece(STRUCTURE_PIECE_MAIN, 1, 3, 0)) return false; - byte metaLow = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 1, zDir + j); - HeatingCoilLevel coilHeatLow = ((IHeatingCoil) blockLow).getCoilHeat(metaLow); - byte metaHi = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 2, zDir + j); - HeatingCoilLevel coilHeatHi = ((IHeatingCoil) blockHi).getCoilHeat(metaHi); - - return heatingCap == coilHeatLow && heatingCap == coilHeatHi; - } + if (mCoilLevel == null) + return false; - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - return this.checkMachineFunction(aBaseMetaTileEntity, aStack); + this.mHeatingCapacity = (int) mCoilLevel.getHeat() + 100 * (GT_Utility.getTier(getMaxInputVoltage()) - 2); + return true; } private void replaceDeprecatedCoils(IGregTechTileEntity aBaseMetaTileEntity) { @@ -326,7 +306,6 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab public boolean addOutput(FluidStack aLiquid) { if (aLiquid == null) return false; - int targetHeight; FluidStack tLiquid = aLiquid.copy(); boolean isOutputPollution = false; for (FluidStack pollutionFluidStack : pollutionFluidStacks) { @@ -336,8 +315,9 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab isOutputPollution = true; break; } + ArrayList tOutputHatches; if (isOutputPollution) { - targetHeight = this.controllerY + 3; + tOutputHatches = this.mPollutionOutputHatches; int pollutionReduction = 0; for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { if (!isValidMetaTileEntity(tHatch)) @@ -347,23 +327,10 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab } tLiquid.amount = tLiquid.amount * (pollutionReduction + 5) / 100; } else { - targetHeight = this.controllerY; + tOutputHatches = this.mOutputHatches; } - for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) { - if (isValidMetaTileEntity(tHatch) && GT_ModHandler.isSteam(aLiquid) ? !tHatch.outputsSteam() : !tHatch.outputsLiquids()) - continue; - - if (tHatch.getBaseMetaTileEntity().getYCoord() != targetHeight) - continue; - - int tAmount = tHatch.fill(tLiquid, false); - if (tAmount >= tLiquid.amount) { - return tHatch.fill(tLiquid, true) >= tLiquid.amount; - } else if (tAmount > 0) { - tLiquid.amount = tLiquid.amount - tHatch.fill(tLiquid, true); - } - } - return false; + return dumpFluid(tOutputHatches, tLiquid, true) || + dumpFluid(tOutputHatches, tLiquid, false); } @Override @@ -401,4 +368,15 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab StatCollector.translateToLocal("GT5U.multiblock.pollution") + ": " + EnumChatFormatting.GREEN + mPollutionReduction + EnumChatFormatting.RESET + " %" }; } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 1,3,0); + } + + @Override + public String[] getStructureDescription(ItemStack stackSize) { + // TODO implement me + return new String[0]; + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java index 3bf7dc4cfb..14dfe6f237 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java @@ -1,11 +1,10 @@ package gregtech.common.tileentities.machines.multi; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; import gregtech.api.GregTech_API; -import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.gui.GT_GUIContainer_MultiMachine; -import gregtech.api.interfaces.IHeatingCoil; import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler; @@ -14,7 +13,6 @@ import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import net.minecraft.block.Block; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; @@ -24,18 +22,30 @@ import org.lwjgl.input.Keyboard; import java.util.ArrayList; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAdder; import static gregtech.api.enums.GT_Values.VN; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.casingTexturePages; +import static gregtech.api.enums.Textures.BlockIcons.*; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; -public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMultiFurnace { +public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMultiFurnace { private int mLevel = 0; private int mCostDiscount = 1; private static final int CASING_INDEX = 11; + private static final String STRUCTURE_PIECE_MAIN = "main"; + private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder() + .addShape(STRUCTURE_PIECE_MAIN, new String[][]{ + {"ccc", "cmc", "ccc"}, + {"CCC", "C-C", "CCC",}, + {"b~b", "bbb", "bbb"} + }) + .addElement('c', ofBlock(GregTech_API.sBlockCasings1, CASING_INDEX)) + .addElement('m', ofHatchAdder(GT_MetaTileEntity_MultiFurnace::addMufflerToMachineList, CASING_INDEX, 2)) + .addElement('C', ofBlockAdder(GT_MetaTileEntity_MultiFurnace::addCoil, GregTech_API.sBlockCasings5, 0)) + .addElement('b', ofHatchAdderOptional(GT_MetaTileEntity_MultiFurnace::addBottomHatch, CASING_INDEX, 3, GregTech_API.sBlockCasings1, CASING_INDEX)) + .build(); public GT_MetaTileEntity_MultiFurnace(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); @@ -46,7 +56,7 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu } @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + public GT_MetaTileEntity_MultiFurnace newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_MultiFurnace(this.mName); } @@ -149,55 +159,29 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu return true; } - private boolean checkMachineFunction(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; + @Override + public IStructureDefinition getStructureDefinition() { + return STRUCTURE_DEFINITION; + } + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack){ this.mLevel = 0; this.mCostDiscount = 1; replaceDeprecatedCoils(aBaseMetaTileEntity); - HeatingCoilLevel heatingCap = getInitialHeatLevel(aBaseMetaTileEntity, xDir, zDir); - if (heatingCap == null) - return false; - - if (!checkStructure(heatingCap, xDir, zDir, aBaseMetaTileEntity)) - return false; - - this.mLevel = heatingCap.getLevel(); - this.mCostDiscount = heatingCap.getCostDiscount(); - return true; - } - @Override - protected boolean checkCoils(HeatingCoilLevel heatingCap, int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity) { - if ((i == 0) && (j == 0)) - return aBaseMetaTileEntity.getAirOffset(xDir, 1, zDir); + mCoilLevel = null; - Block coilM = aBaseMetaTileEntity.getBlockOffset(xDir + i, 1, zDir + j); - if (!(coilM instanceof IHeatingCoil)) + if (!checkPiece(STRUCTURE_PIECE_MAIN, 1, 3, 0)) return false; - byte usedMetaM = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 1, zDir + j); - - IHeatingCoil heatingCoilM = (IHeatingCoil) coilM; - HeatingCoilLevel heatingLevelM = heatingCoilM.getCoilHeat(usedMetaM); - return heatingLevelM == heatingCap; - } - - @Override - protected boolean checkTopLayer(int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity) { - if ((i == 0) && (j == 0)) { - return addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir, 2, zDir), CASING_INDEX); - } - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 2, zDir + j) != GregTech_API.sBlockCasings1) + if (mCoilLevel == null) return false; - return aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 2, zDir + j) == CASING_INDEX; - } - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack){ - return this.checkMachineFunction(aBaseMetaTileEntity,aStack); + this.mLevel = mCoilLevel.getLevel(); + this.mCostDiscount = mCoilLevel.getCostDiscount(); + return true; } private void replaceDeprecatedCoils(IGregTechTileEntity aBaseMetaTileEntity) { diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 1432a19054..0ec17827de 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -16,7 +16,8 @@ "parent": "", "screenshots": [], "dependencies": [ - "Industrialcraft" + "Industrialcraft", + "structurelib" ] } ] -- cgit From cb876c46e9f185b73556c1c8ed7ca2751cac2cdc Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Mon, 31 May 2021 01:09:30 +0800 Subject: Implement IConstructable for demo multis --- .../api/metatileentity/BaseMetaTileEntity.java | 2 +- .../GT_MetaTileEntity_EnhancedMultiBlockBase.java | 35 +++++++++++++++++++++- src/main/java/gregtech/api/util/GT_Utility.java | 15 +++++++++- .../GT_MetaTileEntity_ElectricBlastFurnace.java | 17 ++--------- .../multi/GT_MetaTileEntity_MultiFurnace.java | 17 ++++++----- 5 files changed, 62 insertions(+), 24 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index d108236a39..6eb06d8fae 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -2383,7 +2383,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public void setExtendedFacing(ExtendedFacing alignment) { - setFrontFacing((byte) Math.max(alignment.getDirection().ordinal(), 5)); + setFrontFacing((byte) Math.min(alignment.getDirection().ordinal(), ForgeDirection.UNKNOWN.ordinal() - 1)); } @Override diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java index 7d06378ce1..c3d41664b7 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java @@ -4,15 +4,21 @@ import com.gtnewhorizon.structurelib.StructureLibAPI; import com.gtnewhorizon.structurelib.alignment.IAlignment; import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; +import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable; import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing; import com.gtnewhorizon.structurelib.alignment.enumerable.Flip; import com.gtnewhorizon.structurelib.alignment.enumerable.Rotation; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import cpw.mods.fml.common.network.NetworkRegistry; +import gregtech.api.GregTech_API; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; +import org.lwjgl.input.Keyboard; + +import java.util.concurrent.atomic.AtomicReferenceArray; /** * Enhanced multiblock base class, featuring following improvement over {@link GT_MetaTileEntity_MultiBlockBase} @@ -22,7 +28,8 @@ import net.minecraftforge.common.util.ForgeDirection; * * @param type of this */ -public abstract class GT_MetaTileEntity_EnhancedMultiBlockBase> extends GT_MetaTileEntity_MultiBlockBase implements IAlignment { +public abstract class GT_MetaTileEntity_EnhancedMultiBlockBase> extends GT_MetaTileEntity_MultiBlockBase implements IAlignment, IConstructable { + private static final AtomicReferenceArray tooltips = new AtomicReferenceArray<>(GregTech_API.METATILEENTITIES.length); private ExtendedFacing mExtendedFacing; private final IAlignmentLimits mLimits; @@ -76,6 +83,32 @@ public abstract class GT_MetaTileEntity_EnhancedMultiBlockBase getStructureDefinition(); + protected abstract GT_Multiblock_Tooltip_Builder createTooltip(); + + @Override + public String[] getDescription() { + if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { + return getTooltip().getStructureInformation(); + } else { + return getTooltip().getInformation(); + } + } + + protected GT_Multiblock_Tooltip_Builder getTooltip() { + int tId = getBaseMetaTileEntity().getMetaTileID(); + GT_Multiblock_Tooltip_Builder tooltip = tooltips.get(tId); + if (tooltip == null) { + tooltip = createTooltip(); + tooltips.set(tId, tooltip); + } + return tooltip; + } + + @Override + public String[] getStructureDescription(ItemStack stackSize) { + return getTooltip().getStructureInformation(); + } + protected IAlignmentLimits getInitialAlignmentLimits() { return UNLIMITED; } diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 28faeae7e3..c7cee8c9c2 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -3,6 +3,8 @@ package gregtech.api.util; import cofh.api.transport.IItemDuct; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; +import com.gtnewhorizon.structurelib.alignment.IAlignment; +import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; import com.mojang.authlib.GameProfile; import cpw.mods.fml.common.FMLCommonHandler; import gregtech.api.GregTech_API; @@ -1939,7 +1941,7 @@ public class GT_Utility { tList.add("----- X: " +EnumChatFormatting.AQUA+ aX +EnumChatFormatting.RESET+ " Y: " +EnumChatFormatting.AQUA+ aY +EnumChatFormatting.RESET+ " Z: " +EnumChatFormatting.AQUA+ aZ +EnumChatFormatting.RESET+ " D: " +EnumChatFormatting.AQUA+ aWorld.provider.dimensionId +EnumChatFormatting.RESET+ " -----"); try { - if (tTileEntity != null && tTileEntity instanceof IInventory) + if (tTileEntity instanceof IInventory) tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ ((IInventory) tTileEntity).getInventoryName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET); else tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ tBlock.getUnlocalizedName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET); @@ -1978,6 +1980,17 @@ public class GT_Utility { } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); } + try { + if (tTileEntity instanceof IAlignmentProvider) { + IAlignment tAlignment = ((IAlignmentProvider) tTileEntity).getAlignment(); + if (tAlignment != null) { + rEUAmount += 100; + tList.add(trans("219", "Extended Facing: ") + EnumChatFormatting.GREEN + tAlignment.getExtendedFacing() + EnumChatFormatting.RESET); + } + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } try { if (tTileEntity instanceof ic2.api.tile.IWrenchable) { rEUAmount += 100; diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java index 733710e539..149c7a4172 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java @@ -23,7 +23,6 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; -import org.lwjgl.input.Keyboard; import java.util.ArrayList; @@ -70,8 +69,8 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab } @Override - public String[] getDescription() { - final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); tt.addMachineType("Blast Furnace") .addInfo("Controller block for the Electric Blast Furnace") .addInfo("You can use some fluids to reduce recipe time. Place the circuit in the Input Bus") @@ -95,11 +94,7 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab .addStructureInfo("Recovery amount scales with Muffler Hatch tier") .addOutputHatch("Platline fluids, Any bottom layer casing") .toolTipFinisher("Gregtech"); - if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { - return tt.getStructureInformation(); - } else { - return tt.getInformation(); - } + return tt; } @Override @@ -373,10 +368,4 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab public void construct(ItemStack stackSize, boolean hintsOnly) { buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 1,3,0); } - - @Override - public String[] getStructureDescription(ItemStack stackSize) { - // TODO implement me - return new String[0]; - } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java index 14dfe6f237..aae7497f04 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java @@ -1,5 +1,6 @@ package gregtech.common.tileentities.machines.multi; +import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.StructureDefinition; import gregtech.api.GregTech_API; @@ -29,7 +30,7 @@ import static gregtech.api.enums.Textures.BlockIcons.*; import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; -public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMultiFurnace { +public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMultiFurnace implements IConstructable { private int mLevel = 0; private int mCostDiscount = 1; @@ -61,8 +62,8 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu } @Override - public String[] getDescription() { - final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); tt.addMachineType("Furnace") .addInfo("Controller Block for the Multi Smelter") .addInfo("Smelts up to 8-128 items at once") @@ -79,9 +80,7 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu .addInputBus("Any bottom casing") .addOutputBus("Any bottom casing") .toolTipFinisher("Gregtech"); - if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) - return tt.getInformation(); - return tt.getStructureInformation(); + return tt; } @Override @@ -173,7 +172,7 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu mCoilLevel = null; - if (!checkPiece(STRUCTURE_PIECE_MAIN, 1, 3, 0)) + if (!checkPiece(STRUCTURE_PIECE_MAIN, 1, 2, 0)) return false; if (mCoilLevel == null) @@ -238,4 +237,8 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu }; } + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 1, 2, 0); + } } -- cgit From 86f69a4300e0bdb5c9921f37c84bb446e464ec78 Mon Sep 17 00:00:00 2001 From: Léa Gris Date: Mon, 31 May 2021 10:13:56 +0200 Subject: feat(texture API): integrate ExtendedFacing rotation Add ExtendedFacing rotation to the texture API. Rotatable ExtendedFacing textures can be created with: ```java TextureFactory.builder().addIcon(IICon).extFacing().build(); ``` Improve and unify internal implementation of standard oriented and glow textures. --- src/main/java/gregtech/GT_Mod.java | 3 +- .../gregtech/api/interfaces/ITextureBuilder.java | 8 + .../java/gregtech/api/util/LightingHelper.java | 1 + .../common/render/GT_RenderedGlowTexture.java | 213 ------------ .../gregtech/common/render/GT_RenderedTexture.java | 383 +++++++++++++++------ .../common/render/GT_StdRenderedTexture.java | 36 -- .../gregtech/common/render/GT_TextureBuilder.java | 11 +- 7 files changed, 290 insertions(+), 365 deletions(-) delete mode 100644 src/main/java/gregtech/common/render/GT_RenderedGlowTexture.java delete mode 100644 src/main/java/gregtech/common/render/GT_StdRenderedTexture.java (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index d9a8d72ecd..278908b9a0 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -1,6 +1,7 @@ package gregtech; import com.google.common.base.Stopwatch; +import com.gtnewhorizon.structurelib.StructureLib; import cpw.mods.fml.common.*; import cpw.mods.fml.common.event.*; import cpw.mods.fml.common.registry.EntityRegistry; @@ -74,7 +75,7 @@ import static gregtech.api.enums.GT_Values.MOD_ID_FR; @SuppressWarnings("ALL") @Mod(modid = "gregtech", name = "GregTech", version = "MC1710", useMetadata = false, dependencies = " required-after:IC2;" + - " required-after:structurelib;" + + " required-after:" + StructureLib.MOD_ID + ";" + " after:dreamcraft;" + " after:Forestry;" + " after:PFAAGeologica;" + diff --git a/src/main/java/gregtech/api/interfaces/ITextureBuilder.java b/src/main/java/gregtech/api/interfaces/ITextureBuilder.java index 8a4d715ccb..d72b538243 100644 --- a/src/main/java/gregtech/api/interfaces/ITextureBuilder.java +++ b/src/main/java/gregtech/api/interfaces/ITextureBuilder.java @@ -1,5 +1,6 @@ package gregtech.api.interfaces; +import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing; import gregtech.api.render.TextureFactory; import net.minecraft.block.Block; import net.minecraftforge.common.util.ForgeDirection; @@ -63,6 +64,13 @@ public interface ITextureBuilder { */ ITextureBuilder stdOrient(); + /** + * Texture will orientate from block's {@link ExtendedFacing} + * + * @return {@link ITextureBuilder} for chaining + */ + ITextureBuilder extFacing(); + /** * Texture always render with full brightness to glow in the dark * diff --git a/src/main/java/gregtech/api/util/LightingHelper.java b/src/main/java/gregtech/api/util/LightingHelper.java index 598253b7d7..f131ef74a0 100644 --- a/src/main/java/gregtech/api/util/LightingHelper.java +++ b/src/main/java/gregtech/api/util/LightingHelper.java @@ -255,6 +255,7 @@ public class LightingHelper { } else { + if (hasBrightnessOverride) tessellator.setBrightness(brightnessOverride); tessellator.setColorOpaque_F(rgb[0] * lightness, rgb[1] * lightness, rgb[2] * lightness); } diff --git a/src/main/java/gregtech/common/render/GT_RenderedGlowTexture.java b/src/main/java/gregtech/common/render/GT_RenderedGlowTexture.java deleted file mode 100644 index 899e4d7c5d..0000000000 --- a/src/main/java/gregtech/common/render/GT_RenderedGlowTexture.java +++ /dev/null @@ -1,213 +0,0 @@ -package gregtech.common.render; - -import gregtech.GT_Mod; -import gregtech.api.enums.Textures.BlockIcons; -import gregtech.api.interfaces.IColorModulationContainer; -import gregtech.api.interfaces.IIconContainer; -import gregtech.api.interfaces.ITexture; -import net.minecraft.block.Block; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.util.IIcon; - -import static gregtech.api.util.LightingHelper.MAX_BRIGHTNESS; - -/** - * This {@link ITexture} implementation renders texture with max brightness to glow in the dark. - */ - -class GT_RenderedGlowTexture implements ITexture, IColorModulationContainer { - protected final IIconContainer mIconContainer; - private final short[] mRGBa; - - GT_RenderedGlowTexture(IIconContainer aIcon, short[] aRGBa, boolean allowAlpha) { - if (aRGBa.length != 4) throw new IllegalArgumentException("RGBa doesn't have 4 Values @ GT_RenderedTexture"); - mIconContainer = GT_Mod.gregtechproxy.mRenderGlowTextures ? aIcon : BlockIcons.VOID; - mRGBa = aRGBa; - } - - @Override - public short[] getRGBA() { - return mRGBa; - } - - @Override - public void renderXNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API - if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; - final boolean enableAO = aRenderer.enableAO; - aRenderer.enableAO = false; - // TODO: Uncomment this once all addons have migrated to the new Texture API - //startDrawingQuads(aRenderer, -1.0f, 0.0f, 0.0f); - Tessellator.instance.setBrightness(MAX_BRIGHTNESS); - Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]); - aRenderer.renderFaceXNeg(aBlock, aX, aY, aZ, mIconContainer.getIcon()); - if (mIconContainer.getOverlayIcon() != null) { - Tessellator.instance.setColorOpaque(255, 255, 255); - aRenderer.renderFaceXNeg(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); - } - // TODO: Uncomment this once all addons have migrated to the new Texture API - //draw(aRenderer); - aRenderer.enableAO = enableAO; - } - - @Override - public void renderXPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API - if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; - aRenderer.field_152631_f = true; - final boolean enableAO = aRenderer.enableAO; - aRenderer.enableAO = false; - // TODO: Uncomment this once all addons have migrated to the new Texture API - //startDrawingQuads(aRenderer, 1.0f, 0.0f, 0.0f); - Tessellator.instance.setBrightness(MAX_BRIGHTNESS); - Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]); - aRenderer.renderFaceXPos(aBlock, aX, aY, aZ, mIconContainer.getIcon()); - if (mIconContainer.getOverlayIcon() != null) { - Tessellator.instance.setColorOpaque(255, 255, 255); - aRenderer.renderFaceXPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); - } - // TODO: Uncomment this once all addons have migrated to the new Texture API - //draw(aRenderer); - aRenderer.field_152631_f = false; - aRenderer.enableAO = enableAO; - } - - @Override - public void renderYNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API - if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; - final boolean enableAO = aRenderer.enableAO; - // TODO: Uncomment this once all addons have migrated to the new Texture API - //startDrawingQuads(aRenderer, 0.0f, -1.0f, 0.0f); - final Tessellator tessellator = Tessellator.instance; - IIcon aIcon = mIconContainer.getIcon(); - - float minU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMaxX) * 16.0D); - float maxU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMinX) * 16.0D); - float minV = aIcon.getInterpolatedV(aRenderer.renderMinZ * 16.0D); - float maxV = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0D); - - if (aRenderer.renderMinX < 0.0D || aRenderer.renderMaxX > 1.0D) { - minU = 16.0F - aIcon.getMaxU(); - maxU = 16.0F - aIcon.getMinU(); - } - - if (aRenderer.renderMinZ < 0.0D || aRenderer.renderMaxZ > 1.0D) { - minV = aIcon.getMinV(); - maxV = aIcon.getMaxV(); - } - - double minX = aX + aRenderer.renderMinX; - double maxX = aX + aRenderer.renderMaxX; - double minY = aY + aRenderer.renderMinY; - double minZ = aZ + aRenderer.renderMinZ; - double maxZ = aZ + aRenderer.renderMaxZ; - - Tessellator.instance.setBrightness(MAX_BRIGHTNESS); - Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]); - - tessellator.addVertexWithUV(minX, minY, maxZ, maxU, maxV); - tessellator.addVertexWithUV(minX, minY, minZ, maxU, minV); - tessellator.addVertexWithUV(maxX, minY, minZ, minU, minV); - tessellator.addVertexWithUV(maxX, minY, maxZ, minU, maxV); - - if (mIconContainer.getOverlayIcon() != null) { - minU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMaxX) * 16.0D); - maxU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMinX) * 16.0D); - minV = aIcon.getInterpolatedV(aRenderer.renderMinZ * 16.0D); - maxV = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0D); - - if (aRenderer.renderMinX < 0.0D || aRenderer.renderMaxX > 1.0D) { - minU = 16.0F - aIcon.getMaxU(); - maxU = 16.0F - aIcon.getMinU(); - } - - if (aRenderer.renderMinZ < 0.0D || aRenderer.renderMaxZ > 1.0D) { - minV = aIcon.getMinV(); - maxV = aIcon.getMaxV(); - } - - minX = aX + (float) aRenderer.renderMinX; - maxX = aX + (float) aRenderer.renderMaxX; - minY = aY + (float) aRenderer.renderMinY; - minZ = aZ + (float) aRenderer.renderMinZ; - maxZ = aZ + (float) aRenderer.renderMaxZ; - - Tessellator.instance.setColorOpaque(255, 255, 255); - tessellator.addVertexWithUV(minX, minY, maxZ, maxU, maxV); - tessellator.addVertexWithUV(minX, minY, minZ, maxU, minV); - tessellator.addVertexWithUV(maxX, minY, minZ, minU, minV); - tessellator.addVertexWithUV(maxX, minY, maxZ, minU, maxV); - } - // TODO: Uncomment this once all addons have migrated to the new Texture API - //draw(aRenderer); - aRenderer.enableAO = enableAO; - } - - @Override - public void renderYPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API - if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; - final boolean enableAO = aRenderer.enableAO; - aRenderer.enableAO = false; - // TODO: Uncomment this once all addons have migrated to the new Texture API - //startDrawingQuads(aRenderer, 0.0f, 1.0f, 0.0f); - Tessellator.instance.setBrightness(MAX_BRIGHTNESS); - Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]); - aRenderer.renderFaceYPos(aBlock, aX, aY, aZ, mIconContainer.getIcon()); - if (mIconContainer.getOverlayIcon() != null) { - Tessellator.instance.setColorOpaque(255, 255, 255); - aRenderer.renderFaceYPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); - } - // TODO: Uncomment this once all addons have migrated to the new Texture API - //draw(aRenderer); - aRenderer.enableAO = enableAO; - } - - @Override - public void renderZNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API - if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; - final boolean enableAO = aRenderer.enableAO; - aRenderer.enableAO = false; - aRenderer.field_152631_f = true; - // TODO: Uncomment this once all addons have migrated to the new Texture API - //startDrawingQuads(aRenderer, 0.0f, 0.0f, -1.0f); - Tessellator.instance.setBrightness(MAX_BRIGHTNESS); - Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]); - aRenderer.renderFaceZNeg(aBlock, aX, aY, aZ, mIconContainer.getIcon()); - if (mIconContainer.getOverlayIcon() != null) { - Tessellator.instance.setColorOpaque(255, 255, 255); - aRenderer.renderFaceZNeg(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); - } - // TODO: Uncomment this once all addons have migrated to the new Texture API - //draw(aRenderer); - aRenderer.field_152631_f = false; - aRenderer.enableAO = enableAO; - } - - @Override - public void renderZPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API - if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; - final boolean enableAO = aRenderer.enableAO; - aRenderer.enableAO = false; - // TODO: Uncomment this once all addons have migrated to the new Texture API - //startDrawingQuads(aRenderer, 0.0f, 0.0f, 1.0f); - Tessellator.instance.setBrightness(MAX_BRIGHTNESS); - Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]); - aRenderer.renderFaceZPos(aBlock, aX, aY, aZ, mIconContainer.getIcon()); - if (mIconContainer.getOverlayIcon() != null) { - aRenderer.renderFaceZPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); - } - // TODO: Uncomment this once all addons have migrated to the new Texture API - //draw(aRenderer); - aRenderer.enableAO = enableAO; - } - - @Override - public boolean isValidTexture() { - return mIconContainer != null; - } -} diff --git a/src/main/java/gregtech/common/render/GT_RenderedTexture.java b/src/main/java/gregtech/common/render/GT_RenderedTexture.java index 9e76634385..135ebf28c6 100644 --- a/src/main/java/gregtech/common/render/GT_RenderedTexture.java +++ b/src/main/java/gregtech/common/render/GT_RenderedTexture.java @@ -1,55 +1,92 @@ package gregtech.common.render; +import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; +import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing; +import com.gtnewhorizon.structurelib.alignment.enumerable.Rotation; +import gregtech.GT_Mod; import gregtech.api.interfaces.IColorModulationContainer; import gregtech.api.interfaces.IIconContainer; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.LightingHelper; import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.IconFlipped; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; +import static gregtech.api.util.LightingHelper.MAX_BRIGHTNESS; + class GT_RenderedTexture implements ITexture, IColorModulationContainer { protected final IIconContainer mIconContainer; private final short[] mRGBa; + private final boolean glow; + private final boolean stdOrient; + private final boolean useExtFacing; - GT_RenderedTexture(IIconContainer aIcon, short[] aRGBa, boolean allowAlpha) { + GT_RenderedTexture(IIconContainer aIcon, short[] aRGBa, boolean allowAlpha, boolean glow, boolean stdOrient, boolean extFacing) { if (aRGBa.length != 4) throw new IllegalArgumentException("RGBa doesn't have 4 Values @ GT_RenderedTexture"); mIconContainer = aIcon; mRGBa = aRGBa; + this.glow = glow; + this.stdOrient = stdOrient; + this.useExtFacing = extFacing; } @Override public void renderXPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - aRenderer.field_152631_f = true; // TODO: Uncomment this once all addons have migrated to the new Texture API //startDrawingQuads(aRenderer, 1.0f, 0.0f, 0.0f); + final boolean enableAO = aRenderer.enableAO; LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingXPos(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.EAST.ordinal(), mRGBa); - aRenderer.renderFaceXPos(aBlock, aX, aY, aZ, mIconContainer.getIcon()); + if (glow) { + if (aRenderer.useInventoryTint) + return; // TODO: Remove this once all addons have migrated to the new Texture API + if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; + aRenderer.enableAO = false; + lighting.setLightnessOverride(1.0F); + if (enableAO) lighting.setBrightnessOverride(MAX_BRIGHTNESS); + } + lighting.setupLightingXPos(aBlock, aX, aY, aZ).setupColor(ForgeDirection.EAST.ordinal(), mRGBa); + ExtendedFacing rotation = getExtendedFacing(aX, aY, aZ); + renderFaceXPos(aRenderer, aX, aY, aZ, mIconContainer.getIcon(), rotation); if (mIconContainer.getOverlayIcon() != null) { lighting.setupColor(ForgeDirection.EAST.ordinal(), 0xffffff); - aRenderer.renderFaceXPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); + renderFaceXPos(aRenderer, aX, aY, aZ, mIconContainer.getOverlayIcon(), rotation); } + aRenderer.enableAO = enableAO; // TODO: Uncomment this once all addons have migrated to the new Texture API //draw(aRenderer); - aRenderer.field_152631_f = false; } @Override public void renderXNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { // TODO: Uncomment this once all addons have migrated to the new Texture API //startDrawingQuads(aRenderer, -1.0f, 0.0f, 0.0f); + final boolean enableAO = aRenderer.enableAO; LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingXNeg(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.WEST.ordinal(), mRGBa); - aRenderer.renderFaceXNeg(aBlock, aX, aY, aZ, mIconContainer.getIcon()); + if (glow) { + if (aRenderer.useInventoryTint) + return; // TODO: Remove this once all addons have migrated to the new Texture API + if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; + aRenderer.enableAO = false; + lighting.setLightnessOverride(1.0F); + if (enableAO) lighting.setBrightnessOverride(MAX_BRIGHTNESS); + } + lighting.setupLightingXNeg(aBlock, aX, aY, aZ).setupColor(ForgeDirection.WEST.ordinal(), mRGBa); + ExtendedFacing rotation = getExtendedFacing(aX, aY, aZ); + renderFaceXNeg(aRenderer, aX, aY, aZ, mIconContainer.getIcon(), rotation); if (mIconContainer.getOverlayIcon() != null) { lighting.setupColor(ForgeDirection.WEST.ordinal(), 0xffffff); - aRenderer.renderFaceXNeg(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); + renderFaceXNeg(aRenderer, aX, aY, aZ, mIconContainer.getOverlayIcon(), rotation); } + aRenderer.enableAO = enableAO; // TODO: Uncomment this once all addons have migrated to the new Texture API //draw(aRenderer); } @@ -58,14 +95,24 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { public void renderYPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { // TODO: Uncomment this once all addons have migrated to the new Texture API //startDrawingQuads(aRenderer, 0.0f, 1.0f, 0.0f); + final boolean enableAO = aRenderer.enableAO; LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingYPos(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.UP.ordinal(), mRGBa); - aRenderer.renderFaceYPos(aBlock, aX, aY, aZ, mIconContainer.getIcon()); + if (glow) { + if (aRenderer.useInventoryTint) + return; // TODO: Remove this once all addons have migrated to the new Texture API + if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; + aRenderer.enableAO = false; + lighting.setLightnessOverride(1.0F); + if (enableAO) lighting.setBrightnessOverride(MAX_BRIGHTNESS); + } + lighting.setupLightingYPos(aBlock, aX, aY, aZ).setupColor(ForgeDirection.UP.ordinal(), mRGBa); + ExtendedFacing rotation = getExtendedFacing(aX, aY, aZ); + renderFaceYPos(aRenderer, aX, aY, aZ, mIconContainer.getIcon(), rotation); if (mIconContainer.getOverlayIcon() != null) { lighting.setupColor(ForgeDirection.UP.ordinal(), 0xffffff); - aRenderer.renderFaceYPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); + renderFaceYPos(aRenderer, aX, aY, aZ, mIconContainer.getOverlayIcon(), rotation); } + aRenderer.enableAO = enableAO; // TODO: Uncomment this once all addons have migrated to the new Texture API //draw(aRenderer); } @@ -74,96 +121,24 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { public void renderYNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { // TODO: Uncomment this once all addons have migrated to the new Texture API //startDrawingQuads(aRenderer, 0.0f, -1.0f, 0.0f); - final Tessellator tessellator = Tessellator.instance; - IIcon aIcon = mIconContainer.getIcon(); - - float minU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMaxX) * 16.0D); - float maxU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMinX) * 16.0D); - float minV = aIcon.getInterpolatedV(aRenderer.renderMinZ * 16.0D); - float maxV = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0D); - - if (aRenderer.renderMinX < 0.0D || aRenderer.renderMaxX > 1.0D) { - minU = 16.0F - aIcon.getMaxU(); - maxU = 16.0F - aIcon.getMinU(); - } - - if (aRenderer.renderMinZ < 0.0D || aRenderer.renderMaxZ > 1.0D) { - minV = aIcon.getMinV(); - maxV = aIcon.getMaxV(); - } - - double minX = aX + aRenderer.renderMinX; - double maxX = aX + aRenderer.renderMaxX; - double minY = aY + aRenderer.renderMinY; - double minZ = aZ + aRenderer.renderMinZ; - double maxZ = aZ + aRenderer.renderMaxZ; - + final boolean enableAO = aRenderer.enableAO; LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingYNeg(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.DOWN.ordinal(), mRGBa); - - if (aRenderer.enableAO) { - tessellator.setColorOpaque_F(aRenderer.colorRedTopLeft, aRenderer.colorGreenTopLeft, aRenderer.colorBlueTopLeft); - tessellator.setBrightness(aRenderer.brightnessTopLeft); - tessellator.addVertexWithUV(minX, minY, maxZ, maxU, maxV); - tessellator.setColorOpaque_F(aRenderer.colorRedBottomLeft, aRenderer.colorGreenBottomLeft, aRenderer.colorBlueBottomLeft); - tessellator.setBrightness(aRenderer.brightnessBottomLeft); - tessellator.addVertexWithUV(minX, minY, minZ, maxU, minV); - tessellator.setColorOpaque_F(aRenderer.colorRedBottomRight, aRenderer.colorGreenBottomRight, aRenderer.colorBlueBottomRight); - tessellator.setBrightness(aRenderer.brightnessBottomRight); - tessellator.addVertexWithUV(maxX, minY, minZ, minU, minV); - tessellator.setColorOpaque_F(aRenderer.colorRedTopRight, aRenderer.colorGreenTopRight, aRenderer.colorBlueTopRight); - tessellator.setBrightness(aRenderer.brightnessTopRight); - } else { - tessellator.addVertexWithUV(minX, minY, maxZ, maxU, maxV); - tessellator.addVertexWithUV(minX, minY, minZ, maxU, minV); - tessellator.addVertexWithUV(maxX, minY, minZ, minU, minV); - } - tessellator.addVertexWithUV(maxX, minY, maxZ, minU, maxV); - + if (glow) { + if (aRenderer.useInventoryTint) + return; // TODO: Remove this once all addons have migrated to the new Texture API + if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; + aRenderer.enableAO = false; + lighting.setLightnessOverride(1.0F); + if (enableAO) lighting.setBrightnessOverride(MAX_BRIGHTNESS); + } + lighting.setupLightingYNeg(aBlock, aX, aY, aZ).setupColor(ForgeDirection.DOWN.ordinal(), mRGBa); + ExtendedFacing rotation = getExtendedFacing(aX, aY, aZ); + renderFaceYNeg(aRenderer, aX, aY, aZ, mIconContainer.getIcon(), rotation); if (mIconContainer.getOverlayIcon() != null) { - minU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMaxX) * 16.0D); - maxU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMinX) * 16.0D); - minV = aIcon.getInterpolatedV(aRenderer.renderMinZ * 16.0D); - maxV = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0D); - - if (aRenderer.renderMinX < 0.0D || aRenderer.renderMaxX > 1.0D) { - minU = 16.0F - aIcon.getMaxU(); - maxU = 16.0F - aIcon.getMinU(); - } - - if (aRenderer.renderMinZ < 0.0D || aRenderer.renderMaxZ > 1.0D) { - minV = aIcon.getMinV(); - maxV = aIcon.getMaxV(); - } - - minX = aX + (float)aRenderer.renderMinX; - maxX = aX + (float)aRenderer.renderMaxX; - minY = aY + (float)aRenderer.renderMinY; - minZ = aZ + (float)aRenderer.renderMinZ; - maxZ = aZ + (float)aRenderer.renderMaxZ; - - lighting.setupColor(ForgeDirection.DOWN.ordinal(), 0xffffff); - - if (aRenderer.enableAO) { - tessellator.setColorOpaque_F(aRenderer.colorRedTopLeft, aRenderer.colorGreenTopLeft, aRenderer.colorBlueTopLeft); - tessellator.setBrightness(aRenderer.brightnessTopLeft); - tessellator.addVertexWithUV(minX, minY, maxZ, maxU, maxV); - tessellator.setColorOpaque_F(aRenderer.colorRedBottomLeft, aRenderer.colorGreenBottomLeft, aRenderer.colorBlueBottomLeft); - tessellator.setBrightness(aRenderer.brightnessBottomLeft); - tessellator.addVertexWithUV(minX, minY, minZ, maxU, minV); - tessellator.setColorOpaque_F(aRenderer.colorRedBottomRight, aRenderer.colorGreenBottomRight, aRenderer.colorBlueBottomRight); - tessellator.setBrightness(aRenderer.brightnessBottomRight); - tessellator.addVertexWithUV(maxX, minY, minZ, minU, minV); - tessellator.setColorOpaque_F(aRenderer.colorRedTopRight, aRenderer.colorGreenTopRight, aRenderer.colorBlueTopRight); - tessellator.setBrightness(aRenderer.brightnessTopRight); - } else { - tessellator.addVertexWithUV(minX, minY, maxZ, maxU, maxV); - tessellator.addVertexWithUV(minX, minY, minZ, maxU, minV); - tessellator.addVertexWithUV(maxX, minY, minZ, minU, minV); - } - tessellator.addVertexWithUV(maxX, minY, maxZ, minU, maxV); + Tessellator.instance.setColorRGBA(255, 255, 255, 255); + renderFaceYNeg(aRenderer, aX, aY, aZ, mIconContainer.getOverlayIcon(), rotation); } + aRenderer.enableAO = enableAO; // TODO: Uncomment this once all addons have migrated to the new Texture API //draw(aRenderer); } @@ -172,14 +147,24 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { public void renderZPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { // TODO: Uncomment this once all addons have migrated to the new Texture API //startDrawingQuads(aRenderer, 0.0f, 0.0f, 1.0f); + final boolean enableAO = aRenderer.enableAO; LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingZPos(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.SOUTH.ordinal(), mRGBa); - aRenderer.renderFaceZPos(aBlock, aX, aY, aZ, mIconContainer.getIcon()); + if (glow) { + if (aRenderer.useInventoryTint) + return; // TODO: Remove this once all addons have migrated to the new Texture API + if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; + aRenderer.enableAO = false; + lighting.setLightnessOverride(1.0F); + if (enableAO) lighting.setBrightnessOverride(MAX_BRIGHTNESS); + } + lighting.setupLightingZPos(aBlock, aX, aY, aZ).setupColor(ForgeDirection.SOUTH.ordinal(), mRGBa); + ExtendedFacing rotation = getExtendedFacing(aX, aY, aZ); + renderFaceZPos(aRenderer, aX, aY, aZ, mIconContainer.getIcon(), rotation); if (mIconContainer.getOverlayIcon() != null) { lighting.setupColor(ForgeDirection.SOUTH.ordinal(), 0xffffff); - aRenderer.renderFaceZPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); + renderFaceZPos(aRenderer, aX, aY, aZ, mIconContainer.getOverlayIcon(), rotation); } + aRenderer.enableAO = enableAO; // TODO: Uncomment this once all addons have migrated to the new Texture API //draw(aRenderer); } @@ -188,18 +173,26 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { public void renderZNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { // TODO: Uncomment this once all addons have migrated to the new Texture API //startDrawingQuads(aRenderer, 0.0f, 0.0f, -1.0f); - aRenderer.field_152631_f = true; + final boolean enableAO = aRenderer.enableAO; LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingZNeg(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.NORTH.ordinal(), mRGBa); - aRenderer.renderFaceZNeg(aBlock, aX, aY, aZ, mIconContainer.getIcon()); + if (glow) { + if (aRenderer.useInventoryTint) + return; // TODO: Remove this once all addons have migrated to the new Texture API + if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; + aRenderer.enableAO = false; + lighting.setLightnessOverride(1.0F); + if (enableAO) lighting.setBrightnessOverride(MAX_BRIGHTNESS); + } + lighting.setupLightingZNeg(aBlock, aX, aY, aZ).setupColor(ForgeDirection.NORTH.ordinal(), mRGBa); + ExtendedFacing rotation = getExtendedFacing(aX, aY, aZ); + renderFaceZNeg(aRenderer, aX, aY, aZ, mIconContainer.getIcon(), rotation); if (mIconContainer.getOverlayIcon() != null) { lighting.setupColor(ForgeDirection.NORTH.ordinal(), 0xffffff); - aRenderer.renderFaceZNeg(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); + renderFaceZNeg(aRenderer, aX, aY, aZ, mIconContainer.getOverlayIcon(), rotation); } + aRenderer.enableAO = enableAO; // TODO: Uncomment this once all addons have migrated to the new Texture API //draw(aRenderer); - aRenderer.field_152631_f = false; } @Override @@ -211,4 +204,170 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { public boolean isValidTexture() { return mIconContainer != null; } + + /** + * Renders the given texture to the bottom face of the block. Args: block, x, y, z, texture + */ + protected void renderFaceYNeg(RenderBlocks aRenderer, double x, double y, double z, IIcon icon, ExtendedFacing extendedFacing) { + + switch (useExtFacing ? extendedFacing.getRotation() : Rotation.NORMAL) { + case COUNTER_CLOCKWISE: + aRenderer.uvRotateBottom = 2; + break; + case CLOCKWISE: + aRenderer.uvRotateBottom = 1; + break; + case UPSIDE_DOWN: + aRenderer.uvRotateBottom = 3; + break; + default: + aRenderer.uvRotateBottom = 0; + break; + } + + aRenderer.renderFaceYNeg(Blocks.air, x, y, z, new IconFlipped(icon, !stdOrient, false)); + aRenderer.uvRotateBottom = 0; + } + + /** + * Renders the given texture to the top face of the block. Args: block, x, y, z, texture + */ + protected void renderFaceYPos(RenderBlocks aRenderer, double x, double y, double z, IIcon icon, ExtendedFacing extendedFacing) { + + switch (useExtFacing ? extendedFacing.getRotation() : Rotation.NORMAL) { + case COUNTER_CLOCKWISE: + aRenderer.uvRotateTop = 2; + break; + case CLOCKWISE: + aRenderer.uvRotateTop = 1; + break; + case UPSIDE_DOWN: + aRenderer.uvRotateTop = 3; + break; + default: + aRenderer.uvRotateTop = 0; + break; + } + + aRenderer.renderFaceYPos(Blocks.air, x, y, z, icon); + aRenderer.uvRotateTop = 0; + } + + /** + * Renders the given texture to the north (z-negative) face of the block. Args: block, x, y, z, texture + */ + protected void renderFaceZNeg(RenderBlocks aRenderer, double x, double y, double z, IIcon icon, ExtendedFacing extendedFacing) { + aRenderer.field_152631_f = true; + // **NOT A BUG**: aRenderer.uvRotateEast REALLY CONTROLS THE ROTATION OF THE NORTH SIDE + switch (useExtFacing ? extendedFacing.getRotation() : Rotation.NORMAL) { + case COUNTER_CLOCKWISE: + aRenderer.uvRotateEast = 2; + break; + case CLOCKWISE: + aRenderer.uvRotateEast = 1; + break; + case UPSIDE_DOWN: + aRenderer.uvRotateEast = 3; + break; + default: + aRenderer.uvRotateEast = 0; + break; + } + + aRenderer.renderFaceZNeg(Blocks.air, x, y, z, icon); + aRenderer.uvRotateEast = 0; + aRenderer.field_152631_f = false; + } + + /** + * Renders the given texture to the south (z-positive) face of the block. Args: block, x, y, z, texture + */ + protected void renderFaceZPos(RenderBlocks aRenderer, double x, double y, double z, IIcon icon, ExtendedFacing extendedFacing) { + // **NOT A BUG**: aRenderer.uvRotateWest REALLY CONTROLS THE ROTATION OF THE SOUTH SIDE + switch (useExtFacing ? extendedFacing.getRotation() : Rotation.NORMAL) { + case COUNTER_CLOCKWISE: + aRenderer.uvRotateWest = 2; + break; + case CLOCKWISE: + aRenderer.uvRotateWest = 1; + break; + case UPSIDE_DOWN: + aRenderer.uvRotateWest = 3; + break; + default: + aRenderer.uvRotateWest = 0; + break; + } + + aRenderer.renderFaceZPos(Blocks.air, x, y, z, icon); + aRenderer.uvRotateWest = 0; + } + + /** + * Renders the given texture to the west (x-negative) face of the block. Args: block, x, y, z, texture + */ + protected void renderFaceXNeg(RenderBlocks aRenderer, double x, double y, double z, IIcon icon, ExtendedFacing extendedFacing) { + // **NOT A BUG**: aRenderer.uvRotateNorth REALLY CONTROLS THE ROTATION OF THE WEST SIDE + switch (useExtFacing ? extendedFacing.getRotation() : Rotation.NORMAL) { + case COUNTER_CLOCKWISE: + aRenderer.uvRotateNorth = 2; + break; + case CLOCKWISE: + aRenderer.uvRotateNorth = 1; + break; + case UPSIDE_DOWN: + aRenderer.uvRotateNorth = 3; + break; + default: + aRenderer.uvRotateNorth = 0; + break; + } + + aRenderer.renderFaceXNeg(Blocks.air, x, y, z, icon); + aRenderer.uvRotateNorth = 0; + } + + /** + * Renders the given texture to the east (x-positive) face of the block. Args: block, x, y, z, texture + */ + protected void renderFaceXPos(RenderBlocks aRenderer, double x, double y, double z, IIcon icon, ExtendedFacing extendedFacing) { + aRenderer.field_152631_f = true; + // **NOT A BUG**: aRenderer.uvRotateSouth REALLY CONTROLS THE ROTATION OF THE EAST SIDE + switch (useExtFacing ? extendedFacing.getRotation() : Rotation.NORMAL) { + case COUNTER_CLOCKWISE: + aRenderer.uvRotateSouth = 2; + break; + case CLOCKWISE: + aRenderer.uvRotateSouth = 1; + break; + case UPSIDE_DOWN: + aRenderer.uvRotateSouth = 3; + break; + default: + aRenderer.uvRotateSouth = 0; + break; + } + + aRenderer.renderFaceXPos(Blocks.air, x, y, z, icon); + aRenderer.uvRotateSouth = 0; + aRenderer.field_152631_f = false; + } + + private ExtendedFacing getExtendedFacing(int x, int y, int z) { + if (stdOrient) return ExtendedFacing.DEFAULT; + World w = Minecraft.getMinecraft().theWorld; + if (w == null) return ExtendedFacing.DEFAULT; + TileEntity te = w.getTileEntity(x, y, z); + if (te instanceof IGregTechTileEntity) { + IMetaTileEntity meta = ((IGregTechTileEntity) te).getMetaTileEntity(); + if (meta instanceof IAlignmentProvider) { + return ((IAlignmentProvider) meta).getAlignment().getExtendedFacing(); + } else if (meta != null) { + return ExtendedFacing.of(ForgeDirection.getOrientation(meta.getBaseMetaTileEntity().getFrontFacing())); + } + } else if (te instanceof IAlignmentProvider) { + return ((IAlignmentProvider) te).getAlignment().getExtendedFacing(); + } + return ExtendedFacing.DEFAULT; + } } diff --git a/src/main/java/gregtech/common/render/GT_StdRenderedTexture.java b/src/main/java/gregtech/common/render/GT_StdRenderedTexture.java deleted file mode 100644 index ba0f9d3a91..0000000000 --- a/src/main/java/gregtech/common/render/GT_StdRenderedTexture.java +++ /dev/null @@ -1,36 +0,0 @@ -package gregtech.common.render; - -import gregtech.api.interfaces.IIconContainer; -import gregtech.api.util.LightingHelper; -import net.minecraft.block.Block; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraftforge.common.util.ForgeDirection; - -/** - * This ITexture implementation extends the GT_RenderedTexture class - * to render with bottom side flipped as with dumb blocks rendering. - * It is used in Ore blocks rendering so they better blends with dumb block ores - * from vanilla or other mods, when seen from bottom. - */ -class GT_StdRenderedTexture extends GT_RenderedTexture{ - - GT_StdRenderedTexture(IIconContainer aIcon, short[] aRGBa, boolean allowAlpha) { - super(aIcon, aRGBa, allowAlpha); - } - - @Override - public void renderYNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - // TODO: Uncomment this once all addons have migrated to the new Texture API - //startDrawingQuads(aRenderer, 0.0f, -1.0f, 0.0f); - LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingYNeg(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.DOWN.ordinal(), getRGBA()); - aRenderer.renderFaceYNeg(aBlock, aX, aY, aZ, mIconContainer.getIcon()); - if (mIconContainer.getOverlayIcon() != null) { - lighting.setupColor(ForgeDirection.DOWN.ordinal(), 0xffffff); - aRenderer.renderFaceYNeg(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); - } - // TODO: Uncomment this once all addons have migrated to the new Texture API - //draw(aRenderer); - } -} diff --git a/src/main/java/gregtech/common/render/GT_TextureBuilder.java b/src/main/java/gregtech/common/render/GT_TextureBuilder.java index 22446f99a5..82bce4c8c4 100644 --- a/src/main/java/gregtech/common/render/GT_TextureBuilder.java +++ b/src/main/java/gregtech/common/render/GT_TextureBuilder.java @@ -21,6 +21,7 @@ public class GT_TextureBuilder implements ITextureBuilder { private short[] rgba; private boolean allowAlpha; private boolean stdOrient; + private boolean extFacing; private boolean glow; public GT_TextureBuilder() { @@ -76,6 +77,12 @@ public class GT_TextureBuilder implements ITextureBuilder { return this; } + @Override + public ITextureBuilder extFacing() { + this.extFacing = true; + return this; + } + @Override public ITextureBuilder glow() { glow = true; @@ -88,9 +95,7 @@ public class GT_TextureBuilder implements ITextureBuilder { if (!textureLayers.isEmpty()) return new GT_MultiTexture(textureLayers.toArray(new ITexture[0])); switch (iconContainerList.size()) { case 1: - if (stdOrient) return new GT_StdRenderedTexture(iconContainerList.get(0), rgba, allowAlpha); - if (glow) return new GT_RenderedGlowTexture(iconContainerList.get(0), rgba, allowAlpha); - return new GT_RenderedTexture(iconContainerList.get(0), rgba, allowAlpha); + return new GT_RenderedTexture(iconContainerList.get(0), rgba, allowAlpha, glow, stdOrient, extFacing); case 6: return new GT_SidedTexture( iconContainerList.get(ForgeDirection.DOWN.ordinal()), -- cgit From f812b4a50c922290d6cdee4d1e5e20530814abdc Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Mon, 31 May 2021 22:59:51 +0800 Subject: Add GT_MetaTileEntity_CubicMultiBlockBase and a few minor changes 1. add ofCoil() IStructureElement to standardise how to add a homogeneous set of coils to the structure definition 2. Changed newMetaEntity's return type back to IMetaTileEntity to prevent addons crying out 3. Initialize mExtendedFacing to ensure rendering code don't step on null --- .../GT_MetaTileEntity_CubicMultiBlockBase.java | 111 +++++++++++++++++++++ .../GT_MetaTileEntity_EnhancedMultiBlockBase.java | 9 +- .../gregtech/api/util/GT_StructureUtility.java | 73 ++++++++++++++ .../java/gregtech/api/util/IGT_HatchAdder.java | 5 +- .../GT_MetaTileEntity_AbstractMultiFurnace.java | 22 ++-- .../GT_MetaTileEntity_ElectricBlastFurnace.java | 18 ++-- .../GT_MetaTileEntity_ImplosionCompressor.java | 60 ++++------- .../multi/GT_MetaTileEntity_MultiFurnace.java | 19 ++-- .../multi/GT_MetaTileEntity_ProcessingArray.java | 59 ++++------- .../multi/GT_MetaTileEntity_VacuumFreezer.java | 85 ++++++---------- 10 files changed, 288 insertions(+), 173 deletions(-) create mode 100644 src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java new file mode 100644 index 0000000000..ef53c1bca2 --- /dev/null +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java @@ -0,0 +1,111 @@ +package gregtech.api.metatileentity.implementations; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.IStructureElement; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.item.ItemStack; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +/** + * A simple 3x3x3 hollow cubic multiblock, that can be arbitrarily rotated, made of a single type of machine casing and accepts hatches everywhere. + * Controller will be placed in front center of the structure. + *

+ * Note: You cannot use different casing for the same Class. Make a new subclass for it. + *

+ * Implementation tips: + * 1. To restrict hatches, override {@link #addDynamoToMachineList(IGregTechTileEntity, int)} and its cousins instead of overriding the whole + * {@link #getStructureDefinition()} or change {@link #checkHatches(IGregTechTileEntity, ItemStack)}. The former is a total overkill, while the later cannot + * stop the structure check early. + * 2. To limit rotation, override {@link #getInitialAlignmentLimits()} + * + * @param + */ +public abstract class GT_MetaTileEntity_CubicMultiBlockBase> extends GT_MetaTileEntity_EnhancedMultiBlockBase { + protected static final String STRUCTURE_PIECE_MAIN = "main"; + private static final ConcurrentMap> STRUCTURE_DEFINITIONS = new ConcurrentHashMap<>(); + private int mCasingAmount = 0; + + protected GT_MetaTileEntity_CubicMultiBlockBase(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + protected GT_MetaTileEntity_CubicMultiBlockBase(String aName) { + super(aName); + } + + + private static IStructureDefinition> createStructure(GT_MetaTileEntity_CubicMultiBlockBase aTile) { + return StructureDefinition.>builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ + {"hhh", "hhh", "hhh"}, + {"h-h", "hhh", "hhh"}, + {"hhh", "hhh", "hhh"}, + })) + .addElement('h', ofChain( + ofHatchAdder(GT_MetaTileEntity_CubicMultiBlockBase::addToMachineList, aTile.getHatchTextureIndex(), 1), + onElementPass( + GT_MetaTileEntity_CubicMultiBlockBase::onCorrectCasingAdded, + aTile.getCasingElement() + ) + )) + .build(); + } + + /** + * Create a simple 3x3x3 hollow cubic structure made of a single type of machine casing and accepts hatches everywhere. + *

+ * The created definition contains a single piece named {@link #STRUCTURE_PIECE_MAIN}. + */ + @Override + @SuppressWarnings("unchecked") + public IStructureDefinition getStructureDefinition() { + return (IStructureDefinition) STRUCTURE_DEFINITIONS.computeIfAbsent(getBaseMetaTileEntity().getMetaTileID(), o -> createStructure(this)); + } + + @Override + public void construct(ItemStack aStack, boolean aHintsOnly) { + buildPiece(STRUCTURE_PIECE_MAIN, aStack, aHintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasingAmount = 0; + return checkPiece(STRUCTURE_PIECE_MAIN, 1, 1, 0) && + mCasingAmount > getRequiredCasingCount() && + checkHatches(aBaseMetaTileEntity, aStack); + } + + /** + * Called by {@link #checkMachine(IGregTechTileEntity, ItemStack)} to check if all required hatches are present. + *

+ * Default implementation requires EXACTLY ONE maintenance hatch to be present, and ignore all other conditions. + * + * @param aBaseMetaTileEntity the tile entity of self + * @param aStack The item stack inside the controller + * @return true if the test passes, false otherwise + */ + protected boolean checkHatches(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + return mMaintenanceHatches.size() == 1; + } + + protected abstract IStructureElement> getCasingElement(); + + /** + * The hatch's texture index. + */ + protected abstract int getHatchTextureIndex(); + + protected abstract int getRequiredCasingCount(); + + protected void onCorrectCasingAdded() { + mCasingAmount++; + } +} diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java index c3d41664b7..89d2ce765e 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java @@ -30,17 +30,15 @@ import java.util.concurrent.atomic.AtomicReferenceArray; */ public abstract class GT_MetaTileEntity_EnhancedMultiBlockBase> extends GT_MetaTileEntity_MultiBlockBase implements IAlignment, IConstructable { private static final AtomicReferenceArray tooltips = new AtomicReferenceArray<>(GregTech_API.METATILEENTITIES.length); - private ExtendedFacing mExtendedFacing; - private final IAlignmentLimits mLimits; + private ExtendedFacing mExtendedFacing = ExtendedFacing.DEFAULT; + private final IAlignmentLimits mLimits = getInitialAlignmentLimits(); protected GT_MetaTileEntity_EnhancedMultiBlockBase(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); - mLimits = getInitialAlignmentLimits(); } protected GT_MetaTileEntity_EnhancedMultiBlockBase(String aName) { super(aName); - mLimits = getInitialAlignmentLimits(); } @Override @@ -128,9 +126,6 @@ public abstract class GT_MetaTileEntity_EnhancedMultiBlockBase newMetaEntity(IGregTechTileEntity aTileEntity); - @SuppressWarnings("unchecked") private IStructureDefinition> getCastedStructureDefinition() { return (IStructureDefinition>) getStructureDefinition(); diff --git a/src/main/java/gregtech/api/util/GT_StructureUtility.java b/src/main/java/gregtech/api/util/GT_StructureUtility.java index c8d845ec19..1db672245c 100644 --- a/src/main/java/gregtech/api/util/GT_StructureUtility.java +++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java @@ -3,13 +3,24 @@ package gregtech.api.util; import com.gtnewhorizon.structurelib.StructureLibAPI; import com.gtnewhorizon.structurelib.structure.IStructureElement; import com.gtnewhorizon.structurelib.structure.IStructureElementNoPlacement; +import gregtech.api.GregTech_API; +import gregtech.api.enums.HeatingCoilLevel; +import gregtech.api.interfaces.IHeatingCoil; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import java.util.function.BiConsumer; +import java.util.function.BiPredicate; +import java.util.function.Function; + +import static com.gtnewhorizon.structurelib.StructureLibAPI.HINT_BLOCK_META_GENERIC_11; + public class GT_StructureUtility { + public static final int HINT_COIL_DEFAULT_DOTS = HINT_BLOCK_META_GENERIC_11; + private GT_StructureUtility() { throw new AssertionError("Not instantiable"); } @@ -68,4 +79,66 @@ public class GT_StructureUtility { } }; } + + /** + * Assume a default of LV coil. Assume all coils accepted. Assumes using {@link #HINT_COIL_DEFAULT_DOTS} as dots. + * @see #ofCoil(BiPredicate, Function, int, Block, int) + */ + public static IStructureElement ofCoil(BiConsumer heatingCoilSetter, Function heatingCoilGetter) { + return ofCoil((t, l) -> { + heatingCoilSetter.accept(t, l); + return true; + }, heatingCoilGetter, HINT_COIL_DEFAULT_DOTS, GregTech_API.sBlockCasings5, 0); + } + + /** + * Assumes using {@link #HINT_COIL_DEFAULT_DOTS} as dots + * @see #ofCoil(BiPredicate, Function, int, Block, int) + */ + public static IStructureElement ofCoil(BiPredicate heatingCoilSetter, Function heatingCoilGetter, Block defaultCoil, int defaultMeta) { + return ofCoil(heatingCoilSetter, heatingCoilGetter, HINT_COIL_DEFAULT_DOTS, defaultCoil, defaultMeta); + } + + /** + * Heating coil structure element. + * @param heatingCoilSetter Notify the controller of this new coil. + * Got called exactly once per coil. + * Might be called less times if structure test fails. + * If the setter returns false then it assumes the coil is rejected. + * @param heatingCoilGetter Get the current heating level. Null means no coil recorded yet. + * @param dots The hinting dots + * @param defaultCoil The block to place when auto constructing + * @param defaultMeta The block meta to place when auto constructing + */ + public static IStructureElement ofCoil(BiPredicate heatingCoilSetter, Function heatingCoilGetter, int dots, Block defaultCoil, int defaultMeta) { + if (heatingCoilSetter == null || heatingCoilGetter == null) { + throw new IllegalArgumentException(); + } + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + if (!(block instanceof IHeatingCoil)) + return false; + HeatingCoilLevel existingLevel = heatingCoilGetter.apply(t), + newLevel = ((IHeatingCoil) block).getCoilHeat(world.getBlockMetadata(x, y, z)); + if (existingLevel == null) { + return heatingCoilSetter.test(t, newLevel); + } else { + return newLevel == existingLevel; + } + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), dots); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return world.setBlock(x, y, z, defaultCoil, defaultMeta, 3); + } + }; + } } diff --git a/src/main/java/gregtech/api/util/IGT_HatchAdder.java b/src/main/java/gregtech/api/util/IGT_HatchAdder.java index be0194fc65..362fddaf1f 100644 --- a/src/main/java/gregtech/api/util/IGT_HatchAdder.java +++ b/src/main/java/gregtech/api/util/IGT_HatchAdder.java @@ -6,9 +6,10 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; public interface IGT_HatchAdder { /** * Callback to add hatch, needs to check if hatch is valid (and add it) + * * @param iGregTechTileEntity hatch - * @param aShort requested texture index, or null if not... + * @param aShort requested texture index, or null if not... * @return managed to add hatch (structure still valid) */ - boolean apply(T t,IGregTechTileEntity iGregTechTileEntity, Short aShort); + boolean apply(T t, IGregTechTileEntity iGregTechTileEntity, Short aShort); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java index ad49c72313..2409c1660c 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java @@ -1,15 +1,13 @@ package gregtech.common.tileentities.machines.multi; import gregtech.api.enums.HeatingCoilLevel; -import gregtech.api.interfaces.IHeatingCoil; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase; -import net.minecraft.block.Block; import net.minecraft.item.ItemStack; public abstract class GT_MetaTileEntity_AbstractMultiFurnace> extends GT_MetaTileEntity_EnhancedMultiBlockBase { - protected HeatingCoilLevel mCoilLevel; + private HeatingCoilLevel mCoilLevel; protected GT_MetaTileEntity_AbstractMultiFurnace(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); @@ -24,16 +22,6 @@ public abstract class GT_MetaTileEntity_AbstractMultiFurnace { public GT_MetaTileEntity_ImplosionCompressor(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -40,7 +40,7 @@ public class GT_MetaTileEntity_ImplosionCompressor extends GT_MetaTileEntity_Mul } @Override - public String[] getDescription() { + protected GT_Multiblock_Tooltip_Builder createTooltip() { final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); tt.addMachineType("Implosion Compressor") .addInfo("Explosions are fun") @@ -57,11 +57,7 @@ public class GT_MetaTileEntity_ImplosionCompressor extends GT_MetaTileEntity_Mul .addInputBus("Any casing") .addOutputBus("Any casing") .toolTipFinisher("Gregtech"); - if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { - return tt.getStructureInformation(); - } else { - return tt.getInformation(); - } + return tt; } @Override @@ -94,11 +90,6 @@ public class GT_MetaTileEntity_ImplosionCompressor extends GT_MetaTileEntity_Mul return true; } - @Override - public boolean isFacingValid(byte aFacing) { - return aFacing > 1; - } - @Override public boolean checkRecipe(ItemStack aStack) { ArrayList tInputList = getStoredInputs(); @@ -147,31 +138,18 @@ public class GT_MetaTileEntity_ImplosionCompressor extends GT_MetaTileEntity_Mul } @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; - if (!aBaseMetaTileEntity.getAirOffset(xDir, 0, zDir)) { - return false; - } - int tAmount = 0; - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 2; j++) { - for (int h = -1; h < 2; h++) { - if ((h != 0) || (((xDir + i != 0) || (zDir + j != 0)) && ((i != 0) || (j != 0)))) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, h, zDir + j); - if ((!addMaintenanceToMachineList(tTileEntity, 16)) && (!addMufflerToMachineList(tTileEntity, 16)) && (!addInputToMachineList(tTileEntity, 16)) && (!addOutputToMachineList(tTileEntity, 16)) && (!addEnergyInputToMachineList(tTileEntity, 16))) { - Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); - byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); - if (((tBlock != GregTech_API.sBlockCasings2) || (tMeta != 0)) && ((tBlock != GregTech_API.sBlockCasings3) || (tMeta != 4))) { - return false; - } - tAmount++; - } - } - } - } - } - return tAmount >= 16; + protected IStructureElement> getCasingElement() { + return ofChain(ofBlock(GregTech_API.sBlockCasings2, 0), ofBlock(GregTech_API.sBlockCasings3, 4)); + } + + @Override + protected int getHatchTextureIndex() { + return 17; + } + + @Override + protected int getRequiredCasingCount() { + return 16; } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java index aae7497f04..96bc87ff74 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java @@ -13,20 +13,23 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_StructureUtility; import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraftforge.common.util.ForgeDirection; -import org.lwjgl.input.Keyboard; import java.util.ArrayList; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAdder; import static gregtech.api.enums.GT_Values.VN; -import static gregtech.api.enums.Textures.BlockIcons.*; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE_GLOW; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_GLOW; +import static gregtech.api.enums.Textures.BlockIcons.casingTexturePages; import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; @@ -44,7 +47,7 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu }) .addElement('c', ofBlock(GregTech_API.sBlockCasings1, CASING_INDEX)) .addElement('m', ofHatchAdder(GT_MetaTileEntity_MultiFurnace::addMufflerToMachineList, CASING_INDEX, 2)) - .addElement('C', ofBlockAdder(GT_MetaTileEntity_MultiFurnace::addCoil, GregTech_API.sBlockCasings5, 0)) + .addElement('C', GT_StructureUtility.ofCoil(GT_MetaTileEntity_MultiFurnace::setCoilLevel, GT_MetaTileEntity_MultiFurnace::getCoilLevel)) .addElement('b', ofHatchAdderOptional(GT_MetaTileEntity_MultiFurnace::addBottomHatch, CASING_INDEX, 3, GregTech_API.sBlockCasings1, CASING_INDEX)) .build(); @@ -170,16 +173,16 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu replaceDeprecatedCoils(aBaseMetaTileEntity); - mCoilLevel = null; + setCoilLevel(null); if (!checkPiece(STRUCTURE_PIECE_MAIN, 1, 2, 0)) return false; - if (mCoilLevel == null) + if (getCoilLevel() == null) return false; - this.mLevel = mCoilLevel.getLevel(); - this.mCostDiscount = mCoilLevel.getCostDiscount(); + this.mLevel = getCoilLevel().getLevel(); + this.mCostDiscount = getCoilLevel().getCostDiscount(); return true; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java index 684cead86c..cf29f13b9b 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java @@ -1,5 +1,6 @@ package gregtech.common.tileentities.machines.multi; +import com.gtnewhorizon.structurelib.structure.IStructureElement; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; @@ -9,9 +10,9 @@ import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_CubicMultiBlockBase; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_ProcessingArray_Manager; @@ -24,16 +25,15 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; -import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; -import org.lwjgl.input.Keyboard; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; import static gregtech.api.enums.GT_Values.VN; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_PROCESSING_ARRAY; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_PROCESSING_ARRAY_ACTIVE; @@ -41,7 +41,7 @@ import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_PROCESSING_AR import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_PROCESSING_ARRAY_GLOW; import static gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine.isValidForLowGravity; -public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_MultiBlockBase { +public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_CubicMultiBlockBase { private GT_Recipe mLastRecipe; private int tTier = 0; @@ -62,7 +62,7 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_MultiBl } @Override - public String[] getDescription() { + protected GT_Multiblock_Tooltip_Builder createTooltip() { final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); tt.addMachineType("Processing Array") .addInfo("Runs supplied machines as if placed in the world") @@ -83,11 +83,7 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_MultiBl .addOutputBus("Any casing") .addOutputHatch("Any casing") .toolTipFinisher("Gregtech"); - if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { - return tt.getStructureInformation(); - } else { - return tt.getInformation(); - } + return tt; } @Override @@ -146,11 +142,6 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_MultiBl return aStack != null && aStack.getUnlocalizedName().startsWith("gt.blockmachines.basicmachine."); } - @Override - public boolean isFacingValid(byte aFacing) { - return aFacing > 1; - } - private String mMachine = ""; @Override @@ -328,32 +319,18 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_MultiBl } @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; - if (!aBaseMetaTileEntity.getAirOffset(xDir, 0, zDir)) { - return false; - } - int tAmount = 0; - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 2; j++) { - for (int h = -1; h < 2; h++) { - if ((h != 0) || (((xDir + i != 0) || (zDir + j != 0)) && ((i != 0) || (j != 0)))) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, h, zDir + j); - if ((!addMaintenanceToMachineList(tTileEntity, 48)) && (!addInputToMachineList(tTileEntity, 48)) && (!addOutputToMachineList(tTileEntity, 48)) && (!addEnergyInputToMachineList(tTileEntity, 48))) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j) != GregTech_API.sBlockCasings4) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j) != 0) { - return false; - } - tAmount++; - } - } - } - } - } - return tAmount >= 14; + protected IStructureElement> getCasingElement() { + return ofBlock(GregTech_API.sBlockCasings4, 0); + } + + @Override + protected int getHatchTextureIndex() { + return 48; + } + + @Override + protected int getRequiredCasingCount() { + return 14; } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java index c800592d0d..0050799ea2 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java @@ -1,19 +1,19 @@ package gregtech.common.tileentities.machines.multi; +import com.gtnewhorizon.structurelib.structure.IStructureElement; +import com.gtnewhorizon.structurelib.structure.StructureUtility; import gregtech.api.GregTech_API; import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_CubicMultiBlockBase; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; -import org.lwjgl.input.Keyboard; import java.util.ArrayList; @@ -23,7 +23,7 @@ import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_VACUUM_FREEZE import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_VACUUM_FREEZER_GLOW; import static gregtech.api.enums.Textures.BlockIcons.casingTexturePages; -public class GT_MetaTileEntity_VacuumFreezer extends GT_MetaTileEntity_MultiBlockBase { +public class GT_MetaTileEntity_VacuumFreezer extends GT_MetaTileEntity_CubicMultiBlockBase { public GT_MetaTileEntity_VacuumFreezer(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -38,25 +38,21 @@ public class GT_MetaTileEntity_VacuumFreezer extends GT_MetaTileEntity_MultiBloc } @Override - public String[] getDescription() { - final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType("Vacuum Freezer") - .addInfo("Controller Block for the Vacuum Freezer") - .addInfo("Cools hot ingots and cells") - .addSeparator() - .beginStructureBlock(3, 3, 3, true) - .addController("Front center") - .addCasingInfo("Frost Proof Machine Casing", 16) - .addEnergyHatch("Any casing") - .addMaintenanceHatch("Any casing") - .addInputBus("Any casing") - .addOutputBus("Any casing") - .toolTipFinisher("Gregtech"); - if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { - return tt.getInformation(); - } else { - return tt.getStructureInformation(); - } + protected GT_Multiblock_Tooltip_Builder createTooltip() { + final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType("Vacuum Freezer") + .addInfo("Controller Block for the Vacuum Freezer") + .addInfo("Cools hot ingots and cells") + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfo("Frost Proof Machine Casing", 16) + .addEnergyHatch("Any casing") + .addMaintenanceHatch("Any casing") + .addInputBus("Any casing") + .addOutputBus("Any casing") + .toolTipFinisher("Gregtech"); + return tt; } @Override @@ -95,11 +91,6 @@ public class GT_MetaTileEntity_VacuumFreezer extends GT_MetaTileEntity_MultiBloc return true; } - @Override - public boolean isFacingValid(byte aFacing) { - return aFacing > 1; - } - @Override public boolean checkRecipe(ItemStack aStack) { ArrayList tInputList = getStoredInputs(); @@ -131,32 +122,18 @@ public class GT_MetaTileEntity_VacuumFreezer extends GT_MetaTileEntity_MultiBloc } @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; - if (!aBaseMetaTileEntity.getAirOffset(xDir, 0, zDir)) { - return false; - } - int tAmount = 0; - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 2; j++) { - for (int h = -1; h < 2; h++) { - if ((h != 0) || (((xDir + i != 0) || (zDir + j != 0)) && ((i != 0) || (j != 0)))) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, h, zDir + j); - if ((!addMaintenanceToMachineList(tTileEntity, 17)) && (!addInputToMachineList(tTileEntity, 17)) && (!addOutputToMachineList(tTileEntity, 17)) && (!addEnergyInputToMachineList(tTileEntity, 17))) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j) != GregTech_API.sBlockCasings2) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j) != 1) { - return false; - } - tAmount++; - } - } - } - } - } - return tAmount >= 16; + protected IStructureElement> getCasingElement() { + return StructureUtility.ofBlock(GregTech_API.sBlockCasings2, 1); + } + + @Override + protected int getHatchTextureIndex() { + return 17; + } + + @Override + protected int getRequiredCasingCount() { + return 16; } @Override -- cgit From b0903281c7f2688724335a0a0684f9faeb96d9fc Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Wed, 16 Jun 2021 11:05:12 +0800 Subject: optimize fuel recipe lookup Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../GT_MetaTileEntity_BasicGenerator.java | 27 +++++----- src/main/java/gregtech/api/util/GT_Recipe.java | 23 +++++++++ .../multi/GT_MetaTileEntity_DieselEngine.java | 57 ++++++++++------------ .../multi/GT_MetaTileEntity_LargeTurbine_Gas.java | 10 ++-- .../GT_MetaTileEntity_LargeTurbine_Plasma.java | 10 ++-- .../postload/GT_ExtremeDieselFuelLoader.java | 13 ++--- 6 files changed, 72 insertions(+), 68 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java index 9bbfbf0a3a..63151bde59 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java @@ -18,8 +18,6 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidContainerItem; import net.minecraftforge.fluids.IFluidHandler; -import java.util.Collection; - import static gregtech.api.enums.GT_Values.V; public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity_BasicTank { @@ -271,19 +269,18 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity public int getFuelValue(FluidStack aLiquid) { //System.out.println("Fluid stack check"); - if (aLiquid == null || getRecipes() == null) return 0; - FluidStack tLiquid; - Collection tRecipeList = getRecipes().mRecipeList; - if (tRecipeList != null) for (GT_Recipe tFuel : tRecipeList) - if ((tLiquid = GT_Utility.getFluidForFilledItem(tFuel.getRepresentativeInput(0), true)) != null) - if (aLiquid.isFluidEqual(tLiquid)){ - long val=(long)tFuel.mSpecialValue * getEfficiency() * consumedFluidPerOperation(tLiquid) / 100; - if(val> Integer.MAX_VALUE){ - throw new ArithmeticException("Integer LOOPBACK!"); - } - return (int) val; - } - return 0; + GT_Recipe_Map tRecipes = getRecipes(); + if (aLiquid == null || !(tRecipes instanceof GT_Recipe.GT_Recipe_Map_Fuel)) return 0; + GT_Recipe.GT_Recipe_Map_Fuel tFuels = (GT_Recipe.GT_Recipe_Map_Fuel) tRecipes; + GT_Recipe tFuel = tFuels.findFuel(aLiquid); + if (tFuel == null) { + return 0; + } + long val=(long)tFuel.mSpecialValue * getEfficiency() * consumedFluidPerOperation(aLiquid) / 100; + if(val> Integer.MAX_VALUE){ + throw new ArithmeticException("Integer LOOPBACK!"); + } + return (int) val; } public int getFuelValue(ItemStack aStack) { diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index a04df205b7..a5b263a145 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -197,6 +197,11 @@ public class GT_Recipe implements Comparable { this(aInput1, aOutput1, null, null, null, aFuelValue, aType); } + private static FluidStack[] tryGetFluidInputsFromCells(ItemStack aInput) { + FluidStack tFluid = GT_Utility.getFluidForFilledItem(aInput, true); + return tFluid == null ? null : new FluidStack[] {tFluid}; + } + // aSpecialValue = EU per Liter! If there is no Liquid for this Object, then it gets multiplied with 1000! public GT_Recipe(ItemStack aInput1, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, ItemStack aOutput4, int aSpecialValue, int aType) { this(true, new ItemStack[]{aInput1}, new ItemStack[]{aOutput1, aOutput2, aOutput3, aOutput4}, null, null, null, null, 0, 0, Math.max(1, aSpecialValue)); @@ -977,6 +982,7 @@ public class GT_Recipe implements Comparable { * Just a Recipe Map with Utility specifically for Fuels. */ public static class GT_Recipe_Map_Fuel extends GT_Recipe_Map { + private final Map mRecipesByFluidInput = new HashMap<>(); public GT_Recipe_Map_Fuel(Collection aRecipeList, String aUnlocalizedName, String aLocalName, String aNEIName, String aNEIGUIPath, int aUsualInputCount, int aUsualOutputCount, int aMinimalInputItems, int aMinimalInputFluids, int aAmperage, String aNEISpecialValuePre, int aNEISpecialValueMultiplier, String aNEISpecialValuePost, boolean aShowVoltageAmperageInNEI, boolean aNEIAllowed) { super(aRecipeList, aUnlocalizedName, aLocalName, aNEIName, aNEIGUIPath, aUsualInputCount, aUsualOutputCount, aMinimalInputItems, aMinimalInputFluids, aAmperage, aNEISpecialValuePre, aNEISpecialValueMultiplier, aNEISpecialValuePost, aShowVoltageAmperageInNEI, aNEIAllowed); } @@ -1000,6 +1006,23 @@ public class GT_Recipe implements Comparable { public GT_Recipe addFuel(ItemStack aInput, ItemStack aOutput, FluidStack aFluidInput, FluidStack aFluidOutput, int aChance, int aFuelValueInEU) { return addRecipe(true, new ItemStack[]{aInput}, new ItemStack[]{aOutput}, null, new int[]{aChance}, new FluidStack[]{aFluidInput}, new FluidStack[]{aFluidOutput}, 0, 0, aFuelValueInEU); } + + @Override + public GT_Recipe add(GT_Recipe aRecipe) { + aRecipe = super.add(aRecipe); + if (aRecipe.mInputs != null && aRecipe.mInputs.length == 1 && (aRecipe.mFluidInputs == null || aRecipe.mFluidInputs.length == 0)) { + FluidStack tFluid = GT_Utility.getFluidForFilledItem(aRecipe.mInputs[0], true); + if (tFluid != null) { + tFluid.amount = 0; + mRecipesByFluidInput.put(tFluid.getUnlocalizedName(), aRecipe); + } + } + return aRecipe; + } + + public GT_Recipe findFuel(FluidStack aFluidInput) { + return mRecipesByFluidInput.get(aFluidInput.getUnlocalizedName()); + } } /** diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DieselEngine.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DieselEngine.java index 1783a0c328..567297648a 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DieselEngine.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DieselEngine.java @@ -14,7 +14,6 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffl import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Utility; import net.minecraft.block.Block; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; @@ -24,7 +23,6 @@ import net.minecraft.util.StatCollector; import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; -import java.util.Collection; import static com.gtnewhorizon.structurelib.structure.StructureUtility.defer; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; @@ -160,34 +158,30 @@ public class GT_MetaTileEntity_DieselEngine extends GT_MetaTileEntity_EnhancedMu @Override public boolean checkRecipe(ItemStack aStack) { ArrayList tFluids = getStoredFluids(); - Collection tRecipeList = getFuelMap().mRecipeList; - - if(!tFluids.isEmpty() && tRecipeList != null) { //Does input hatch have a diesel fuel? - for (FluidStack hatchFluid1 : tFluids) { //Loops through hatches - for(GT_Recipe aFuel : tRecipeList) { //Loops through diesel fuel recipes - FluidStack tLiquid; - if ((tLiquid = GT_Utility.getFluidForFilledItem(aFuel.getRepresentativeInput(0), true)) != null) { //Create fluidstack from current recipe - if (hatchFluid1.isFluidEqual(tLiquid)) { //Has a diesel fluid - fuelConsumption = tLiquid.amount = boostEu ? (getBoostFactor() * getNominalOutput() / aFuel.mSpecialValue) : (getNominalOutput() / aFuel.mSpecialValue); //Calc fuel consumption - if(depleteInput(tLiquid)) { //Deplete that amount - boostEu = depleteInput(getBooster().getGas(2L * getAdditiveFactor())); - - if(tFluids.contains(Materials.Lubricant.getFluid(1L))) { //Has lubricant? - //Deplete Lubricant. 1000L should = 1 hour of runtime (if baseEU = 2048) - if(mRuntime % 72 == 0 || mRuntime == 0) depleteInput(Materials.Lubricant.getFluid((boostEu ? 2L : 1L) * getAdditiveFactor())); - } else return false; - - fuelValue = aFuel.mSpecialValue; - fuelRemaining = hatchFluid1.amount; //Record available fuel - this.mEUt = mEfficiency < 2000 ? 0 : getNominalOutput(); //Output 0 if startup is less than 20% - this.mProgresstime = 1; - this.mMaxProgresstime = 1; - this.mEfficiencyIncrease = getEfficiencyIncrease(); - return true; - } - } - } - } + + // fast track lookup + if (!tFluids.isEmpty()) { + for (FluidStack tFluid : tFluids) { + GT_Recipe tRecipe = getFuelMap().findFuel(tFluid); + if (tRecipe == null) continue; + + FluidStack tLiquid = tFluid.copy(); + fuelConsumption = tLiquid.amount = boostEu ? (getBoostFactor() * getNominalOutput() / tRecipe.mSpecialValue) : (getNominalOutput() / tRecipe.mSpecialValue); //Calc fuel consumption + //Deplete that amount + if (!depleteInput(tLiquid)) return false; + boostEu = depleteInput(getBooster().getGas(2L * getAdditiveFactor())); + + //Deplete Lubricant. 1000L should = 1 hour of runtime (if baseEU = 2048) + if ((mRuntime % 72 == 0 || mRuntime == 0) && !depleteInput(Materials.Lubricant.getFluid((boostEu ? 2L : 1L) * getAdditiveFactor()))) + return false; + + fuelValue = tRecipe.mSpecialValue; + fuelRemaining = tFluid.amount; //Record available fuel + this.mEUt = mEfficiency < 2000 ? 0 : getNominalOutput(); //Output 0 if startup is less than 20% + this.mProgresstime = 1; + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = getEfficiencyIncrease(); + return true; } } this.mEUt = 0; @@ -195,6 +189,7 @@ public class GT_MetaTileEntity_DieselEngine extends GT_MetaTileEntity_EnhancedMu return false; } + @Override public IStructureDefinition getStructureDefinition() { return STRUCTURE_DEFINITION; @@ -299,7 +294,7 @@ public class GT_MetaTileEntity_DieselEngine extends GT_MetaTileEntity_EnhancedMu getIdealStatus() == getRepairStatus() ? EnumChatFormatting.GREEN+StatCollector.translateToLocal("GT5U.turbine.maintenance.false")+EnumChatFormatting.RESET : EnumChatFormatting.RED+StatCollector.translateToLocal("GT5U.turbine.maintenance.true")+EnumChatFormatting.RESET, - StatCollector.translateToLocal("GT5U.engine.output")+": " +EnumChatFormatting.RED+(-mEUt*mEfficiency/10000)+EnumChatFormatting.RESET+" EU/t", + StatCollector.translateToLocal("GT5U.engine.output")+": " +EnumChatFormatting.RED+(mEUt*mEfficiency/10000)+EnumChatFormatting.RESET+" EU/t", StatCollector.translateToLocal("GT5U.engine.consumption")+": " +EnumChatFormatting.YELLOW+fuelConsumption+EnumChatFormatting.RESET+" L/t", StatCollector.translateToLocal("GT5U.engine.value")+": " +EnumChatFormatting.YELLOW+fuelValue+EnumChatFormatting.RESET+" EU/L", StatCollector.translateToLocal("GT5U.turbine.fuel")+": " +EnumChatFormatting.GOLD+fuelRemaining+EnumChatFormatting.RESET+" L", diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Gas.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Gas.java index 214e0648c2..27e4bf7084 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Gas.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Gas.java @@ -14,7 +14,6 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; -import java.util.Collection; import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS5; import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS_ACTIVE5; @@ -56,12 +55,9 @@ public class GT_MetaTileEntity_LargeTurbine_Gas extends GT_MetaTileEntity_LargeT } public int getFuelValue(FluidStack aLiquid) { - if (aLiquid == null || GT_Recipe_Map.sTurbineFuels == null) return 0; - FluidStack tLiquid; - Collection tRecipeList = GT_Recipe_Map.sTurbineFuels.mRecipeList; - if (tRecipeList != null) for (GT_Recipe tFuel : tRecipeList) - if ((tLiquid = GT_Utility.getFluidForFilledItem(tFuel.getRepresentativeInput(0), true)) != null) - if (aLiquid.isFluidEqual(tLiquid)) return tFuel.mSpecialValue; + if (aLiquid == null) return 0; + GT_Recipe tFuel = GT_Recipe_Map.sTurbineFuels.findFuel(aLiquid); + if (tFuel != null) return tFuel.mSpecialValue; return 0; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Plasma.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Plasma.java index efc3ecaea3..d1bf1e7c0b 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Plasma.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Plasma.java @@ -22,7 +22,6 @@ import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; -import java.util.Collection; import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU_ACTIVE5; import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS; @@ -63,12 +62,9 @@ public class GT_MetaTileEntity_LargeTurbine_Plasma extends GT_MetaTileEntity_Lar } public int getFuelValue(FluidStack aLiquid) { - if (aLiquid == null || GT_Recipe_Map.sTurbineFuels == null) return 0; - FluidStack tLiquid; - Collection tRecipeList = GT_Recipe_Map.sPlasmaFuels.mRecipeList; - if (tRecipeList != null) for (GT_Recipe tFuel : tRecipeList) - if ((tLiquid = GT_Utility.getFluidForFilledItem(tFuel.getRepresentativeInput(0), true)) != null) - if (aLiquid.isFluidEqual(tLiquid)) return tFuel.mSpecialValue; + if (aLiquid == null) return 0; + GT_Recipe tFuel = GT_Recipe_Map.sPlasmaFuels.findFuel(aLiquid); + if (tFuel != null) return tFuel.mSpecialValue; return 0; } diff --git a/src/main/java/gregtech/loaders/postload/GT_ExtremeDieselFuelLoader.java b/src/main/java/gregtech/loaders/postload/GT_ExtremeDieselFuelLoader.java index dcb76ae17b..d85a47e3c9 100644 --- a/src/main/java/gregtech/loaders/postload/GT_ExtremeDieselFuelLoader.java +++ b/src/main/java/gregtech/loaders/postload/GT_ExtremeDieselFuelLoader.java @@ -3,7 +3,6 @@ package gregtech.loaders.postload; import gregtech.api.enums.Materials; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Utility; import net.minecraftforge.fluids.FluidStack; public class GT_ExtremeDieselFuelLoader implements Runnable { @@ -11,13 +10,11 @@ public class GT_ExtremeDieselFuelLoader implements Runnable { public void run() { GT_Log.out.println("GT_Mod: Adding extreme diesel fuel."); FluidStack tHOGStack = Materials.GasolinePremium.getFluid(1); - for (GT_Recipe tFuel : GT_Recipe.GT_Recipe_Map.sDieselFuels.mRecipeList) { - FluidStack tLiquid = GT_Utility.getFluidForFilledItem(tFuel.getRepresentativeInput(0), true); - if (tLiquid != null && tHOGStack.isFluidEqual(tLiquid)) { - GT_Recipe.GT_Recipe_Map.sExtremeDieselFuels.add(tFuel); - return; - } + GT_Recipe tFuel = GT_Recipe.GT_Recipe_Map.sDieselFuels.findFuel(tHOGStack); + if (tFuel != null) { + GT_Recipe.GT_Recipe_Map.sExtremeDieselFuels.add(tFuel); + } else { + GT_Log.out.println("GT_Mod: No extreme diesel fuel found."); } - GT_Log.out.println("GT_Mod: No extreme diesel fuel found."); } } -- cgit From a47c5003192c87f6960d490abedd1e342acb56bd Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Wed, 16 Jun 2021 16:33:53 +0800 Subject: make fuel recipe map index building a bit more robust Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/api/util/GT_Recipe.java | 3 ++- src/main/java/gregtech/api/util/GT_Utility.java | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index a5b263a145..19f46dfd15 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -1010,7 +1010,8 @@ public class GT_Recipe implements Comparable { @Override public GT_Recipe add(GT_Recipe aRecipe) { aRecipe = super.add(aRecipe); - if (aRecipe.mInputs != null && aRecipe.mInputs.length == 1 && (aRecipe.mFluidInputs == null || aRecipe.mFluidInputs.length == 0)) { + if (aRecipe.mInputs != null && GT_Utility.getNonnullElementCount(aRecipe.mInputs) == 1 && + (aRecipe.mFluidInputs == null || GT_Utility.getNonnullElementCount(aRecipe.mFluidInputs) == 0)) { FluidStack tFluid = GT_Utility.getFluidForFilledItem(aRecipe.mInputs[0], true); if (tFluid != null) { tFluid.amount = 0; diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index c7cee8c9c2..bb2c644f95 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -2884,4 +2884,8 @@ public class GT_Utility { dropItem.delayBeforeCanPickup = 0; } } + + public static long getNonnullElementCount(Object[] tArray) { + return Arrays.stream(tArray).filter(Objects::nonNull).count(); + } } -- cgit From bf056ef6a134d63de48642d5830da216babff9cc Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Thu, 17 Jun 2021 21:27:28 +0800 Subject: Fix coil structure checks Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/api/util/GT_StructureUtility.java | 2 +- .../machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java | 2 +- .../tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_StructureUtility.java b/src/main/java/gregtech/api/util/GT_StructureUtility.java index 1db672245c..2670d9e684 100644 --- a/src/main/java/gregtech/api/util/GT_StructureUtility.java +++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java @@ -122,7 +122,7 @@ public class GT_StructureUtility { return false; HeatingCoilLevel existingLevel = heatingCoilGetter.apply(t), newLevel = ((IHeatingCoil) block).getCoilHeat(world.getBlockMetadata(x, y, z)); - if (existingLevel == null) { + if (existingLevel == null || existingLevel == HeatingCoilLevel.None) { return heatingCoilSetter.test(t, newLevel); } else { return newLevel == existingLevel; diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java index 7c992e7c1e..7b31553253 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java @@ -265,7 +265,7 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab if (!checkPiece(STRUCTURE_PIECE_MAIN, 1, 3, 0)) return false; - if (getCoilLevel() == null) + if (getCoilLevel() == HeatingCoilLevel.None) return false; if (mMaintenanceHatches.size() != 1) diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java index 20ef0fa6e7..ba77716622 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java @@ -181,7 +181,7 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu if (!checkPiece(STRUCTURE_PIECE_MAIN, 1, 2, 0)) return false; - if (getCoilLevel() == null) + if (getCoilLevel() == HeatingCoilLevel.None) return false; this.mLevel = getCoilLevel().getLevel(); -- cgit From e5a6de86d47d12130afe179303d7de5b78c85bff Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Fri, 25 Jun 2021 20:54:11 +0800 Subject: general bugfix & tweaking pass for multis 1. stupid typo in EBF preventing it from working at all. 2. All multis now require exactly one maintenance hatch to form. 3. All multis now use the unified overclocking mechanism if possible. 4. All multis that emits pollution now require at least one muffler hatch to form. 5. Coil structure element slightly tweaked. Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../java/gregtech/api/enums/HeatingCoilLevel.java | 10 ++++++-- .../gregtech/api/util/GT_StructureUtility.java | 30 ++++++++-------------- .../gregtech/common/blocks/GT_Block_Casings5.java | 29 +++++++++++++++++++++ .../multi/GT_MetaTileEntity_AssemblyLine.java | 26 +++++++------------ .../multi/GT_MetaTileEntity_DistillationTower.java | 19 ++++++++++---- .../multi/GT_MetaTileEntity_DrillerBase.java | 2 +- .../GT_MetaTileEntity_ElectricBlastFurnace.java | 1 + .../multi/GT_MetaTileEntity_LargeTurbine.java | 2 +- .../multi/GT_MetaTileEntity_MultiFurnace.java | 3 +++ .../multi/GT_MetaTileEntity_OilCracker.java | 29 ++++++++++++--------- .../multi/GT_MetaTileEntity_PyrolyseOven.java | 3 ++- 11 files changed, 96 insertions(+), 58 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/enums/HeatingCoilLevel.java b/src/main/java/gregtech/api/enums/HeatingCoilLevel.java index d4446e31d0..c2e3ff075a 100644 --- a/src/main/java/gregtech/api/enums/HeatingCoilLevel.java +++ b/src/main/java/gregtech/api/enums/HeatingCoilLevel.java @@ -23,6 +23,8 @@ public enum HeatingCoilLevel { MAX, ; + private static final HeatingCoilLevel[] VALUES = values(); + /** * @return the Coils Tier Name */ @@ -61,9 +63,13 @@ public enum HeatingCoilLevel { } public static HeatingCoilLevel getFromTier(byte tier){ - if (tier < 0 || tier > HeatingCoilLevel.values().length -1) + if (tier < 0 || tier > VALUES.length -1) return HeatingCoilLevel.None; - return HeatingCoilLevel.values()[tier+2]; + return VALUES[tier+2]; + } + + public static int size() { + return VALUES.length; } } diff --git a/src/main/java/gregtech/api/util/GT_StructureUtility.java b/src/main/java/gregtech/api/util/GT_StructureUtility.java index 2670d9e684..5067c698ab 100644 --- a/src/main/java/gregtech/api/util/GT_StructureUtility.java +++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java @@ -7,6 +7,7 @@ import gregtech.api.GregTech_API; import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.interfaces.IHeatingCoil; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.common.blocks.GT_Block_Casings5; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -19,8 +20,6 @@ import java.util.function.Function; import static com.gtnewhorizon.structurelib.StructureLibAPI.HINT_BLOCK_META_GENERIC_11; public class GT_StructureUtility { - public static final int HINT_COIL_DEFAULT_DOTS = HINT_BLOCK_META_GENERIC_11; - private GT_StructureUtility() { throw new AssertionError("Not instantiable"); } @@ -81,22 +80,14 @@ public class GT_StructureUtility { } /** - * Assume a default of LV coil. Assume all coils accepted. Assumes using {@link #HINT_COIL_DEFAULT_DOTS} as dots. - * @see #ofCoil(BiPredicate, Function, int, Block, int) + * Assume all coils accepted. + * @see #ofCoil(BiPredicate, Function) */ public static IStructureElement ofCoil(BiConsumer heatingCoilSetter, Function heatingCoilGetter) { return ofCoil((t, l) -> { heatingCoilSetter.accept(t, l); return true; - }, heatingCoilGetter, HINT_COIL_DEFAULT_DOTS, GregTech_API.sBlockCasings5, 0); - } - - /** - * Assumes using {@link #HINT_COIL_DEFAULT_DOTS} as dots - * @see #ofCoil(BiPredicate, Function, int, Block, int) - */ - public static IStructureElement ofCoil(BiPredicate heatingCoilSetter, Function heatingCoilGetter, Block defaultCoil, int defaultMeta) { - return ofCoil(heatingCoilSetter, heatingCoilGetter, HINT_COIL_DEFAULT_DOTS, defaultCoil, defaultMeta); + }, heatingCoilGetter); } /** @@ -106,11 +97,8 @@ public class GT_StructureUtility { * Might be called less times if structure test fails. * If the setter returns false then it assumes the coil is rejected. * @param heatingCoilGetter Get the current heating level. Null means no coil recorded yet. - * @param dots The hinting dots - * @param defaultCoil The block to place when auto constructing - * @param defaultMeta The block meta to place when auto constructing */ - public static IStructureElement ofCoil(BiPredicate heatingCoilSetter, Function heatingCoilGetter, int dots, Block defaultCoil, int defaultMeta) { + public static IStructureElement ofCoil(BiPredicate heatingCoilSetter, Function heatingCoilGetter) { if (heatingCoilSetter == null || heatingCoilGetter == null) { throw new IllegalArgumentException(); } @@ -131,13 +119,17 @@ public class GT_StructureUtility { @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), dots); + StructureLibAPI.hintParticle(world, x, y, z, GregTech_API.sBlockCasings5, getMeta(trigger)); return true; } + private int getMeta(ItemStack trigger) { + return GT_Block_Casings5.getMetaFromCoilHeat(HeatingCoilLevel.getFromTier((byte) Math.min(HeatingCoilLevel.size(), Math.max(0, trigger.stackSize)))); + } + @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return world.setBlock(x, y, z, defaultCoil, defaultMeta, 3); + return world.setBlock(x, y, z, GregTech_API.sBlockCasings5, getMeta(trigger), 3); } }; } diff --git a/src/main/java/gregtech/common/blocks/GT_Block_Casings5.java b/src/main/java/gregtech/common/blocks/GT_Block_Casings5.java index 296bf765b0..63645f3c3f 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Casings5.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Casings5.java @@ -108,6 +108,35 @@ public class GT_Block_Casings5 extends GT_Block_Casings_Abstract implements IHea } } + public static int getMetaFromCoilHeat(HeatingCoilLevel level) { + switch (level) { + case LV: + return 0; + case MV: + return 1; + case HV: + return 2; + case EV: + return 3; + case IV: + return 4; + case ZPM: + return 5; + case UV: + return 6; + case UEV: + return 7; + case UIV: + return 8; + case LuV: + return 9; + case UHV: + return 10; + default: + return 0; + } + } + @Override public HeatingCoilLevel getCoilHeat(int meta) { getOnCoilCheck().accept(this); diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java index 5d363d9aa1..dd10b2465d 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java @@ -242,13 +242,19 @@ public class GT_MetaTileEntity_AssemblyLine extends GT_MetaTileEntity_EnhancedMu if (!tTag.hasKey("time")) continue; - mMaxProgresstime = tTag.getInteger("time"); - if (mMaxProgresstime <= 0) + int tMaxProgressTime = tTag.getInteger("time"); + if (tMaxProgressTime <= 0) continue; if (!tTag.hasKey("eu")) continue; - mEUt = tTag.getInteger("eu"); + + calculateOverclockedNessMulti(tTag.getInteger("eu"), tMaxProgressTime, 1, getMaxInputVoltage()); + //In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) { + if (GT_Values.D1) GT_FML_LOGGER.info("Recipe too OP"); + continue; + } if (GT_Values.D1) GT_FML_LOGGER.info("Find avaiable recipe"); findRecipe = true; @@ -274,22 +280,8 @@ public class GT_MetaTileEntity_AssemblyLine extends GT_MetaTileEntity_EnhancedMu } if (GT_Values.D1) GT_FML_LOGGER.info("Check overclock"); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(getMaxInputVoltage())); this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); this.mEfficiencyIncrease = 10000; - if (mEUt <= 16) { - this.mEUt = (mEUt * (1 << tTier - 1) * (1 << tTier - 1)); - this.mMaxProgresstime = (mMaxProgresstime / (1 << tTier - 1)); - } else { - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 2; - } - } - if (this.mEUt > 0) { - this.mEUt = -this.mEUt; - } - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); updateSlots(); if (GT_Values.D1) GT_FML_LOGGER.info("Recipe sucessfull"); diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java index 73bbfe056a..bbbaed929a 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java @@ -59,7 +59,11 @@ public class GT_MetaTileEntity_DistillationTower extends GT_MetaTileEntity_Enhan onElementPass(GT_MetaTileEntity_DistillationTower::onCasingFound, ofBlock(GregTech_API.sBlockCasings4, 1)) )) .addElement('c', ofChain( - onElementPass(GT_MetaTileEntity_DistillationTower::onTopLayerFound, ofBlock(GregTech_API.sBlockCasings4, 1)), + onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GT_MetaTileEntity_DistillationTower::addEnergyInputToMachineList, CASING_INDEX, 1)), + onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GT_MetaTileEntity_DistillationTower::addOutputToMachineList, CASING_INDEX, 1)), + onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GT_MetaTileEntity_DistillationTower::addInputToMachineList, CASING_INDEX, 1)), + onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GT_MetaTileEntity_DistillationTower::addMaintenanceToMachineList, CASING_INDEX, 1)), + onElementPass(t -> t.onTopLayerFound(true), ofBlock(GregTech_API.sBlockCasings4, 1)), isAir() )) .build(); @@ -96,7 +100,7 @@ public class GT_MetaTileEntity_DistillationTower extends GT_MetaTileEntity_Enhan .addMaintenanceHatch("Any casing") .addInputHatch("Any bottom layer casing") .addOutputBus("Any bottom layer casing") - .addOutputHatch("2-11x Output Hatches (One per layer except bottom layer)") + .addOutputHatch("2-11x Output Hatches (At least one per layer except bottom layer)") .toolTipFinisher("Gregtech"); return tt; } @@ -182,9 +186,10 @@ public class GT_MetaTileEntity_DistillationTower extends GT_MetaTileEntity_Enhan mCasing++; } - protected void onTopLayerFound() { + protected void onTopLayerFound(boolean aIsCasing) { mTopLayerFound = true; - onCasingFound(); + if (aIsCasing) + onCasingFound(); } protected boolean addLayerOutputHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { @@ -220,9 +225,13 @@ public class GT_MetaTileEntity_DistillationTower extends GT_MetaTileEntity_Enhan return false; // check each layer - while (mHeight < 12 && checkPiece(STRUCTURE_PIECE_LAYER, 1, mHeight, 0) && !mTopLayerFound) + while (mHeight < 12 && checkPiece(STRUCTURE_PIECE_LAYER, 1, mHeight, 0) && !mTopLayerFound) { + if (mOutputHatchesByLayer.get(mHeight - 1).isEmpty()) + // layer without output hatch + return false; // not top mHeight++; + } // validate final invariants... return mCasing >= 7 * mHeight - 5 && mHeight >= 2 && mTopLayerFound && mMaintenanceHatches.size() == 1; diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java index 9bd2a66250..0ea04f1cfa 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java @@ -361,7 +361,7 @@ public abstract class GT_MetaTileEntity_DrillerBase extends GT_MetaTileEntity_En @Override public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { updateCoordinates(); - return checkPiece(STRUCTURE_PIECE_MAIN, 1, 6, 0) && checkHatches() && GT_Utility.getTier(getMaxInputVoltage()) >= getMinTier(); + return checkPiece(STRUCTURE_PIECE_MAIN, 1, 6, 0) && checkHatches() && GT_Utility.getTier(getMaxInputVoltage()) >= getMinTier() && mMaintenanceHatches.size() == 1; } private void updateCoordinates() { diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java index 23c6685d8a..c7a3c3490d 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java @@ -269,6 +269,7 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab return false; if (mMaintenanceHatches.size() != 1) + return false; this.mHeatingCapacity = (int) getCoilLevel().getHeat() + 100 * (GT_Utility.getTier(getMaxInputVoltage()) - 2); return true; diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java index 8cede375dc..fd3117e451 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java @@ -79,7 +79,7 @@ public abstract class GT_MetaTileEntity_LargeTurbine extends GT_MetaTileEntity_E @Override public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - return checkPiece(STRUCTURE_PIECE_MAIN, 2, 2, 1); + return checkPiece(STRUCTURE_PIECE_MAIN, 2, 2, 1) && mMaintenanceHatches.size() == 1 && mMufflerHatches.isEmpty() == (getPollutionPerTick(null) == 0); } public abstract Block getCasingBlock(); diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java index ba77716622..edfce02aad 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java @@ -184,6 +184,9 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu if (getCoilLevel() == HeatingCoilLevel.None) return false; + if (mMaintenanceHatches.size() != 1) + return false; + this.mLevel = getCoilLevel().getLevel(); this.mCostDiscount = getCoilLevel().getCostDiscount(); return true; diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java index e4f96db248..8a257db8ee 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java @@ -49,11 +49,11 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_EnhancedMult .addElement('c', ofCoil(GT_MetaTileEntity_OilCracker::setCoilLevel, GT_MetaTileEntity_OilCracker::getCoilLevel)) .addElement('l', ofChain( ofHatchAdder(GT_MetaTileEntity_OilCracker::addLeftHatchToMachineList, CASING_INDEX, 2), - onElementPass(GT_MetaTileEntity_OilCracker::onCasingAdded, ofBlock(GregTech_API.sBlockCasings4, 2)) + onElementPass(GT_MetaTileEntity_OilCracker::onCasingAdded, ofBlock(GregTech_API.sBlockCasings4, 1)) )) .addElement('r', ofChain( ofHatchAdder(GT_MetaTileEntity_OilCracker::addRightHatchToMachineList, CASING_INDEX, 2), - onElementPass(GT_MetaTileEntity_OilCracker::onCasingAdded, ofBlock(GregTech_API.sBlockCasings4, 3)) + onElementPass(GT_MetaTileEntity_OilCracker::onCasingAdded, ofBlock(GregTech_API.sBlockCasings4, 1)) )) .addElement('m', ofChain( ofHatchAdder(GT_MetaTileEntity_OilCracker::addMiddleInputToMachineList, CASING_INDEX, 1), @@ -90,10 +90,10 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_EnhancedMult .addController("Front center") .addCasingInfo("Clean Stainless Steel Machine Casing", 18) .addOtherStructurePart("2 Rings of 8 Coils", "Each side of the controller") - .addInfo("Gets 5% energy cost reduction per coil tier") + .addInfo("Gets 5% EU/t reduction per coil tier") .addEnergyHatch("Any casing") .addMaintenanceHatch("Any casing") - .addInputHatch("Steam/Hydrogen, Any middle ring casing") + .addInputHatch("Steam/Hydrogen ONLY, Any middle ring casing") .addInputHatch("Any left/right side casing") .addOutputHatch("Any left/right side casing") .addStructureInfo("Input/Output Hatches must be on opposite sides!") @@ -119,6 +119,11 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_EnhancedMult return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "OilCrackingUnit.png"); } + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sCrakingRecipes; + } + @Override public boolean checkRecipe(ItemStack aStack) { ArrayList tInputList = getStoredFluids(); @@ -126,7 +131,7 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_EnhancedMult long tVoltage = getMaxInputVoltage(); byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sCrakingRecipes.findRecipe( + GT_Recipe tRecipe = getRecipeMap().findRecipe( getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], @@ -140,12 +145,10 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_EnhancedMult if (tRecipe.isRecipeInputEqual(true, tFluidInputs, mInventory[1])) { this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); this.mEfficiencyIncrease = 10000; - this.mEUt = tRecipe.mEUt; - this.mMaxProgresstime = tRecipe.mDuration; - while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { - this.mEUt *= 4; - this.mMaxProgresstime /= 2; - } + calculateOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage); + //In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) + return false; this.mEUt *= Math.pow(0.95D, this.heatLevel.getTier()); @@ -248,7 +251,9 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_EnhancedMult mInputOnSide = -1; mOutputOnSide = -1; replaceDeprecatedCoils(aBaseMetaTileEntity); - return checkPiece(STRUCTURE_PIECE_MAIN, 2, 1, 0) && mInputOnSide != -1 && mOutputOnSide != -1 && mCasingAmount >= 18; + return checkPiece(STRUCTURE_PIECE_MAIN, 2, 1, 0) && + mInputOnSide != -1 && mOutputOnSide != -1 && mCasingAmount >= 18 && + mMaintenanceHatches.size() == 1 && !mMiddleInputHatches.isEmpty(); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java index 9ad84d061a..76bdb8423a 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java @@ -188,7 +188,8 @@ public class GT_MetaTileEntity_PyrolyseOven extends GT_MetaTileEntity_EnhancedMu coilHeat = HeatingCoilLevel.None; mCasingAmount = 0; replaceDeprecatedCoils(aBaseMetaTileEntity); - return checkPiece("main", 2, 3, 0) && mCasingAmount >= 60; + return checkPiece("main", 2, 3, 0) && mCasingAmount >= 60 && + mMaintenanceHatches.size() == 1 && !mMufflerHatches.isEmpty(); } @Override -- cgit From 1cdefed2daf27b0a36032067f9af97962bf353fb Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sun, 18 Jul 2021 08:20:13 +0800 Subject: Fix mod loading order problem This utility method could probably be extracted to upstream. Let's do it when the structurelib integration comes to the end of test phase. Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../gregtech/api/util/GT_StructureUtility.java | 37 ++++++++++++++++++++-- .../multi/GT_MetaTileEntity_PyrolyseOven.java | 26 ++++++--------- 2 files changed, 45 insertions(+), 18 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_StructureUtility.java b/src/main/java/gregtech/api/util/GT_StructureUtility.java index 5067c698ab..7e39a0d838 100644 --- a/src/main/java/gregtech/api/util/GT_StructureUtility.java +++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java @@ -3,6 +3,7 @@ package gregtech.api.util; import com.gtnewhorizon.structurelib.StructureLibAPI; import com.gtnewhorizon.structurelib.structure.IStructureElement; import com.gtnewhorizon.structurelib.structure.IStructureElementNoPlacement; +import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.GregTech_API; import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.interfaces.IHeatingCoil; @@ -12,13 +13,12 @@ import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import org.apache.commons.lang3.StringUtils; import java.util.function.BiConsumer; import java.util.function.BiPredicate; import java.util.function.Function; -import static com.gtnewhorizon.structurelib.StructureLibAPI.HINT_BLOCK_META_GENERIC_11; - public class GT_StructureUtility { private GT_StructureUtility() { throw new AssertionError("Not instantiable"); @@ -133,4 +133,37 @@ public class GT_StructureUtility { } }; } + + public static IStructureElement ofBlockUnlocalizedName(String modid, String unlocalizedName, int meta) { + if (StringUtils.isBlank(unlocalizedName)) throw new IllegalArgumentException(); + if (meta < 0) throw new IllegalArgumentException(); + if (meta > 15) throw new IllegalArgumentException(); + if (StringUtils.isBlank(modid)) throw new IllegalArgumentException(); + return new IStructureElement() { + private Block block; + + private Block getBlock() { + if (block == null) + block = GameRegistry.findBlock(modid, unlocalizedName); + return block; + } + + @Override + public boolean check(T t, World world, int x, int y, int z) { + return world.getBlock(x, y, z) != getBlock() && world.getBlockMetadata(x, y, z) == meta; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, getBlock(), meta); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + world.setBlock(x, y, z, getBlock(), meta, 2); + return true; + } + }; + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java index 76bdb8423a..3db096eca3 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java @@ -1,9 +1,9 @@ package gregtech.common.tileentities.machines.multi; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.IStructureElement; import com.gtnewhorizon.structurelib.structure.StructureDefinition; import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.GregTech_API; import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.enums.Textures; @@ -17,12 +17,10 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import net.minecraft.block.Block; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.oredict.OreDictionary; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; @@ -32,6 +30,7 @@ import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_PYROLYSE_OVEN import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_PYROLYSE_OVEN_ACTIVE; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_PYROLYSE_OVEN_ACTIVE_GLOW; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_PYROLYSE_OVEN_GLOW; +import static gregtech.api.util.GT_StructureUtility.ofBlockUnlocalizedName; import static gregtech.api.util.GT_StructureUtility.ofCoil; import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; @@ -43,16 +42,11 @@ public class GT_MetaTileEntity_PyrolyseOven extends GT_MetaTileEntity_EnhancedMu private static final IStructureDefinition STRUCTURE_DEFINITION = createStructureDefinition(); private static IStructureDefinition createStructureDefinition() { - Block casingBlock; - int casingMeta; - - if (Loader.isModLoaded("dreamcraft")) { - casingBlock = GameRegistry.findBlock("dreamcraft", "gt.blockcasingsNH"); - casingMeta = 2; - } else { - casingBlock = GregTech_API.sBlockCasings1; - casingMeta = 0; - } + IStructureElement tCasingElement = + Loader.isModLoaded("dreamcraft") ? + ofBlockUnlocalizedName("dreamcraft", "gt.blockcasingsNH", 2) : + ofBlock(GregTech_API.sBlockCasings1, 0); + return StructureDefinition.builder() .addShape("main", transpose(new String[][]{ {"ccccc", "ctttc", "ctttc", "ctttc", "ccccc"}, @@ -60,18 +54,18 @@ public class GT_MetaTileEntity_PyrolyseOven extends GT_MetaTileEntity_EnhancedMu {"ccccc", "c---c", "c---c", "c---c", "ccccc"}, {"bb~bb", "bCCCb", "bCCCb", "bCCCb", "bbbbb"}, })) - .addElement('c', onElementPass(GT_MetaTileEntity_PyrolyseOven::onCasingAdded, ofBlock(casingBlock, casingMeta))) + .addElement('c', onElementPass(GT_MetaTileEntity_PyrolyseOven::onCasingAdded, tCasingElement)) .addElement('C', ofCoil(GT_MetaTileEntity_PyrolyseOven::setCoilLevel, GT_MetaTileEntity_PyrolyseOven::getCoilLevel)) .addElement('b', ofChain( ofHatchAdder(GT_MetaTileEntity_PyrolyseOven::addMaintenanceToMachineList, CASING_INDEX, 1), ofHatchAdder(GT_MetaTileEntity_PyrolyseOven::addOutputToMachineList, CASING_INDEX, 1), ofHatchAdder(GT_MetaTileEntity_PyrolyseOven::addEnergyInputToMachineList, CASING_INDEX, 1), - onElementPass(GT_MetaTileEntity_PyrolyseOven::onCasingAdded, ofBlock(casingBlock, casingMeta)) + onElementPass(GT_MetaTileEntity_PyrolyseOven::onCasingAdded, tCasingElement) )) .addElement('t', ofChain( ofHatchAdder(GT_MetaTileEntity_PyrolyseOven::addInputToMachineList, CASING_INDEX, 1), ofHatchAdder(GT_MetaTileEntity_PyrolyseOven::addMufflerToMachineList, CASING_INDEX, 1), - onElementPass(GT_MetaTileEntity_PyrolyseOven::onCasingAdded, ofBlock(casingBlock, casingMeta)) + onElementPass(GT_MetaTileEntity_PyrolyseOven::onCasingAdded, tCasingElement) )) .build(); } -- cgit From bfe1836ddc069653d9af9d59008ec23f4dcb6c05 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Mon, 19 Jul 2021 15:51:27 +0800 Subject: Fixes related to coil hint blocks Also updates StructureLib to fix invisible block hint and pulled the utility methods up. Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- build.properties | 2 +- .../java/gregtech/api/enums/HeatingCoilLevel.java | 6 +++- .../api/metatileentity/BaseMetaTileEntity.java | 11 ++++++- .../gregtech/api/util/GT_StructureUtility.java | 36 ++-------------------- .../multi/GT_MetaTileEntity_PyrolyseOven.java | 2 +- 5 files changed, 19 insertions(+), 38 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/build.properties b/build.properties index c9a1e92d05..16566feedf 100644 --- a/build.properties +++ b/build.properties @@ -1,7 +1,7 @@ minecraft.version=1.7.10 forge.version=10.13.4.1614-1.7.10 gt.version=5.09.37.02 -structurelib.version=1.0.4 +structurelib.version=1.0.5 ae2.version=rv3-beta-22 applecore.version=1.7.10-1.2.1+107.59407 buildcraft.version=7.1.11 diff --git a/src/main/java/gregtech/api/enums/HeatingCoilLevel.java b/src/main/java/gregtech/api/enums/HeatingCoilLevel.java index c2e3ff075a..06ceedff53 100644 --- a/src/main/java/gregtech/api/enums/HeatingCoilLevel.java +++ b/src/main/java/gregtech/api/enums/HeatingCoilLevel.java @@ -63,7 +63,7 @@ public enum HeatingCoilLevel { } public static HeatingCoilLevel getFromTier(byte tier){ - if (tier < 0 || tier > VALUES.length -1) + if (tier < 0 || tier > getMaxTier()) return HeatingCoilLevel.None; return VALUES[tier+2]; @@ -72,4 +72,8 @@ public enum HeatingCoilLevel { public static int size() { return VALUES.length; } + + public static int getMaxTier() { + return VALUES.length - 1 - 2; + } } diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 6eb06d8fae..1adcb41259 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -11,6 +11,8 @@ import appeng.tile.events.TileEventType; import com.gtnewhorizon.structurelib.alignment.IAlignment; import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; +import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable; +import com.gtnewhorizon.structurelib.alignment.constructable.IConstructableProvider; import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing; import cpw.mods.fml.common.Optional; import gregtech.GT_Mod; @@ -54,6 +56,7 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; +import javax.annotation.Nullable; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; @@ -73,7 +76,7 @@ import static gregtech.api.objects.XSTR.XSTR_INSTANCE; @Optional.InterfaceList(value = { @Optional.Interface(iface = "appeng.api.networking.security.IActionHost", modid = "appliedenergistics2", striprefs = true), @Optional.Interface(iface = "appeng.me.helpers.IGridProxyable", modid = "appliedenergistics2", striprefs = true)}) -public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileEntity, IActionHost, IGridProxyable, IAlignmentProvider { +public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileEntity, IActionHost, IGridProxyable, IAlignmentProvider, IConstructableProvider { private final GT_CoverBehavior[] mCoverBehaviors = new GT_CoverBehavior[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior}; protected MetaTileEntity mMetaTileEntity; protected long mStoredEnergy = 0, mStoredSteam = 0; @@ -2374,6 +2377,12 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE return getMetaTileEntity() instanceof IAlignmentProvider ? ((IAlignmentProvider) getMetaTileEntity()).getAlignment() : new BasicAlignment(); } + @Nullable + @Override + public IConstructable getConstructable() { + return getMetaTileEntity() instanceof IConstructable ? (IConstructable) getMetaTileEntity() : null; + } + private class BasicAlignment implements IAlignment { @Override diff --git a/src/main/java/gregtech/api/util/GT_StructureUtility.java b/src/main/java/gregtech/api/util/GT_StructureUtility.java index 7e39a0d838..dc916f02e3 100644 --- a/src/main/java/gregtech/api/util/GT_StructureUtility.java +++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java @@ -124,7 +124,8 @@ public class GT_StructureUtility { } private int getMeta(ItemStack trigger) { - return GT_Block_Casings5.getMetaFromCoilHeat(HeatingCoilLevel.getFromTier((byte) Math.min(HeatingCoilLevel.size(), Math.max(0, trigger.stackSize)))); + // -4 to skip unimplemented tiers + return GT_Block_Casings5.getMetaFromCoilHeat(HeatingCoilLevel.getFromTier((byte) Math.min(HeatingCoilLevel.getMaxTier() - 4, Math.max(0, trigger.stackSize)))); } @Override @@ -133,37 +134,4 @@ public class GT_StructureUtility { } }; } - - public static IStructureElement ofBlockUnlocalizedName(String modid, String unlocalizedName, int meta) { - if (StringUtils.isBlank(unlocalizedName)) throw new IllegalArgumentException(); - if (meta < 0) throw new IllegalArgumentException(); - if (meta > 15) throw new IllegalArgumentException(); - if (StringUtils.isBlank(modid)) throw new IllegalArgumentException(); - return new IStructureElement() { - private Block block; - - private Block getBlock() { - if (block == null) - block = GameRegistry.findBlock(modid, unlocalizedName); - return block; - } - - @Override - public boolean check(T t, World world, int x, int y, int z) { - return world.getBlock(x, y, z) != getBlock() && world.getBlockMetadata(x, y, z) == meta; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, getBlock(), meta); - return true; - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x, y, z, getBlock(), meta, 2); - return true; - } - }; - } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java index 3db096eca3..7312e0d992 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java @@ -23,6 +23,7 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockUnlocalizedName; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; @@ -30,7 +31,6 @@ import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_PYROLYSE_OVEN import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_PYROLYSE_OVEN_ACTIVE; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_PYROLYSE_OVEN_ACTIVE_GLOW; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_PYROLYSE_OVEN_GLOW; -import static gregtech.api.util.GT_StructureUtility.ofBlockUnlocalizedName; import static gregtech.api.util.GT_StructureUtility.ofCoil; import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; -- cgit From 875ff766ce3801918c9d726a8a14a6710e655147 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Mon, 19 Jul 2021 19:25:36 +0800 Subject: Make block hint text more informative Also migrated from defer to lazy where possible Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../GT_MetaTileEntity_CubicMultiBlockBase.java | 38 ++-- .../GT_MetaTileEntity_EnhancedMultiBlockBase.java | 2 +- .../api/util/GT_Multiblock_Tooltip_Builder.java | 200 +++++++++++++++++++-- .../multi/GT_MetaTileEntity_AssemblyLine.java | 25 ++- .../GT_MetaTileEntity_ConcreteBackfillerBase.java | 10 +- .../multi/GT_MetaTileEntity_DieselEngine.java | 45 ++--- .../multi/GT_MetaTileEntity_DistillationTower.java | 18 +- .../multi/GT_MetaTileEntity_DrillerBase.java | 51 +++--- .../GT_MetaTileEntity_ElectricBlastFurnace.java | 14 +- .../GT_MetaTileEntity_ExtremeDieselEngine.java | 12 +- .../multi/GT_MetaTileEntity_FusionComputer.java | 129 ++++++------- .../multi/GT_MetaTileEntity_FusionComputer1.java | 6 +- .../multi/GT_MetaTileEntity_FusionComputer2.java | 6 +- .../multi/GT_MetaTileEntity_FusionComputer3.java | 6 +- .../multi/GT_MetaTileEntity_HeatExchanger.java | 11 +- .../GT_MetaTileEntity_ImplosionCompressor.java | 10 +- .../multi/GT_MetaTileEntity_LargeBoiler.java | 61 ++++--- .../GT_MetaTileEntity_LargeChemicalReactor.java | 22 +-- .../multi/GT_MetaTileEntity_LargeTurbine.java | 41 +++-- .../multi/GT_MetaTileEntity_LargeTurbine_Gas.java | 8 +- .../GT_MetaTileEntity_LargeTurbine_HPSteam.java | 8 +- .../GT_MetaTileEntity_LargeTurbine_Plasma.java | 8 +- .../GT_MetaTileEntity_LargeTurbine_Steam.java | 8 +- .../multi/GT_MetaTileEntity_MultiFurnace.java | 12 +- .../multi/GT_MetaTileEntity_OilCracker.java | 13 +- .../multi/GT_MetaTileEntity_OilDrillBase.java | 8 +- .../GT_MetaTileEntity_OreDrillingPlantBase.java | 10 +- .../multi/GT_MetaTileEntity_ProcessingArray.java | 12 +- .../multi/GT_MetaTileEntity_PyrolyseOven.java | 18 +- .../multi/GT_MetaTileEntity_VacuumFreezer.java | 8 +- src/main/resources/assets/gregtech/lang/en_US.lang | 20 +++ 31 files changed, 531 insertions(+), 309 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java index c84ca61eec..5499e756ba 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java @@ -6,7 +6,7 @@ import com.gtnewhorizon.structurelib.structure.StructureDefinition; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.item.ItemStack; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.defer; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; @@ -16,7 +16,8 @@ import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; * A simple 3x3x3 hollow cubic multiblock, that can be arbitrarily rotated, made of a single type of machine casing and accepts hatches everywhere. * Controller will be placed in front center of the structure. *

- * Note: You cannot use different casing for the same Class. Make a new subclass for it. + * Note: You cannot use different casing for the same Class. Make a new subclass for it. You also should not change the casing + * dynamically, i.e. it should be a dumb method returning some sort of constant. *

* Implementation tips: * 1. To restrict hatches, override {@link #addDynamoToMachineList(IGregTechTileEntity, int)} and its cousins instead of overriding the whole @@ -28,20 +29,25 @@ import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; */ public abstract class GT_MetaTileEntity_CubicMultiBlockBase> extends GT_MetaTileEntity_EnhancedMultiBlockBase { protected static final String STRUCTURE_PIECE_MAIN = "main"; - protected static final IStructureDefinition> STRUCTURE_DEFINITION = StructureDefinition.>builder() - .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ - {"hhh", "hhh", "hhh"}, - {"h-h", "hhh", "hhh"}, - {"hhh", "hhh", "hhh"}, - })) - .addElement('h', ofChain( - defer(t -> ofHatchAdder(GT_MetaTileEntity_CubicMultiBlockBase::addToMachineList, t.getHatchTextureIndex(), 1)), - onElementPass( - GT_MetaTileEntity_CubicMultiBlockBase::onCorrectCasingAdded, - defer(GT_MetaTileEntity_CubicMultiBlockBase::getCasingElement) - ) - )) - .build(); + protected static final ClassValue>> STRUCTURE_DEFINITION = new ClassValue>>() { + @Override + protected IStructureDefinition> computeValue(Class type) { + return StructureDefinition.>builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ + {"hhh", "hhh", "hhh"}, + {"h-h", "hhh", "hhh"}, + {"hhh", "hhh", "hhh"}, + })) + .addElement('h', ofChain( + lazy(t -> ofHatchAdder(GT_MetaTileEntity_CubicMultiBlockBase::addToMachineList, t.getHatchTextureIndex(), 1)), + onElementPass( + GT_MetaTileEntity_CubicMultiBlockBase::onCorrectCasingAdded, + lazy(GT_MetaTileEntity_CubicMultiBlockBase::getCasingElement) + ) + )) + .build(); + } + }; private int mCasingAmount = 0; protected GT_MetaTileEntity_CubicMultiBlockBase(int aID, String aName, String aNameRegional) { diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java index a9b50e6662..cc2513f5c2 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java @@ -128,7 +128,7 @@ public abstract class GT_MetaTileEntity_EnhancedMultiBlockBase * Info section order should be:
@@ -32,12 +39,16 @@ import net.minecraft.util.StatCollector; public class GT_Multiblock_Tooltip_Builder { private static final String TAB = " "; private static final String COLON = ": "; - + private static final String SEPARATOR = ", "; + private final List iLines; private final List sLines; - + private final List hLines; + private final SetMultimap hBlocks; + private String[] iArray; private String[] sArray; + private String[] hArray; //Localized tooltips private static final String TT_machineType = StatCollector.translateToLocal("GT5U.MBTT.MachineType"); @@ -58,11 +69,17 @@ public class GT_Multiblock_Tooltip_Builder { private static final String TT_pps = StatCollector.translateToLocal("GT5U.MBTT.PPS"); private static final String TT_hold = StatCollector.translateToLocal("GT5U.MBTT.Hold"); private static final String TT_todisplay = StatCollector.translateToLocal("GT5U.MBTT.Display"); + private static final String TT_structurehint = StatCollector.translateToLocal("GT5U.MBTT.StructureHint"); private static final String TT_mod = StatCollector.translateToLocal("GT5U.MBTT.Mod"); + private static final String TT_air = StatCollector.translateToLocal("GT5U.MBTT.Air"); + private static final String[] TT_dots = IntStream.range(0, 16).mapToObj(i -> StatCollector.translateToLocal("GT5U.MBTT.Dots." + i)).toArray(String[]::new); public GT_Multiblock_Tooltip_Builder() { iLines = new LinkedList<>(); sLines = new LinkedList<>(); + hLines = new LinkedList<>(); + hBlocks = Multimaps.newSetMultimap(new HashMap<>(), HashSet::new); + hBlocks.put(0, TT_air); } /** @@ -103,11 +120,10 @@ public class GT_Multiblock_Tooltip_Builder { } /** - * Add a line telling you what the machine type is. Usually, this will be the name of a SB version.
- * Machine Type: machine + * Add a line telling how much this machine pollutes. * - * @param machine - * Name of the machine type + * @param pollution + * Amount of pollution per second when active * * @return Instance this method was called on. */ @@ -307,7 +323,136 @@ public class GT_Multiblock_Tooltip_Builder { sLines.add(TAB + TT_outputhatch + COLON + info); return this; } - + + /** + * Use this method to add a structural part that isn't covered by the other methods.
+ * (indent)name: info + * @param name + * Name of the hatch or other component. + * @param info + * Positional information. + * @param dots + * The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addOtherStructurePart(String name, String info, int... dots) { + sLines.add(TAB + name + COLON + info); + for (int dot : dots) hBlocks.put(dot, name); + return this; + } + + /** + * Add a line of information about the structure:
+ * (indent)Maintenance Hatch: info + * + * @param info Positional information. + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addMaintenanceHatch(String info, int... dots) { + sLines.add(TAB + TT_maintenancehatch + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_maintenancehatch); + return this; + } + + /** + * Add a line of information about the structure:
+ * (indent)Muffler Hatch: info + * + * @param info Location where the hatch goes + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addMufflerHatch(String info, int... dots) { + sLines.add(TAB + TT_mufflerhatch + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_mufflerhatch); + return this; + } + + /** + * Add a line of information about the structure:
+ * (indent)Energy Hatch: info + * + * @param info Positional information. + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addEnergyHatch(String info, int... dots) { + sLines.add(TAB + TT_energyhatch + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_energyhatch); + return this; + } + + /** + * Add a line of information about the structure:
+ * (indent)Dynamo Hatch: info + * + * @param info Positional information. + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addDynamoHatch(String info, int... dots) { + sLines.add(TAB + TT_dynamohatch + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_dynamohatch); + return this; + } + + /** + * Add a line of information about the structure:
+ * (indent)Input Bus: info + * + * @param info Location where the bus goes + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addInputBus(String info, int... dots) { + sLines.add(TAB + TT_inputbus + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_inputbus); + return this; + } + + /** + * Add a line of information about the structure:
+ * (indent)Input Hatch: info + * + * @param info Location where the hatch goes + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addInputHatch(String info, int... dots) { + sLines.add(TAB + TT_inputhatch + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_inputhatch); + return this; + } + + /** + * Add a line of information about the structure:
+ * (indent)Output Bus: info + * + * @param info Location where the bus goes + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addOutputBus(String info, int... dots) { + sLines.add(TAB + TT_outputbus + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_outputbus); + return this; + } + + /** + * Add a line of information about the structure:
+ * (indent)Output Hatch: info + * + * @param info Location where the bus goes + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addOutputHatch(String info, int... dots) { + sLines.add(TAB + TT_outputhatch + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_outputhatch); + return this; + } + /** * Use this method to add non-standard structural info.
* (indent)info @@ -319,6 +464,30 @@ public class GT_Multiblock_Tooltip_Builder { sLines.add(TAB + info); return this; } + + /** + * Use this method to add non-standard structural hint. This info will appear before the standard structural hint. + * @param info + * The line to be added. This should be an entry into minecraft's localization system. + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addStructureHint(String info) { + hLines.add(StatCollector.translateToLocal(info)); + return this; + } + + /** + * Use this method to add an entry to standard structural hint without creating a corresponding line in structure information + * @param name + * The name of block This should be an entry into minecraft's localization system. + * @param dots + * Possible locations of this block + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addStructureHint(String name, int... dots) { + for (int dot : dots) hBlocks.put(dot, StatCollector.translateToLocal(name)); + return this; + } /** * Call at the very end.
@@ -331,10 +500,10 @@ public class GT_Multiblock_Tooltip_Builder { public void toolTipFinisher(String mod) { iLines.add(TT_hold + " " + EnumChatFormatting.BOLD + "[LSHIFT]" + EnumChatFormatting.RESET + EnumChatFormatting.GRAY + " " + TT_todisplay); iLines.add(TT_mod + COLON + EnumChatFormatting.GREEN + mod + EnumChatFormatting.GRAY); - iArray = new String[iLines.size()]; - sArray = new String[sLines.size()]; - iLines.toArray(iArray); - sLines.toArray(sArray); + hLines.add(TT_structurehint); + iArray = iLines.toArray(new String[0]); + sArray = sLines.toArray(new String[0]); + hArray = Stream.concat(hLines.stream(), hBlocks.asMap().entrySet().stream().map(e -> TT_dots[e.getKey()] + COLON + String.join(SEPARATOR, e.getValue()))).toArray(String[]::new); } public String[] getInformation() { @@ -345,4 +514,7 @@ public class GT_Multiblock_Tooltip_Builder { return sArray; } + public String[] getStructureHint() { + return hArray; + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java index dd10b2465d..60aa372d20 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java @@ -69,18 +69,18 @@ public class GT_MetaTileEntity_AssemblyLine extends GT_MetaTileEntity_EnhancedMu .addElement('m', ofBlock(GregTech_API.sBlockCasings2, 5)) // assembling line casing .addElement('g', ofBlockAnyMeta(GameRegistry.findBlock("IC2", "blockAlloyGlass"))) .addElement('e', ofHatchAdderOptional(GT_MetaTileEntity_AssemblyLine::addEnergyInputToMachineList, 16, 1, GregTech_API.sBlockCasings2, 0)) - .addElement('d', ofHatchAdderOptional(GT_MetaTileEntity_AssemblyLine::addDataAccessToMachineList, 42, 1, GregTech_API.sBlockCasings3, 10)) + .addElement('d', ofHatchAdderOptional(GT_MetaTileEntity_AssemblyLine::addDataAccessToMachineList, 42, 2, GregTech_API.sBlockCasings3, 10)) .addElement('b', ofChain( - ofHatchAdder(GT_MetaTileEntity_AssemblyLine::addMaintenanceToMachineList, 16, 2), - ofHatchAdder(GT_MetaTileEntity_AssemblyLine::addInputHatchToMachineList, 16, 2), + ofHatchAdder(GT_MetaTileEntity_AssemblyLine::addMaintenanceToMachineList, 16, 3), + ofHatchAdder(GT_MetaTileEntity_AssemblyLine::addInputHatchToMachineList, 16, 3), ofBlock(GregTech_API.sBlockCasings2, 0) )) .addElement('I', ofChain( // all blocks nearby use solid steel casing, so let's use the texture of that - ofHatchAdder(GT_MetaTileEntity_AssemblyLine::addInputToMachineList, 16, 2), - ofHatchAdder(GT_MetaTileEntity_AssemblyLine::addOutputToMachineList, 16, 2) + ofHatchAdder(GT_MetaTileEntity_AssemblyLine::addInputToMachineList, 16, 4), + ofHatchAdder(GT_MetaTileEntity_AssemblyLine::addOutputToMachineList, 16,4) )) - .addElement('i', ofHatchAdder(GT_MetaTileEntity_AssemblyLine::addInputToMachineList, 16, 2)) + .addElement('i', ofHatchAdder(GT_MetaTileEntity_AssemblyLine::addInputToMachineList, 16, 5)) .build(); public GT_MetaTileEntity_AssemblyLine(int aID, String aName, String aNameRegional) { @@ -111,15 +111,14 @@ public class GT_MetaTileEntity_AssemblyLine extends GT_MetaTileEntity_EnhancedMu .addStructureInfo("Layer 3 - Grate Machine Casing, Assembler Machine Casing, Grate Machine Casing") .addStructureInfo("Layer 4 - Empty, Solid Steel Machine Casing, Empty") .addStructureInfo("Up to 16 repeating slices, each one allows for 1 more item in recipes, aside from the last") - .addStructureInfo("Optional - Replace 1x Grate with (Advanced) Data Access Hatch next to the Controller") - .addStructureInfo("Optional - Replace 1x Grate with (Advanced) Data Access Hatch next to the Controller")//TT .addController("Either Grate on layer 3 of the first slice") - .addEnergyHatch("Any layer 4 casing") - .addMaintenanceHatch("Any layer 1 casing") - .addInputBus("As specified on layer 1") - .addInputHatch("Any layer 1 casing") - .addOutputBus("Replaces Input Bus on final slice") + .addEnergyHatch("Any layer 4 casing", 1) + .addMaintenanceHatch("Any layer 1 casing", 3) + .addInputBus("As specified on layer 1", 4, 5) + .addInputHatch("Any layer 1 casing", 3) + .addOutputBus("Replaces Input Bus on final slice", 4) + .addOtherStructurePart("Data Access Hatch", "Optional, next to controller", 2) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ConcreteBackfillerBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ConcreteBackfillerBase.java index 2341452ebe..8c1f28dd1c 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ConcreteBackfillerBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ConcreteBackfillerBase.java @@ -39,11 +39,11 @@ public abstract class GT_MetaTileEntity_ConcreteBackfillerBase extends GT_MetaTi .addStructureInfo(casings + " form the 3x1x3 Base") .addOtherStructurePart(casings, " 1x3x1 pillar above the center of the base (2 minimum total)") .addOtherStructurePart(getFrameMaterial().mName + " Frame Boxes", "Each pillar's side and 1x3x1 on top") - .addEnergyHatch(VN[getMinTier()] + "+, Any base casing") - .addMaintenanceHatch("Any base casing") - .addInputBus("Mining Pipes, optional, any base casing") - .addInputHatch("GT Concrete, any base casing") - .addOutputBus("Mining Pipes, optional, any base casing") + .addEnergyHatch(VN[getMinTier()] + "+, Any base casing", 1) + .addMaintenanceHatch("Any base casing", 1) + .addInputBus("Mining Pipes, optional, any base casing", 1) + .addInputHatch("GT Concrete, any base casing", 1) + .addOutputBus("Mining Pipes, optional, any base casing", 1) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DieselEngine.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DieselEngine.java index 567297648a..8dfc605d6b 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DieselEngine.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DieselEngine.java @@ -24,7 +24,7 @@ import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.defer; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_DIESEL_ENGINE; @@ -37,18 +37,23 @@ import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; public class GT_MetaTileEntity_DieselEngine extends GT_MetaTileEntity_EnhancedMultiBlockBase { private static final String STRUCTURE_PIECE_MAIN = "main"; - private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder() - .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ - {"---", "iii", "chc", "chc", "ccc", }, - {"---", "i~i", "hgh", "hgh", "cdc", }, - {"---", "iii", "chc", "chc", "ccc", }, - })) - .addElement('i', defer(t -> ofBlock(t.getIntakeBlock(), t.getIntakeMeta()))) - .addElement('c', defer(t -> ofBlock(t.getCasingBlock(), t.getCasingMeta()))) - .addElement('g', defer(t -> ofBlock(t.getGearboxBlock(), t.getGearboxMeta()))) - .addElement('d', defer(t -> ofHatchAdder(GT_MetaTileEntity_DieselEngine::addDynamoToMachineList, t.getCasingTextureIndex(), 0))) - .addElement('h', defer(t -> ofHatchAdderOptional(GT_MetaTileEntity_DieselEngine::addToMachineList, t.getCasingTextureIndex(), 0, t.getCasingBlock(), t.getCasingMeta()))) - .build(); + private static final ClassValue> STRUCTURE_DEFINITION = new ClassValue>() { + @Override + protected IStructureDefinition computeValue(Class type) { + return StructureDefinition.builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ + {"---", "iii", "chc", "chc", "ccc", }, + {"---", "i~i", "hgh", "hgh", "cdc", }, + {"---", "iii", "chc", "chc", "ccc", }, + })) + .addElement('i', lazy(t -> ofBlock(t.getIntakeBlock(), t.getIntakeMeta()))) + .addElement('c', lazy(t -> ofBlock(t.getCasingBlock(), t.getCasingMeta()))) + .addElement('g', lazy(t -> ofBlock(t.getGearboxBlock(), t.getGearboxMeta()))) + .addElement('d', lazy(t -> ofHatchAdder(GT_MetaTileEntity_DieselEngine::addDynamoToMachineList, t.getCasingTextureIndex(), 2))) + .addElement('h', lazy(t -> ofHatchAdderOptional(GT_MetaTileEntity_DieselEngine::addToMachineList, t.getCasingTextureIndex(), 1, t.getCasingBlock(), t.getCasingMeta()))) + .build(); + } + }; protected int fuelConsumption = 0; protected int fuelValue = 0; protected int fuelRemaining = 0; @@ -80,12 +85,12 @@ public class GT_MetaTileEntity_DieselEngine extends GT_MetaTileEntity_EnhancedMu .addOtherStructurePart("Titanium Gear Box Machine Casing", "Inner 2 blocks") .addOtherStructurePart("Engine Intake Machine Casing", "8x, ring around controller") .addStructureInfo("Engine Intake Casings must not be obstructed in front (only air blocks)") - .addDynamoHatch("Back center") - .addMaintenanceHatch("One of the casings next to a Gear Box") - .addMufflerHatch("Top middle back, above the rear Gear Box") - .addInputHatch("Diesel Fuel, next to a Gear Box") - .addInputHatch("Lubricant, next to a Gear Box") - .addInputHatch("Oxygen, optional, next to a Gear Box") + .addDynamoHatch("Back center", 2) + .addMaintenanceHatch("One of the casings next to a Gear Box", 1) + .addMufflerHatch("Top middle back, above the rear Gear Box", 1) + .addInputHatch("Diesel Fuel, next to a Gear Box", 1) + .addInputHatch("Lubricant, next to a Gear Box", 1) + .addInputHatch("Oxygen, optional, next to a Gear Box", 1) .toolTipFinisher("Gregtech"); return tt; } @@ -192,7 +197,7 @@ public class GT_MetaTileEntity_DieselEngine extends GT_MetaTileEntity_EnhancedMu @Override public IStructureDefinition getStructureDefinition() { - return STRUCTURE_DEFINITION; + return STRUCTURE_DEFINITION.get(getClass()); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java index b35d6e3c56..3710112c9b 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java @@ -53,14 +53,14 @@ public class GT_MetaTileEntity_DistillationTower extends GT_MetaTileEntity_Enhan onElementPass(GT_MetaTileEntity_DistillationTower::onCasingFound, ofBlock(GregTech_API.sBlockCasings4, 1)) )) .addElement('l', ofChain( - ofHatchAdder(GT_MetaTileEntity_DistillationTower::addEnergyInputToMachineList, CASING_INDEX, 1), + ofHatchAdder(GT_MetaTileEntity_DistillationTower::addEnergyInputToMachineList, CASING_INDEX, 2), ofHatchAdder(GT_MetaTileEntity_DistillationTower::addLayerOutputHatch, CASING_INDEX, 2), - ofHatchAdder(GT_MetaTileEntity_DistillationTower::addMaintenanceToMachineList, CASING_INDEX, 1), + ofHatchAdder(GT_MetaTileEntity_DistillationTower::addMaintenanceToMachineList, CASING_INDEX, 2), onElementPass(GT_MetaTileEntity_DistillationTower::onCasingFound, ofBlock(GregTech_API.sBlockCasings4, 1)) )) .addElement('c', ofChain( - onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GT_MetaTileEntity_DistillationTower::addOutputToMachineList, CASING_INDEX, 1)), - onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GT_MetaTileEntity_DistillationTower::addMaintenanceToMachineList, CASING_INDEX, 1)), + onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GT_MetaTileEntity_DistillationTower::addOutputToMachineList, CASING_INDEX, 3)), + onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GT_MetaTileEntity_DistillationTower::addMaintenanceToMachineList, CASING_INDEX, 3)), onElementPass(t -> t.onTopLayerFound(true), ofBlock(GregTech_API.sBlockCasings4, 1)), isAir() )) @@ -94,11 +94,11 @@ public class GT_MetaTileEntity_DistillationTower extends GT_MetaTileEntity_Enhan .beginVariableStructureBlock(3, 3, 3, 12, 3, 3, true) .addController("Front bottom") .addOtherStructurePart("Clean Stainless Steel Machine Casing", "7 x h - 5 (minimum)") - .addEnergyHatch("Any casing") - .addMaintenanceHatch("Any casing") - .addInputHatch("Any bottom layer casing") - .addOutputBus("Any bottom layer casing") - .addOutputHatch("2-11x Output Hatches (At least one per layer except bottom layer)") + .addEnergyHatch("Any casing", 1, 2) + .addMaintenanceHatch("Any casing", 1, 2, 3) + .addInputHatch("Any bottom layer casing", 1) + .addOutputBus("Any bottom layer casing", 1) + .addOutputHatch("2-11x Output Hatches (At least one per layer except bottom layer)", 2, 3) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java index 0ea04f1cfa..a610a502f9 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java @@ -30,7 +30,7 @@ import net.minecraftforge.common.util.ForgeDirection; import java.util.ArrayList; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.defer; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; @@ -48,27 +48,32 @@ public abstract class GT_MetaTileEntity_DrillerBase extends GT_MetaTileEntity_En private static final Block miningPipeBlock = GT_Utility.getBlockFromStack(miningPipe); private static final Block miningPipeTipBlock = GT_Utility.getBlockFromStack(miningPipeTip); protected static final String STRUCTURE_PIECE_MAIN = "main"; - protected static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder() - .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ - {" ", " f ", " "}, - {" ", " f ", " "}, - {" ", " f ", " "}, - {" f ", "fcf", " f "}, - {" f ", "fcf", " f "}, - {" f ", "fcf", " f "}, - {"b~b", "bbb", "bbb"}, - })) - .addElement('f', defer(t -> ofBlock(GregTech_API.sBlockMachines, t.frameMeta))) - .addElement('c', defer(t -> ofBlock(t.casingBlock, t.casingMeta))) - .addElement('b', defer(t -> ofChain( - ofBlock(t.casingBlock, t.casingMeta), - ofHatchAdder(GT_MetaTileEntity_DrillerBase::addMaintenanceToMachineList, t.casingTextureIndex, 1), - ofHatchAdder(GT_MetaTileEntity_DrillerBase::addInputToMachineList, t.casingTextureIndex, 1), - ofHatchAdder(GT_MetaTileEntity_DrillerBase::addOutputToMachineList, t.casingTextureIndex, 1), - ofHatchAdder(GT_MetaTileEntity_DrillerBase::addEnergyInputToMachineList, t.casingTextureIndex, 1), - ofHatchAdder(GT_MetaTileEntity_DrillerBase::addDataAccessToMachineList, t.casingTextureIndex, 1) - ))) - .build(); + protected static final ClassValue> STRUCTURE_DEFINITION = new ClassValue>() { + @Override + protected IStructureDefinition computeValue(Class type) { + return StructureDefinition.builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ + {" ", " f ", " "}, + {" ", " f ", " "}, + {" ", " f ", " "}, + {" f ", "fcf", " f "}, + {" f ", "fcf", " f "}, + {" f ", "fcf", " f "}, + {"b~b", "bbb", "bbb"}, + })) + .addElement('f', lazy(t -> ofBlock(GregTech_API.sBlockMachines, t.frameMeta))) + .addElement('c', lazy(t -> ofBlock(t.casingBlock, t.casingMeta))) + .addElement('b', lazy(t -> ofChain( + ofBlock(t.casingBlock, t.casingMeta), + ofHatchAdder(GT_MetaTileEntity_DrillerBase::addMaintenanceToMachineList, t.casingTextureIndex, 1), + ofHatchAdder(GT_MetaTileEntity_DrillerBase::addInputToMachineList, t.casingTextureIndex, 1), + ofHatchAdder(GT_MetaTileEntity_DrillerBase::addOutputToMachineList, t.casingTextureIndex, 1), + ofHatchAdder(GT_MetaTileEntity_DrillerBase::addEnergyInputToMachineList, t.casingTextureIndex, 1), + ofHatchAdder(GT_MetaTileEntity_DrillerBase::addDataAccessToMachineList, t.casingTextureIndex, 1) + ))) + .build(); + } + }; private Block casingBlock; private int casingMeta; @@ -355,7 +360,7 @@ public abstract class GT_MetaTileEntity_DrillerBase extends GT_MetaTileEntity_En @Override public final IStructureDefinition getStructureDefinition() { - return STRUCTURE_DEFINITION; + return STRUCTURE_DEFINITION.get(getClass()); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java index c7a3c3490d..d3c9e7176b 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java @@ -90,13 +90,13 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab .addController("Front bottom") .addCasingInfo("Heat Proof Machine Casing", 0) .addOtherStructurePart("Heating Coils", "Two middle Layers") - .addEnergyHatch("Any bottom layer casing") - .addMaintenanceHatch("Any bottom layer casing") - .addMufflerHatch("Top middle") - .addInputBus("Any bottom layer casing") - .addInputHatch("Any bottom layer casing") - .addOutputBus("Any bottom layer casing") - .addOutputHatch("Gasses, Any top layer casing") + .addEnergyHatch("Any bottom layer casing", 3) + .addMaintenanceHatch("Any bottom layer casing", 3) + .addMufflerHatch("Top middle", 2) + .addInputBus("Any bottom layer casing", 3) + .addInputHatch("Any bottom layer casing", 3) + .addOutputBus("Any bottom layer casing", 3) + .addOutputHatch("Gasses, Any top layer casing", 1) .addStructureInfo("Recovery amount scales with Muffler Hatch tier") .addOutputHatch("Platline fluids, Any bottom layer casing") .toolTipFinisher("Gregtech"); diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ExtremeDieselEngine.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ExtremeDieselEngine.java index f85f27935e..1878f25a5f 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ExtremeDieselEngine.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ExtremeDieselEngine.java @@ -51,12 +51,12 @@ public class GT_MetaTileEntity_ExtremeDieselEngine extends GT_MetaTileEntity_Die .addOtherStructurePart("Titanium Gear Box Machine Casing", "Inner 2 blocks") .addOtherStructurePart("Extreme Engine Intake Machine Casing", "8x, ring around controller") .addStructureInfo("Extreme Engine Intake Casings must not be obstructed in front (only air blocks)") - .addDynamoHatch("Back center") - .addMaintenanceHatch("One of the casings next to a Gear Box") - .addMufflerHatch("Top middle back, above the rear Gear Box") - .addInputHatch("HOG, next to a Gear Box") - .addInputHatch("Lubricant, next to a Gear Box") - .addInputHatch("Liquid Oxygen, optional, next to a Gear Box") + .addDynamoHatch("Back center", 2) + .addMaintenanceHatch("One of the casings next to a Gear Box", 1) + .addMufflerHatch("Top middle back, above the rear Gear Box", 1) + .addInputHatch("HOG, next to a Gear Box", 1) + .addInputHatch("Lubricant, next to a Gear Box", 1) + .addInputHatch("Liquid Oxygen, optional, next to a Gear Box", 1) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java index bf2aeadcf8..88604979d2 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java @@ -29,7 +29,7 @@ import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.defer; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS; @@ -39,66 +39,71 @@ import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; public abstract class GT_MetaTileEntity_FusionComputer extends GT_MetaTileEntity_EnhancedMultiBlockBase { public static final String STRUCTURE_PIECE_MAIN = "main"; - private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder() - .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ - { - " ", - " ihi ", - " hh hh ", - " h h ", - " h h ", - " h h ", - " i i ", - " h h ", - " i i ", - " h h ", - " h h ", - " h h ", - " hh hh ", - " ihi ", - " ", - }, - { - " xhx ", - " hhccchh ", - " eccxhxcce ", - " eceh hece ", - " hce ech ", - " hch hch ", - "xcx xcx", - "hch hch", - "xcx xcx", - " hch hch ", - " hce ech ", - " eceh hece ", - " eccx~xcce ", - " hhccchh ", - " xhx ", - }, - { - " ", - " ihi ", - " hh hh ", - " h h ", - " h h ", - " h h ", - " i i ", - " h h ", - " i i ", - " h h ", - " h h ", - " h h ", - " hh hh ", - " ihi ", - " ", - } - })) - .addElement('c', defer(t -> ofBlock(t.getFusionCoil(), t.getFusionCoilMeta()))) - .addElement('h', defer(t -> ofBlock(t.getCasing(), t.getCasingMeta()))) - .addElement('i', defer(t -> ofHatchAdderOptional(GT_MetaTileEntity_FusionComputer::addInjector, 53, 1, t.getCasing(), t.getCasingMeta()))) - .addElement('e', defer(t -> ofHatchAdderOptional(GT_MetaTileEntity_FusionComputer::addEnergyInjector, 53, 1, t.getCasing(), t.getCasingMeta()))) - .addElement('x', defer(t -> ofHatchAdderOptional(GT_MetaTileEntity_FusionComputer::addExtractor, 53, 1, t.getCasing(), t.getCasingMeta()))) - .build(); + private static final ClassValue> STRUCTURE_DEFINITION = new ClassValue>() { + @Override + protected IStructureDefinition computeValue(Class type) { + return StructureDefinition.builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ + { + " ", + " ihi ", + " hh hh ", + " h h ", + " h h ", + " h h ", + " i i ", + " h h ", + " i i ", + " h h ", + " h h ", + " h h ", + " hh hh ", + " ihi ", + " ", + }, + { + " xhx ", + " hhccchh ", + " eccxhxcce ", + " eceh hece ", + " hce ech ", + " hch hch ", + "xcx xcx", + "hch hch", + "xcx xcx", + " hch hch ", + " hce ech ", + " eceh hece ", + " eccx~xcce ", + " hhccchh ", + " xhx ", + }, + { + " ", + " ihi ", + " hh hh ", + " h h ", + " h h ", + " h h ", + " i i ", + " h h ", + " i i ", + " h h ", + " h h ", + " h h ", + " hh hh ", + " ihi ", + " ", + } + })) + .addElement('c', lazy(t -> ofBlock(t.getFusionCoil(), t.getFusionCoilMeta()))) + .addElement('h', lazy(t -> ofBlock(t.getCasing(), t.getCasingMeta()))) + .addElement('i', lazy(t -> ofHatchAdderOptional(GT_MetaTileEntity_FusionComputer::addInjector, 53, 1, t.getCasing(), t.getCasingMeta()))) + .addElement('e', lazy(t -> ofHatchAdderOptional(GT_MetaTileEntity_FusionComputer::addEnergyInjector, 53, 2, t.getCasing(), t.getCasingMeta()))) + .addElement('x', lazy(t -> ofHatchAdderOptional(GT_MetaTileEntity_FusionComputer::addExtractor, 53, 3, t.getCasing(), t.getCasingMeta()))) + .build(); + } + }; public GT_Recipe mLastRecipe; public int mEUStore; @@ -154,7 +159,7 @@ public abstract class GT_MetaTileEntity_FusionComputer extends GT_MetaTileEntity @Override public IStructureDefinition getStructureDefinition() { - return STRUCTURE_DEFINITION; + return STRUCTURE_DEFINITION.get(getClass()); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer1.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer1.java index 2901a9e4f1..dd942d2635 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer1.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer1.java @@ -75,9 +75,9 @@ public class GT_MetaTileEntity_FusionComputer1 extends GT_MetaTileEntity_FusionC .addCasingInfo("LuV Machine Casing", 79) .addStructureInfo("Cover the coils with casing") .addOtherStructurePart("Superconducting Coil Block", "Center part of the ring") - .addEnergyHatch("1-16, Specified casings") - .addInputHatch("2-16, Specified casings") - .addOutputHatch("1-16, Specified casings") + .addEnergyHatch("1-16, Specified casings", 2) + .addInputHatch("2-16, Specified casings", 1) + .addOutputHatch("1-16, Specified casings", 3) .addStructureInfo("ALL Hatches must be LuV or better") .toolTipFinisher("Gregtech"); return tt; diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer2.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer2.java index 6cefdc6812..de9d863529 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer2.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer2.java @@ -75,9 +75,9 @@ public class GT_MetaTileEntity_FusionComputer2 extends GT_MetaTileEntity_FusionC .addCasingInfo("Fusion Machine Casing", 79) .addStructureInfo("Cover the coils with casing") .addOtherStructurePart("Fusion Coil Block", "Center part of the ring") - .addEnergyHatch("1-16, Specified casings") - .addInputHatch("2-16, Specified casings") - .addOutputHatch("1-16, Specified casings") + .addEnergyHatch("1-16, Specified casings", 2) + .addInputHatch("2-16, Specified casings", 1) + .addOutputHatch("1-16, Specified casings", 3) .addStructureInfo("ALL Hatches must be ZPM or better") .toolTipFinisher("Gregtech"); return tt; diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer3.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer3.java index b879c7923b..4e5c6c3cad 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer3.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer3.java @@ -75,9 +75,9 @@ public class GT_MetaTileEntity_FusionComputer3 extends GT_MetaTileEntity_FusionC .addCasingInfo("Fusion Machine Casing Mk II", 79) .addStructureInfo("Cover the coils with casing") .addOtherStructurePart("Fusion Coil Block", "Center part of the ring") - .addEnergyHatch("1-16, Specified casings") - .addInputHatch("2-16, Specified casings") - .addOutputHatch("1-16, Specified casings") + .addEnergyHatch("1-16, Specified casings", 2) + .addInputHatch("2-16, Specified casings", 1) + .addOutputHatch("1-16, Specified casings", 3) .addStructureInfo("ALL Hatches must be UV or better") .toolTipFinisher("Gregtech"); return tt; diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_HeatExchanger.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_HeatExchanger.java index 392726e13a..e8beb270e0 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_HeatExchanger.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_HeatExchanger.java @@ -52,7 +52,6 @@ public class GT_MetaTileEntity_HeatExchanger extends GT_MetaTileEntity_EnhancedM ofHatchAdder(GT_MetaTileEntity_HeatExchanger::addInputToMachineList, CASING_INDEX, 1), ofHatchAdder(GT_MetaTileEntity_HeatExchanger::addOutputToMachineList, CASING_INDEX, 1), ofHatchAdder(GT_MetaTileEntity_HeatExchanger::addMaintenanceToMachineList, CASING_INDEX, 1), - ofHatchAdder(GT_MetaTileEntity_HeatExchanger::addEnergyInputToMachineList, CASING_INDEX, 1), onElementPass(GT_MetaTileEntity_HeatExchanger::onCasingAdded, ofBlock(GregTech_API.sBlockCasings4, (byte) 2)) )) .build(); @@ -87,11 +86,11 @@ public class GT_MetaTileEntity_HeatExchanger extends GT_MetaTileEntity_EnhancedM .addController("Front bottom") .addCasingInfo("Stable Titanium Machine Casing", 20) .addOtherStructurePart("Titanium Pipe Casing", "Center 2 blocks") - .addMaintenanceHatch("Any casing") - .addInputHatch("Hot fluid, bottom center") - .addInputHatch("Distilled water, any casing") - .addOutputHatch("Cold fluid, top center") - .addOutputHatch("Steam/SH Steam, any casing") + .addMaintenanceHatch("Any casing", 1) + .addInputHatch("Hot fluid, bottom center", 2) + .addInputHatch("Distilled water, any casing", 1) + .addOutputHatch("Cold fluid, top center", 3) + .addOutputHatch("Steam/SH Steam, any casing", 1) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ImplosionCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ImplosionCompressor.java index 41b40f56fa..17417a09c8 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ImplosionCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ImplosionCompressor.java @@ -51,11 +51,11 @@ public class GT_MetaTileEntity_ImplosionCompressor extends GT_MetaTileEntity_Cub .addController("Front center") .addCasingInfo("Solid Steel Machine Casing", 16) .addStructureInfo("Casings can be replaced with Explosion Warning Signs") - .addEnergyHatch("Any casing") - .addMaintenanceHatch("Any casing") - .addMufflerHatch("Any casing") - .addInputBus("Any casing") - .addOutputBus("Any casing") + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addMufflerHatch("Any casing", 1) + .addInputBus("Any casing", 1) + .addOutputBus("Any casing", 1) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeBoiler.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeBoiler.java index 7f409f38f4..8565ae8774 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeBoiler.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeBoiler.java @@ -26,7 +26,7 @@ import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.defer; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; @@ -40,26 +40,31 @@ import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; public abstract class GT_MetaTileEntity_LargeBoiler extends GT_MetaTileEntity_EnhancedMultiBlockBase { private static final String STRUCTURE_PIECE_MAIN = "main"; - private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder() - .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ - {"ccc", "ccc", "ccc"}, - {"ccc", "cPc", "ccc"}, - {"ccc", "cPc", "ccc"}, - {"ccc", "cPc", "ccc"}, - {"f~f", "fff", "fff"}, - })) - .addElement('P', defer(t -> ofBlock(t.getPipeBlock(), t.getPipeMeta()))) - .addElement('c', defer(t -> ofChain( - ofHatchAdder(GT_MetaTileEntity_LargeBoiler::addOutputToMachineList, t.getCasingTextureIndex(), 2), - onElementPass(GT_MetaTileEntity_LargeBoiler::onCasingAdded, ofBlock(t.getCasingBlock(), t.getCasingMeta())) - ))) - .addElement('f', defer(t -> ofChain( - ofHatchAdder(GT_MetaTileEntity_LargeBoiler::addMaintenanceToMachineList, t.getCasingTextureIndex(), 1), - ofHatchAdder(GT_MetaTileEntity_LargeBoiler::addInputToMachineList, t.getCasingTextureIndex(), 1), - ofHatchAdder(GT_MetaTileEntity_LargeBoiler::addMufflerToMachineList, t.getCasingTextureIndex(), 1), - onElementPass(GT_MetaTileEntity_LargeBoiler::onFireboxAdded, ofBlock(t.getCasingBlock(), t.getCasingMeta())) - ))) - .build(); + private static final ClassValue> STRUCTURE_DEFINITION =new ClassValue>() { + @Override + protected IStructureDefinition computeValue(Class type) { + return StructureDefinition.builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ + {"ccc", "ccc", "ccc"}, + {"ccc", "cPc", "ccc"}, + {"ccc", "cPc", "ccc"}, + {"ccc", "cPc", "ccc"}, + {"f~f", "fff", "fff"}, + })) + .addElement('P', lazy(t -> ofBlock(t.getPipeBlock(), t.getPipeMeta()))) + .addElement('c', lazy(t -> ofChain( + ofHatchAdder(GT_MetaTileEntity_LargeBoiler::addOutputToMachineList, t.getCasingTextureIndex(), 2), + onElementPass(GT_MetaTileEntity_LargeBoiler::onCasingAdded, ofBlock(t.getCasingBlock(), t.getCasingMeta())) + ))) + .addElement('f', lazy(t -> ofChain( + ofHatchAdder(GT_MetaTileEntity_LargeBoiler::addMaintenanceToMachineList, t.getCasingTextureIndex(), 1), + ofHatchAdder(GT_MetaTileEntity_LargeBoiler::addInputToMachineList, t.getCasingTextureIndex(), 1), + ofHatchAdder(GT_MetaTileEntity_LargeBoiler::addMufflerToMachineList, t.getCasingTextureIndex(), 1), + onElementPass(GT_MetaTileEntity_LargeBoiler::onFireboxAdded, ofBlock(t.getCasingBlock(), t.getCasingMeta())) + ))) + .build(); + } + }; private boolean firstRun = true; private int mSuperEfficencyIncrease = 0; private int integratedCircuitConfig = 0; //Steam output is reduced by 1000L per config @@ -92,13 +97,13 @@ public abstract class GT_MetaTileEntity_LargeBoiler extends GT_MetaTileEntity_En .addCasingInfo(getCasingMaterial() + " " + getCasingBlockType() + " Casing", 24)//? .addOtherStructurePart(getCasingMaterial() + " Fire Boxes", "Bottom layer, 3 minimum") .addOtherStructurePart(getCasingMaterial() + " Pipe Casing Blocks", "Inner 3 blocks") - .addMaintenanceHatch("Any firebox") - .addMufflerHatch("Any firebox") - .addInputBus("Solid fuel, Any firebox") - .addInputHatch("Liquid fuel, Any firebox") + .addMaintenanceHatch("Any firebox", 1) + .addMufflerHatch("Any firebox", 1) + .addInputBus("Solid fuel, Any firebox", 1) + .addInputHatch("Liquid fuel, Any firebox", 1) .addStructureInfo("You can use either, or both") - .addInputHatch("Water, Any firebox") - .addOutputHatch("Steam, any casing") + .addInputHatch("Water, Any firebox", 1) + .addOutputHatch("Steam, any casing", 2) .toolTipFinisher("Gregtech"); return tt; } @@ -271,7 +276,7 @@ public abstract class GT_MetaTileEntity_LargeBoiler extends GT_MetaTileEntity_En @Override public IStructureDefinition getStructureDefinition() { - return STRUCTURE_DEFINITION; + return STRUCTURE_DEFINITION.get(getClass()); } private void onCasingAdded() { diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java index 072f54e4af..63b536fc72 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java @@ -47,10 +47,10 @@ public class GT_MetaTileEntity_LargeChemicalReactor extends GT_MetaTileEntity_En onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCasingAdded, ofBlock(GregTech_API.sBlockCasings8, 0)) )) .addElement('x', ofChain( - ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addInputToMachineList, CASING_INDEX, 1), - ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addOutputToMachineList, CASING_INDEX, 1), - ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addMaintenanceToMachineList, CASING_INDEX, 1), - ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addEnergyInputToMachineList, CASING_INDEX, 1), + ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addInputToMachineList, CASING_INDEX, 2), + ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addOutputToMachineList, CASING_INDEX, 2), + ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addMaintenanceToMachineList, CASING_INDEX, 2), + ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addEnergyInputToMachineList, CASING_INDEX, 2), onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 0)), onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCasingAdded, ofBlock(GregTech_API.sBlockCasings8, 0)) )) @@ -84,13 +84,13 @@ public class GT_MetaTileEntity_LargeChemicalReactor extends GT_MetaTileEntity_En .addController("Front center") .addCasingInfo("Chemically Inert Machine Casing", 8) .addOtherStructurePart("PTFE Pipe Machine Casing", "Center") - .addOtherStructurePart("Cupronickel Coil Block", "Adjacent to the PTFE Pipe Machine Casing") - .addEnergyHatch("Any casing") - .addMaintenanceHatch("Any casing") - .addInputBus("Any casing") - .addInputHatch("Any casing") - .addOutputBus("Any casing") - .addOutputHatch("Any casing") + .addOtherStructurePart("Cupronickel Coil Block", "Adjacent to the PTFE Pipe Machine Casing", 1) + .addEnergyHatch("Any casing", 1, 2) + .addMaintenanceHatch("Any casing", 1, 2) + .addInputBus("Any casing", 1, 2) + .addInputHatch("Any casing", 1, 2) + .addOutputBus("Any casing", 1, 2) + .addOutputHatch("Any casing", 1, 2) .addStructureInfo("You can have multiple hatches/busses") .toolTipFinisher("Gregtech"); return tt; diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java index fd3117e451..f0a5abbe62 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java @@ -22,7 +22,7 @@ import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.defer; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; @@ -30,22 +30,27 @@ import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; public abstract class GT_MetaTileEntity_LargeTurbine extends GT_MetaTileEntity_EnhancedMultiBlockBase { private static final String STRUCTURE_PIECE_MAIN = "main"; - private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder() - .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ - {" ", "xxxxx", "xxxxx", "xxxxx", "xxxxx",}, - {" --- ", "xcccx", "xchcx", "xchcx", "xcccx",}, - {" --- ", "xc~cx", "xh-hx", "xh-hx", "xcdcx",}, - {" --- ", "xcccx", "xchcx", "xchcx", "xcccx",}, - {" ", "xxxxx", "xxxxx", "xxxxx", "xxxxx",}, - })) - .addElement('c', defer(t -> ofBlock(t.getCasingBlock(), t.getCasingMeta()))) - .addElement('d', defer(t -> ofHatchAdder(GT_MetaTileEntity_LargeTurbine::addDynamoToMachineList, t.getCasingTextureIndex(), 0))) - .addElement('h', defer(t -> ofHatchAdderOptional(GT_MetaTileEntity_LargeTurbine::addToMachineList, t.getCasingTextureIndex(), 0, t.getCasingBlock(), t.getCasingMeta()))) - .addElement('x', (IStructureElementCheckOnly) (aContext, aWorld, aX, aY, aZ) -> { - TileEntity tTile = aWorld.getTileEntity(aX, aY, aZ); - return !(tTile instanceof IGregTechTileEntity) || !(((IGregTechTileEntity) tTile).getMetaTileEntity() instanceof GT_MetaTileEntity_LargeTurbine); - }) - .build(); + private static final ClassValue> STRUCTURE_DEFINITION = new ClassValue>() { + @Override + protected IStructureDefinition computeValue(Class type) { + return StructureDefinition.builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ + {" ", "xxxxx", "xxxxx", "xxxxx", "xxxxx",}, + {" --- ", "xcccx", "xchcx", "xchcx", "xcccx",}, + {" --- ", "xc~cx", "xh-hx", "xh-hx", "xcdcx",}, + {" --- ", "xcccx", "xchcx", "xchcx", "xcccx",}, + {" ", "xxxxx", "xxxxx", "xxxxx", "xxxxx",}, + })) + .addElement('c', lazy(t -> ofBlock(t.getCasingBlock(), t.getCasingMeta()))) + .addElement('d', lazy(t -> ofHatchAdder(GT_MetaTileEntity_LargeTurbine::addDynamoToMachineList, t.getCasingTextureIndex(), 1))) + .addElement('h', lazy(t -> ofHatchAdderOptional(GT_MetaTileEntity_LargeTurbine::addToMachineList, t.getCasingTextureIndex(), 2, t.getCasingBlock(), t.getCasingMeta()))) + .addElement('x', (IStructureElementCheckOnly) (aContext, aWorld, aX, aY, aZ) -> { + TileEntity tTile = aWorld.getTileEntity(aX, aY, aZ); + return !(tTile instanceof IGregTechTileEntity) || !(((IGregTechTileEntity) tTile).getMetaTileEntity() instanceof GT_MetaTileEntity_LargeTurbine); + }) + .build(); + } + }; protected int baseEff = 0; protected int optFlow = 0; @@ -74,7 +79,7 @@ public abstract class GT_MetaTileEntity_LargeTurbine extends GT_MetaTileEntity_E @Override public IStructureDefinition getStructureDefinition() { - return STRUCTURE_DEFINITION; + return STRUCTURE_DEFINITION.get(getClass()); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Gas.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Gas.java index 27e4bf7084..20f795572e 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Gas.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Gas.java @@ -46,10 +46,10 @@ public class GT_MetaTileEntity_LargeTurbine_Gas extends GT_MetaTileEntity_LargeT .beginStructureBlock(3, 3, 4, true) .addController("Front center") .addCasingInfo("Stainless Steel Turbine Casing", 24) - .addDynamoHatch("Back center") - .addMaintenanceHatch("Side centered") - .addMufflerHatch("Side centered") - .addInputHatch("Gas Fuel, Side centered") + .addDynamoHatch("Back center", 1) + .addMaintenanceHatch("Side centered", 2) + .addMufflerHatch("Side centered", 2) + .addInputHatch("Gas Fuel, Side centered", 2) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_HPSteam.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_HPSteam.java index 0d22271a34..2c803712f1 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_HPSteam.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_HPSteam.java @@ -54,10 +54,10 @@ public class GT_MetaTileEntity_LargeTurbine_HPSteam extends GT_MetaTileEntity_La .beginStructureBlock(3, 3, 4, true) .addController("Front center") .addCasingInfo("Titanium Turbine Casing", 24) - .addDynamoHatch("Back center") - .addMaintenanceHatch("Side centered") - .addInputHatch("Superheated Steam, Side centered") - .addOutputHatch("Steam, Side centered") + .addDynamoHatch("Back center", 1) + .addMaintenanceHatch("Side centered", 2) + .addInputHatch("Superheated Steam, Side centered", 2) + .addOutputHatch("Steam, Side centered", 2) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Plasma.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Plasma.java index d1bf1e7c0b..c34f190242 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Plasma.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Plasma.java @@ -53,10 +53,10 @@ public class GT_MetaTileEntity_LargeTurbine_Plasma extends GT_MetaTileEntity_Lar .beginStructureBlock(3, 3, 4, true) .addController("Front center") .addCasingInfo("Tungstensteel Turbine Casing", 24) - .addDynamoHatch("Back center") - .addMaintenanceHatch("Side centered") - .addInputHatch("Plasma Fluid, Side centered") - .addOutputHatch("Molten Fluid, optional, Side centered") + .addDynamoHatch("Back center", 1) + .addMaintenanceHatch("Side centered", 2) + .addInputHatch("Plasma Fluid, Side centered", 2) + .addOutputHatch("Molten Fluid, optional, Side centered", 2) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Steam.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Steam.java index 8990ad3324..356dda9183 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Steam.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine_Steam.java @@ -57,10 +57,10 @@ public class GT_MetaTileEntity_LargeTurbine_Steam extends GT_MetaTileEntity_Larg .beginStructureBlock(3, 3, 4, true) .addController("Front center") .addCasingInfo("Turbine Casing", 24) - .addDynamoHatch("Back center") - .addMaintenanceHatch("Side centered") - .addInputHatch("Steam, Side centered") - .addOutputHatch("Distilled Water, Side centered") + .addDynamoHatch("Back center", 1) + .addMaintenanceHatch("Side centered", 2) + .addInputHatch("Steam, Side centered", 2) + .addOutputHatch("Distilled Water, Side centered", 2) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java index edfce02aad..907de38f6b 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java @@ -51,7 +51,7 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu .addElement('c', ofBlock(GregTech_API.sBlockCasings1, CASING_INDEX)) .addElement('m', ofHatchAdder(GT_MetaTileEntity_MultiFurnace::addMufflerToMachineList, CASING_INDEX, 2)) .addElement('C', GT_StructureUtility.ofCoil(GT_MetaTileEntity_MultiFurnace::setCoilLevel, GT_MetaTileEntity_MultiFurnace::getCoilLevel)) - .addElement('b', ofHatchAdderOptional(GT_MetaTileEntity_MultiFurnace::addBottomHatch, CASING_INDEX, 3, GregTech_API.sBlockCasings1, CASING_INDEX)) + .addElement('b', ofHatchAdderOptional(GT_MetaTileEntity_MultiFurnace::addBottomHatch, CASING_INDEX, 1, GregTech_API.sBlockCasings1, CASING_INDEX)) .build(); public GT_MetaTileEntity_MultiFurnace(int aID, String aName, String aNameRegional) { @@ -80,11 +80,11 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu .addController("Front bottom") .addCasingInfo("Heat Proof Machine Casing", 8) .addOtherStructurePart("Heating Coils", "Middle layer") - .addEnergyHatch("Any bottom casing") - .addMaintenanceHatch("Any bottom casing") - .addMufflerHatch("Top Middle") - .addInputBus("Any bottom casing") - .addOutputBus("Any bottom casing") + .addEnergyHatch("Any bottom casing", 1) + .addMaintenanceHatch("Any bottom casing", 1) + .addMufflerHatch("Top Middle", 2) + .addInputBus("Any bottom casing", 1) + .addOutputBus("Any bottom casing", 1) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java index 8a257db8ee..c8dbe2321a 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java @@ -52,7 +52,7 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_EnhancedMult onElementPass(GT_MetaTileEntity_OilCracker::onCasingAdded, ofBlock(GregTech_API.sBlockCasings4, 1)) )) .addElement('r', ofChain( - ofHatchAdder(GT_MetaTileEntity_OilCracker::addRightHatchToMachineList, CASING_INDEX, 2), + ofHatchAdder(GT_MetaTileEntity_OilCracker::addRightHatchToMachineList, CASING_INDEX, 3), onElementPass(GT_MetaTileEntity_OilCracker::onCasingAdded, ofBlock(GregTech_API.sBlockCasings4, 1)) )) .addElement('m', ofChain( @@ -91,12 +91,13 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_EnhancedMult .addCasingInfo("Clean Stainless Steel Machine Casing", 18) .addOtherStructurePart("2 Rings of 8 Coils", "Each side of the controller") .addInfo("Gets 5% EU/t reduction per coil tier") - .addEnergyHatch("Any casing") - .addMaintenanceHatch("Any casing") - .addInputHatch("Steam/Hydrogen ONLY, Any middle ring casing") - .addInputHatch("Any left/right side casing") - .addOutputHatch("Any left/right side casing") + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addInputHatch("Steam/Hydrogen ONLY, Any middle ring casing", 1) + .addInputHatch("Any left/right side casing",2, 3) + .addOutputHatch("Any right/left side casing", 2, 3) .addStructureInfo("Input/Output Hatches must be on opposite sides!") + .addStructureHint("GT5U.cracker.io_side") .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrillBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrillBase.java index 554e5dfd63..76231980ec 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrillBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrillBase.java @@ -92,10 +92,10 @@ public abstract class GT_MetaTileEntity_OilDrillBase extends GT_MetaTileEntity_D .addStructureInfo(casings + " form the 3x1x3 Base") .addOtherStructurePart(casings, " 1x3x1 pillar above the center of the base (2 minimum total)") .addOtherStructurePart(getFrameMaterial().mName + " Frame Boxes", "Each pillar's side and 1x3x1 on top") - .addEnergyHatch(VN[getMinTier()] + "+, Any base casing") - .addMaintenanceHatch("Any base casing") - .addInputBus("Mining Pipes or Circuits, optional, any base casing") - .addOutputHatch("Any base casing") + .addEnergyHatch(VN[getMinTier()] + "+, Any base casing", 1) + .addMaintenanceHatch("Any base casing", 1) + .addInputBus("Mining Pipes or Circuits, optional, any base casing", 1) + .addOutputHatch("Any base casing", 1) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java index 5b4444cec3..b168e44c41 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java @@ -350,11 +350,11 @@ public abstract class GT_MetaTileEntity_OreDrillingPlantBase extends GT_MetaTile .addStructureInfo(casings + " form the 3x1x3 Base") .addOtherStructurePart(casings, " 1x3x1 pillar above the center of the base (2 minimum total)") .addOtherStructurePart(getFrameMaterial().mName + " Frame Boxes", "Each pillar's side and 1x3x1 on top") - .addEnergyHatch(VN[getMinTier()] + "+, Any base casing") - .addMaintenanceHatch("Any base casing") - .addInputBus("Mining Pipes, optional, any base casing") - .addInputHatch("Drilling Fluid, any base casing") - .addOutputBus("Any base casing") + .addEnergyHatch(VN[getMinTier()] + "+, Any base casing", 1) + .addMaintenanceHatch("Any base casing", 1) + .addInputBus("Mining Pipes, optional, any base casing", 1) + .addInputHatch("Drilling Fluid, any base casing", 1) + .addOutputBus("Any base casing", 1) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java index 0a46c47f7c..ea56266b41 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java @@ -76,12 +76,12 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_CubicMu .beginStructureBlock(3, 3, 3, true) .addController("Front center") .addCasingInfo("Robust Tungstensteel Machine Casing", 14) - .addEnergyHatch("Any casing") - .addMaintenanceHatch("Any casing") - .addInputBus("Any casing") - .addInputHatch("Any casing") - .addOutputBus("Any casing") - .addOutputHatch("Any casing") + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addInputBus("Any casing", 1) + .addInputHatch("Any casing", 1) + .addOutputBus("Any casing", 1) + .addOutputHatch("Any casing", 1) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java index 7312e0d992..48da2c5dce 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java @@ -63,8 +63,8 @@ public class GT_MetaTileEntity_PyrolyseOven extends GT_MetaTileEntity_EnhancedMu onElementPass(GT_MetaTileEntity_PyrolyseOven::onCasingAdded, tCasingElement) )) .addElement('t', ofChain( - ofHatchAdder(GT_MetaTileEntity_PyrolyseOven::addInputToMachineList, CASING_INDEX, 1), - ofHatchAdder(GT_MetaTileEntity_PyrolyseOven::addMufflerToMachineList, CASING_INDEX, 1), + ofHatchAdder(GT_MetaTileEntity_PyrolyseOven::addInputToMachineList, CASING_INDEX, 2), + ofHatchAdder(GT_MetaTileEntity_PyrolyseOven::addMufflerToMachineList, CASING_INDEX, 2), onElementPass(GT_MetaTileEntity_PyrolyseOven::onCasingAdded, tCasingElement) )) .build(); @@ -95,13 +95,13 @@ public class GT_MetaTileEntity_PyrolyseOven extends GT_MetaTileEntity_EnhancedMu .addController("Front center") .addCasingInfo("Pyrolyse Oven Casing", 60) .addOtherStructurePart("Heating Coils", "Center 3x1x3 of the bottom layer") - .addEnergyHatch("Any bottom layer casing") - .addMaintenanceHatch("Any bottom layer casing") - .addMufflerHatch("Center 3x1x3 area in top layer") - .addInputBus("Center 3x1x3 area in top layer") - .addInputHatch("Center 3x1x3 area in top layer") - .addOutputBus("Any bottom layer casing") - .addOutputHatch("Any bottom layer casing") + .addEnergyHatch("Any bottom layer casing", 1) + .addMaintenanceHatch("Any bottom layer casing", 1) + .addMufflerHatch("Center 3x1x3 area in top layer", 2) + .addInputBus("Center 3x1x3 area in top layer", 2) + .addInputHatch("Center 3x1x3 area in top layer", 2) + .addOutputBus("Any bottom layer casing", 1) + .addOutputHatch("Any bottom layer casing", 1) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java index bef433e626..b7f24f7e7a 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java @@ -47,10 +47,10 @@ public class GT_MetaTileEntity_VacuumFreezer extends GT_MetaTileEntity_CubicMult .beginStructureBlock(3, 3, 3, true) .addController("Front center") .addCasingInfo("Frost Proof Machine Casing", 16) - .addEnergyHatch("Any casing") - .addMaintenanceHatch("Any casing") - .addInputBus("Any casing") - .addOutputBus("Any casing") + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addInputBus("Any casing", 1) + .addOutputBus("Any casing", 1) .toolTipFinisher("Gregtech"); return tt; } diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang index b0d0018312..ce60b8d70e 100644 --- a/src/main/resources/assets/gregtech/lang/en_US.lang +++ b/src/main/resources/assets/gregtech/lang/en_US.lang @@ -18,7 +18,27 @@ GT5U.MBTT.Causes=Causes GT5U.MBTT.PPS=pollution per second GT5U.MBTT.Hold=Hold GT5U.MBTT.Display=to display structure guidelines +GT5U.MBTT.StructureHint=Some blocks have multiple candidates or can use any tier GT5U.MBTT.Mod=Added by +GT5U.MBTT.Air=Mandatory Air +GT5U.MBTT.Dots.0=No Dot +GT5U.MBTT.Dots.1=Dot 1 +GT5U.MBTT.Dots.2=Dot 2 +GT5U.MBTT.Dots.3=Dot 3 +GT5U.MBTT.Dots.4=Dot 4 +GT5U.MBTT.Dots.5=Dot 5 +GT5U.MBTT.Dots.6=Dot 6 +GT5U.MBTT.Dots.7=Dot 7 +GT5U.MBTT.Dots.8=Dot 8 +GT5U.MBTT.Dots.9=Dot 9 +GT5U.MBTT.Dots.10=Dot 10 +GT5U.MBTT.Dots.11=Dot 11 +GT5U.MBTT.Dots.12=Dot 12 +GT5U.MBTT.Dots.13=Dot 13 +GT5U.MBTT.Dots.14=Dot 14 +GT5U.MBTT.Dots.15=Dot 15 + +GT5U.cracker.io_side=Input/Output Hatches must be on opposite sides! GT5U.turbine.running.true=Turbine running GT5U.turbine.running.false=Turbine stopped -- cgit From 5a01df12f0a87fd7d14fe9517247395582472264 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Wed, 21 Jul 2021 19:05:49 +0800 Subject: Fix coil hint block usage Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/api/util/GT_StructureUtility.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_StructureUtility.java b/src/main/java/gregtech/api/util/GT_StructureUtility.java index dc916f02e3..2d15f568ab 100644 --- a/src/main/java/gregtech/api/util/GT_StructureUtility.java +++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java @@ -125,7 +125,7 @@ public class GT_StructureUtility { private int getMeta(ItemStack trigger) { // -4 to skip unimplemented tiers - return GT_Block_Casings5.getMetaFromCoilHeat(HeatingCoilLevel.getFromTier((byte) Math.min(HeatingCoilLevel.getMaxTier() - 4, Math.max(0, trigger.stackSize)))); + return GT_Block_Casings5.getMetaFromCoilHeat(HeatingCoilLevel.getFromTier((byte) Math.min(HeatingCoilLevel.getMaxTier() - 4, Math.max(0, trigger.stackSize - 1)))); } @Override -- cgit From 9267016bf3a3e0ae90c89f3bfc61058f1275207d Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Wed, 21 Jul 2021 22:41:53 +0800 Subject: Use upstream existing localization instead of creating our own Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../gregtech/api/util/GT_Multiblock_Tooltip_Builder.java | 5 +++-- src/main/resources/assets/gregtech/lang/en_US.lang | 16 ---------------- 2 files changed, 3 insertions(+), 18 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java index 84d4bbbd48..9afb9e58c1 100644 --- a/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java +++ b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java @@ -2,6 +2,7 @@ package gregtech.api.util; import com.google.common.collect.Multimaps; import com.google.common.collect.SetMultimap; +import com.gtnewhorizon.structurelib.StructureLibAPI; import gregtech.api.enums.Materials; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; @@ -72,14 +73,14 @@ public class GT_Multiblock_Tooltip_Builder { private static final String TT_structurehint = StatCollector.translateToLocal("GT5U.MBTT.StructureHint"); private static final String TT_mod = StatCollector.translateToLocal("GT5U.MBTT.Mod"); private static final String TT_air = StatCollector.translateToLocal("GT5U.MBTT.Air"); - private static final String[] TT_dots = IntStream.range(0, 16).mapToObj(i -> StatCollector.translateToLocal("GT5U.MBTT.Dots." + i)).toArray(String[]::new); + private static final String[] TT_dots = IntStream.range(0, 16).mapToObj(i -> StatCollector.translateToLocal("structurelib.blockhint." + i + ".name")).toArray(String[]::new); public GT_Multiblock_Tooltip_Builder() { iLines = new LinkedList<>(); sLines = new LinkedList<>(); hLines = new LinkedList<>(); hBlocks = Multimaps.newSetMultimap(new HashMap<>(), HashSet::new); - hBlocks.put(0, TT_air); + hBlocks.put(StructureLibAPI.HINT_BLOCK_META_AIR, TT_air); } /** diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang index ce60b8d70e..e173f9cfea 100644 --- a/src/main/resources/assets/gregtech/lang/en_US.lang +++ b/src/main/resources/assets/gregtech/lang/en_US.lang @@ -21,22 +21,6 @@ GT5U.MBTT.Display=to display structure guidelines GT5U.MBTT.StructureHint=Some blocks have multiple candidates or can use any tier GT5U.MBTT.Mod=Added by GT5U.MBTT.Air=Mandatory Air -GT5U.MBTT.Dots.0=No Dot -GT5U.MBTT.Dots.1=Dot 1 -GT5U.MBTT.Dots.2=Dot 2 -GT5U.MBTT.Dots.3=Dot 3 -GT5U.MBTT.Dots.4=Dot 4 -GT5U.MBTT.Dots.5=Dot 5 -GT5U.MBTT.Dots.6=Dot 6 -GT5U.MBTT.Dots.7=Dot 7 -GT5U.MBTT.Dots.8=Dot 8 -GT5U.MBTT.Dots.9=Dot 9 -GT5U.MBTT.Dots.10=Dot 10 -GT5U.MBTT.Dots.11=Dot 11 -GT5U.MBTT.Dots.12=Dot 12 -GT5U.MBTT.Dots.13=Dot 13 -GT5U.MBTT.Dots.14=Dot 14 -GT5U.MBTT.Dots.15=Dot 15 GT5U.cracker.io_side=Input/Output Hatches must be on opposite sides! -- cgit From f4495a61bd5d20f5784856227a567d03f275b554 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Thu, 22 Jul 2021 18:21:24 +0800 Subject: Fix frame box hint & placement Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../gregtech/api/util/GT_StructureUtility.java | 92 ++++++++++++++++------ .../multi/GT_MetaTileEntity_DrillerBase.java | 7 +- 2 files changed, 73 insertions(+), 26 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_StructureUtility.java b/src/main/java/gregtech/api/util/GT_StructureUtility.java index 2d15f568ab..a627da4fd6 100644 --- a/src/main/java/gregtech/api/util/GT_StructureUtility.java +++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java @@ -3,18 +3,24 @@ package gregtech.api.util; import com.gtnewhorizon.structurelib.StructureLibAPI; import com.gtnewhorizon.structurelib.structure.IStructureElement; import com.gtnewhorizon.structurelib.structure.IStructureElementNoPlacement; -import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.GregTech_API; import gregtech.api.enums.HeatingCoilLevel; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; import gregtech.api.interfaces.IHeatingCoil; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.BaseMetaPipeEntity; +import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Frame; import gregtech.common.blocks.GT_Block_Casings5; import net.minecraft.block.Block; +import net.minecraft.init.Items; +import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; import net.minecraft.world.World; -import org.apache.commons.lang3.StringUtils; +import java.util.Arrays; import java.util.function.BiConsumer; import java.util.function.BiPredicate; import java.util.function.Function; @@ -24,35 +30,75 @@ public class GT_StructureUtility { throw new AssertionError("Not instantiable"); } - public static IStructureElementNoPlacement ofHatchAdder(IGT_HatchAdder IGT_HatchAdder, int textureIndex, int dots) { - return ofHatchAdder(IGT_HatchAdder, textureIndex, StructureLibAPI.getBlockHint(), dots - 1); + public static IStructureElementNoPlacement ofHatchAdder(IGT_HatchAdder aHatchAdder, int aTextureIndex, int aDots) { + return ofHatchAdder(aHatchAdder, aTextureIndex, StructureLibAPI.getBlockHint(), aDots - 1); } - public static IStructureElementNoPlacement ofHatchAdder(IGT_HatchAdder IGT_HatchAdder, int textureIndex, Block hintBlock, int hintMeta) { - if (IGT_HatchAdder == null || hintBlock == null) { + public static IStructureElement ofFrame(Materials aFrameMaterial) { + if (aFrameMaterial == null) throw new IllegalArgumentException(); + return new IStructureElement() { + + private IIcon[] mIcons; + + @Override + public boolean check(T t, World world, int x, int y, int z) { + TileEntity tBase = world.getTileEntity(x, y, z); + if (tBase instanceof BaseMetaPipeEntity) { + BaseMetaPipeEntity tPipeBase = (BaseMetaPipeEntity) tBase; + if (tPipeBase.isInvalidTileEntity()) return false; + if (tPipeBase.getMetaTileEntity() instanceof GT_MetaPipeEntity_Frame) + return aFrameMaterial == ((GT_MetaPipeEntity_Frame) tPipeBase.getMetaTileEntity()).mMaterial; + } + return false; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + if (mIcons == null) { + mIcons = new IIcon[6]; + Arrays.fill(mIcons, aFrameMaterial.mIconSet.mTextures[OrePrefixes.frameGt.mTextureIndex].getIcon()); + } + StructureLibAPI.hintParticleTinted(world, x, y, z, mIcons, aFrameMaterial.mRGBa); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + ItemStack tFrameStack = GT_OreDictUnificator.get(OrePrefixes.frameGt, aFrameMaterial, 1); + if (tFrameStack.getItem() instanceof ItemBlock) { + ItemBlock tFrameStackItem = (ItemBlock) tFrameStack.getItem(); + return tFrameStackItem.placeBlockAt(tFrameStack, null, world, x, y, z, 6, 0, 0, 0, Items.feather.getDamage(tFrameStack)); + } + return false; + } + }; + } + + public static IStructureElementNoPlacement ofHatchAdder(IGT_HatchAdder aHatchAdder, int aTextureIndex, Block aHintBlock, int aHintMeta) { + if (aHatchAdder == null || aHintBlock == null) { throw new IllegalArgumentException(); } return new IStructureElementNoPlacement() { @Override public boolean check(T t, World world, int x, int y, int z) { TileEntity tileEntity = world.getTileEntity(x, y, z); - return tileEntity instanceof IGregTechTileEntity && IGT_HatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) textureIndex); + return tileEntity instanceof IGregTechTileEntity && aHatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) aTextureIndex); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta); + StructureLibAPI.hintParticle(world, x, y, z, aHintBlock, aHintMeta); return true; } }; } - public static IStructureElement ofHatchAdderOptional(IGT_HatchAdder IGT_HatchAdder, int textureIndex, int dots, Block placeCasing, int placeCasingMeta) { - return ofHatchAdderOptional(IGT_HatchAdder, textureIndex, StructureLibAPI.getBlockHint(), dots - 1, placeCasing, placeCasingMeta); + public static IStructureElement ofHatchAdderOptional(IGT_HatchAdder aHatchAdder, int textureIndex, int dots, Block placeCasing, int placeCasingMeta) { + return ofHatchAdderOptional(aHatchAdder, textureIndex, StructureLibAPI.getBlockHint(), dots - 1, placeCasing, placeCasingMeta); } - public static IStructureElement ofHatchAdderOptional(IGT_HatchAdder IGT_HatchAdder, int textureIndex, Block hintBlock, int hintMeta, Block placeCasing, int placeCasingMeta) { - if (IGT_HatchAdder == null || hintBlock == null) { + public static IStructureElement ofHatchAdderOptional(IGT_HatchAdder aHatchAdder, int aTextureIndex, Block aHintBlock, int hintMeta, Block placeCasing, int placeCasingMeta) { + if (aHatchAdder == null || aHintBlock == null) { throw new IllegalArgumentException(); } return new IStructureElement() { @@ -61,13 +107,13 @@ public class GT_StructureUtility { TileEntity tileEntity = world.getTileEntity(x, y, z); Block worldBlock = world.getBlock(x, y, z); return (tileEntity instanceof IGregTechTileEntity && - IGT_HatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) textureIndex)) || + aHatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) aTextureIndex)) || (worldBlock == placeCasing && worldBlock.getDamageValue(world, x, y, z) == placeCasingMeta); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta); + StructureLibAPI.hintParticle(world, x, y, z, aHintBlock, hintMeta); return true; } @@ -83,23 +129,23 @@ public class GT_StructureUtility { * Assume all coils accepted. * @see #ofCoil(BiPredicate, Function) */ - public static IStructureElement ofCoil(BiConsumer heatingCoilSetter, Function heatingCoilGetter) { + public static IStructureElement ofCoil(BiConsumer aHeatingCoilSetter, Function aHeatingCoilGetter) { return ofCoil((t, l) -> { - heatingCoilSetter.accept(t, l); + aHeatingCoilSetter.accept(t, l); return true; - }, heatingCoilGetter); + }, aHeatingCoilGetter); } /** * Heating coil structure element. - * @param heatingCoilSetter Notify the controller of this new coil. + * @param aHeatingCoilSetter Notify the controller of this new coil. * Got called exactly once per coil. * Might be called less times if structure test fails. * If the setter returns false then it assumes the coil is rejected. - * @param heatingCoilGetter Get the current heating level. Null means no coil recorded yet. + * @param aHeatingCoilGetter Get the current heating level. Null means no coil recorded yet. */ - public static IStructureElement ofCoil(BiPredicate heatingCoilSetter, Function heatingCoilGetter) { - if (heatingCoilSetter == null || heatingCoilGetter == null) { + public static IStructureElement ofCoil(BiPredicate aHeatingCoilSetter, Function aHeatingCoilGetter) { + if (aHeatingCoilSetter == null || aHeatingCoilGetter == null) { throw new IllegalArgumentException(); } return new IStructureElement() { @@ -108,10 +154,10 @@ public class GT_StructureUtility { Block block = world.getBlock(x, y, z); if (!(block instanceof IHeatingCoil)) return false; - HeatingCoilLevel existingLevel = heatingCoilGetter.apply(t), + HeatingCoilLevel existingLevel = aHeatingCoilGetter.apply(t), newLevel = ((IHeatingCoil) block).getCoilHeat(world.getBlockMetadata(x, y, z)); if (existingLevel == null || existingLevel == HeatingCoilLevel.None) { - return heatingCoilSetter.test(t, newLevel); + return aHeatingCoilSetter.test(t, newLevel); } else { return newLevel == existingLevel; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java index a610a502f9..010d1558be 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DrillerBase.java @@ -40,6 +40,7 @@ import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ORE_DRILL_ACT import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ORE_DRILL_ACTIVE_GLOW; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ORE_DRILL_GLOW; import static gregtech.api.enums.Textures.BlockIcons.getCasingTextureForId; +import static gregtech.api.util.GT_StructureUtility.ofFrame; import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; public abstract class GT_MetaTileEntity_DrillerBase extends GT_MetaTileEntity_EnhancedMultiBlockBase implements IChunkLoader { @@ -61,10 +62,10 @@ public abstract class GT_MetaTileEntity_DrillerBase extends GT_MetaTileEntity_En {" f ", "fcf", " f "}, {"b~b", "bbb", "bbb"}, })) - .addElement('f', lazy(t -> ofBlock(GregTech_API.sBlockMachines, t.frameMeta))) - .addElement('c', lazy(t -> ofBlock(t.casingBlock, t.casingMeta))) + .addElement('f', lazy(t -> ofFrame(t.getFrameMaterial()))) + .addElement('c', lazy(t -> ofBlock(t.getCasingBlockItem().getBlock(), t.getCasingBlockItem().get(0).getItemDamage()))) .addElement('b', lazy(t -> ofChain( - ofBlock(t.casingBlock, t.casingMeta), + ofBlock(t.getCasingBlockItem().getBlock(), t.getCasingBlockItem().get(0).getItemDamage()), ofHatchAdder(GT_MetaTileEntity_DrillerBase::addMaintenanceToMachineList, t.casingTextureIndex, 1), ofHatchAdder(GT_MetaTileEntity_DrillerBase::addInputToMachineList, t.casingTextureIndex, 1), ofHatchAdder(GT_MetaTileEntity_DrillerBase::addOutputToMachineList, t.casingTextureIndex, 1), -- cgit From 99f8c40f2b37b72dea22fba9f05f74253a11dffb Mon Sep 17 00:00:00 2001 From: DreamMasterXXL Date: Fri, 30 Jul 2021 12:09:29 +0200 Subject: fix (GT) build on jenkins --- src/main/java/gregtech/api/util/GT_Utility.java | 54 +++---------------------- 1 file changed, 6 insertions(+), 48 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index bb2c644f95..12ec2427ce 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -10,24 +10,13 @@ import cpw.mods.fml.common.FMLCommonHandler; import gregtech.api.GregTech_API; import gregtech.api.damagesources.GT_DamageSources; import gregtech.api.enchants.Enchantment_Radioactivity; -import gregtech.api.enums.GT_Values; -import gregtech.api.enums.ItemList; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.enums.SubTag; -import gregtech.api.enums.Textures; -import gregtech.api.enums.ToolDictNames; +import gregtech.api.enums.*; import gregtech.api.events.BlockScanningEvent; import gregtech.api.interfaces.IBlockContainer; import gregtech.api.interfaces.IDebugableBlock; import gregtech.api.interfaces.IProjectileItem; import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IBasicEnergyContainer; -import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.interfaces.tileentity.IGregTechDeviceInformation; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.interfaces.tileentity.IMachineProgress; -import gregtech.api.interfaces.tileentity.IUpgradableMachine; +import gregtech.api.interfaces.tileentity.*; import gregtech.api.items.GT_EnergyArmor_Item; import gregtech.api.items.GT_Generic_Item; import gregtech.api.items.GT_MetaGenerated_Tool; @@ -43,11 +32,7 @@ import ic2.api.recipe.RecipeOutput; import net.minecraft.block.Block; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; -import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.EnumCreatureAttribute; +import net.minecraft.entity.*; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -83,16 +68,9 @@ import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.world.BlockEvent; -import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.*; import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTankInfo; -import net.minecraftforge.fluids.IFluidContainerItem; -import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.oredict.OreDictionary; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import javax.annotation.Nullable; import java.lang.reflect.Constructor; @@ -101,31 +79,11 @@ import java.lang.reflect.Method; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Optional; -import java.util.UUID; import static gregtech.GT_Mod.GT_FML_LOGGER; -import static gregtech.api.enums.GT_Values.D1; -import static gregtech.api.enums.GT_Values.DW; -import static gregtech.api.enums.GT_Values.E; -import static gregtech.api.enums.GT_Values.GT; -import static gregtech.api.enums.GT_Values.L; -import static gregtech.api.enums.GT_Values.M; -import static gregtech.api.enums.GT_Values.NW; -import static gregtech.api.enums.GT_Values.V; -import static gregtech.api.enums.GT_Values.W; +import static gregtech.api.enums.GT_Values.*; import static gregtech.common.GT_Proxy.GTPOLLUTION; import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; -- cgit From 290e3d4ddf85fa6f912f5c81028a3032fb6ca1c7 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sun, 1 Aug 2021 02:59:57 +0800 Subject: Fix off by one in cubic multi base and tooltip builder Also added a command to toggle structure lib debug print. Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../GT_MetaTileEntity_CubicMultiBlockBase.java | 57 +++------------------- .../api/util/GT_Multiblock_Tooltip_Builder.java | 3 +- src/main/java/gregtech/common/misc/GT_Command.java | 9 +++- 3 files changed, 16 insertions(+), 53 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java index de36b845b2..3854a96cda 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java @@ -13,56 +13,19 @@ import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; /** - * A simple 3x3x3 hollow cubic multiblock, that can be arbitrarily rotated, made of a single type of machine casing, accepts hatches everywhere. - * + * A simple 3x3x3 hollow cubic multiblock, that can be arbitrarily rotated, made of a single type of machine casing and accepts hatches everywhere. * Controller will be placed in front center of the structure. *

* Note: You cannot use different casing for the same Class. Make a new subclass for it. You also should not change the casing * dynamically, i.e. it should be a dumb method returning some sort of constant. *

* Implementation tips: - *

    - *
  • To restrict hatches, override {@link #addDynamoToMachineList(IGregTechTileEntity, int)} and its cousins instead of overriding the whole + * 1. To restrict hatches, override {@link #addDynamoToMachineList(IGregTechTileEntity, int)} and its cousins instead of overriding the whole * {@link #getStructureDefinition()} or change {@link #checkHatches(IGregTechTileEntity, ItemStack)}. The former is a total overkill, while the later cannot * stop the structure check early. - * Example 1: Require ULV input only: - *
    - * {@code
    - * @Override
    - * public boolean addInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) {
    - *     if (aTileEntity == null) return false;
    - *     IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();
    - *     if (aMetaTileEntity == null) return false;
    - *     if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) {
    - *         if (((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mTier != 0) return false; // addition
    - *         ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex);
    - *         ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = getRecipeMap();
    - *         return mInputHatches.add((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity);
    - *     }
    - *     if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) {
    - *         if (((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mTier != 0) return false; // addition
    - *         ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex);
    - *         ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = getRecipeMap();
    - *         return mInputBusses.add((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity);
    - *     }
    - *     return false;
    - * }
    - * }
    - * Example 2: Allow dynamo, muffler and prevent energy hatch - *
    - * {@code
    - * @Override
    - * public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) {
    - *     return addInputToMachineList(aTileEntity, aBaseCasingIndex) ||
    - *         addOutputToMachineList(aTileEntity, aBaseCasingIndex) ||
    - *         addDynamoToMachineList(aTileEntity, aBaseCasingIndex) ||
    - *         addMufflerToMachineList(aTileEntity, aBaseCasingIndex) ||
    - *         addMaintenanceToMachineList(aTileEntity, aBaseCasingIndex);
    - * }
    - * }
  • - *
  • To limit rotation, override {@link #getInitialAlignmentLimits()}
  • - *
- * @param this + * 2. To limit rotation, override {@link #getInitialAlignmentLimits()} + * + * @param */ public abstract class GT_MetaTileEntity_CubicMultiBlockBase> extends GT_MetaTileEntity_EnhancedMultiBlockBase { protected static final String STRUCTURE_PIECE_MAIN = "main"; @@ -95,14 +58,6 @@ public abstract class GT_MetaTileEntity_CubicMultiBlockBase @@ -123,7 +78,7 @@ public abstract class GT_MetaTileEntity_CubicMultiBlockBase getRequiredCasingCount() && + mCasingAmount >= getRequiredCasingCount() && checkHatches(aBaseMetaTileEntity, aStack); } diff --git a/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java index 9afb9e58c1..3071cb95a3 100644 --- a/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java +++ b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java @@ -504,7 +504,8 @@ public class GT_Multiblock_Tooltip_Builder { hLines.add(TT_structurehint); iArray = iLines.toArray(new String[0]); sArray = sLines.toArray(new String[0]); - hArray = Stream.concat(hLines.stream(), hBlocks.asMap().entrySet().stream().map(e -> TT_dots[e.getKey()] + COLON + String.join(SEPARATOR, e.getValue()))).toArray(String[]::new); + // e.getKey() - 1 because 1 dot is meta 0. + hArray = Stream.concat(hLines.stream(), hBlocks.asMap().entrySet().stream().map(e -> TT_dots[e.getKey() - 1] + COLON + String.join(SEPARATOR, e.getValue()))).toArray(String[]::new); } public String[] getInformation() { diff --git a/src/main/java/gregtech/common/misc/GT_Command.java b/src/main/java/gregtech/common/misc/GT_Command.java index a4b46b8cee..13e26353d8 100644 --- a/src/main/java/gregtech/common/misc/GT_Command.java +++ b/src/main/java/gregtech/common/misc/GT_Command.java @@ -1,5 +1,6 @@ package gregtech.common.misc; +import com.gtnewhorizon.structurelib.StructureLib; import gregtech.GT_Mod; import gregtech.api.enums.GT_Values; import gregtech.api.objects.GT_ChunkManager; @@ -40,6 +41,7 @@ public final class GT_Command extends CommandBase { sender.addChatMessage(new ChatComponentText("\"toggle debugSmallOres\" - toggles worldgen small vein debug")); sender.addChatMessage(new ChatComponentText("\"toggle debugStones\" - toggles worldgen stones debug")); sender.addChatMessage(new ChatComponentText("\"toggle debugChunkloaders\" - toggles chunkloaders debug")); + sender.addChatMessage(new ChatComponentText("\"toggle debugMulti\" - toggles structurelib debug")); sender.addChatMessage(new ChatComponentText("\"chunks\" - print a list of the force loaded chunks")); sender.addChatMessage(new ChatComponentText( "\"pollution \" - adds the of the pollution to the current chunk, " + @@ -59,7 +61,7 @@ public final class GT_Command extends CommandBase { } else if (test.equals("toggle")) { String test1 = ss[1].trim(); Stream.of("D1", "D2", "debugCleanroom", "debugDriller", "debugBlockPump", "debugBlockMiner", "debugWorldGen", "debugEntityCramming", - "debugOrevein", "debugSmallOres", "debugStones", "debugChunkloaders") + "debugOrevein", "debugSmallOres", "debugStones", "debugChunkloaders", "debugMulti") .filter(s -> test1.isEmpty() || s.startsWith(test1)) .forEach(l::add); @@ -79,6 +81,11 @@ public final class GT_Command extends CommandBase { printHelp(sender); return; } + if ("debugMulti".equals(strings[1])) { + StructureLib.DEBUG_MODE = !StructureLib.DEBUG_MODE; + sender.addChatMessage(new ChatComponentText(strings[1] + " = " + (StructureLib.DEBUG_MODE ? "true" : "false"))); + return; + } try { Field field = GT_Values.class.getDeclaredField(strings[1]); if (field.getType() != boolean.class) { -- cgit From 3e59d9f8f2db7d56d9b1431b1e3b93c97752e20a Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Sun, 1 Aug 2021 16:29:52 -0600 Subject: Add cracked fluid cells --- build.properties | 2 +- src/main/java/gregtech/api/enums/OrePrefixes.java | 30 ++++- .../GT_MetaTileEntity_BasicGenerator.java | 21 +-- src/main/java/gregtech/api/util/GT_ModHandler.java | 17 ++- src/main/java/gregtech/common/GT_Proxy.java | 28 ++-- .../common/items/GT_MetaGenerated_Item_04.java | 146 +++++++++++++++++++++ .../preload/GT_Loader_Item_Block_And_Fluid.java | 1 + 7 files changed, 222 insertions(+), 23 deletions(-) create mode 100644 src/main/java/gregtech/common/items/GT_MetaGenerated_Item_04.java (limited to 'src/main/java/gregtech/api/util') diff --git a/build.properties b/build.properties index 6f7b5408b8..9c6f282480 100644 --- a/build.properties +++ b/build.properties @@ -1,6 +1,6 @@ minecraft.version=1.7.10 forge.version=10.13.4.1614-1.7.10 -gt.version=5.09.37.05 +gt.version=5.09.37.06 structurelib.version=1.0.6 ae2.version=rv3-beta-22 applecore.version=1.7.10-1.2.1+107.59407 diff --git a/src/main/java/gregtech/api/enums/OrePrefixes.java b/src/main/java/gregtech/api/enums/OrePrefixes.java index 3aaea29f28..77b6ee9426 100644 --- a/src/main/java/gregtech/api/enums/OrePrefixes.java +++ b/src/main/java/gregtech/api/enums/OrePrefixes.java @@ -1,6 +1,7 @@ package gregtech.api.enums; import com.google.common.base.Objects; +import com.google.common.collect.ImmutableList; import gregtech.api.GregTech_API; import gregtech.api.enums.TC_Aspects.TC_AspectStack; import gregtech.api.interfaces.ICondition; @@ -319,8 +320,27 @@ public enum OrePrefixes { bars("Bars", "", "", false, false, false, false, false, false, false, false, false, false, 0, -1, 64, -1), bar("Bars", "", "", false, false, false, false, false, false, false, false, false, false, 0, -1, 64, -1), toolHeadMallet("Mallet Heads", "", " Mallet Head", true, true, false, false, false, false, true, true, false, false, B[6], M * 6, 16, 127), // Reverse Head consisting out of 6 Ingots. - handleMallet("Mallet Handle", "", " Handle", true, true, false, false, false, false, true, true, false, false, B[1] | B[2], M / 2, 64, 126); // Reverse Stick made of half an Ingot. Introduced by Eloraam - + handleMallet("Mallet Handle", "", " Handle", true, true, false, false, false, false, true, true, false, false, B[1] | B[2], M / 2, 64, 126), // Reverse Stick made of half an Ingot. Introduced by Eloraam + + // Cracked fluids + cellHydroCracked1("Cells", "Lightly Hydro-Cracked ", " Cell", true, true, true, true, false, false, false, true, false, false, 0, M * 1, 64, 30), + cellHydroCracked2("Cells", "Moderately Hydro-Cracked ", " Cell", true, true, true, true, false, false, false, true, false, false, 0, M * 1, 64, 30), + cellHydroCracked3("Cells", "Severely Hydro-Cracked ", " Cell", true, true, true, true, false, false, false, true, false, false, 0, M * 1, 64, 30), + cellSteamCracked1("Cells", "Lightly Steam-Cracked ", " Cell", true, true, true, true, false, false, false, true, false, false, 0, M * 1, 64, 30), + cellSteamCracked2("Cells", "Moderately Steam-Cracked ", " Cell", true, true, true, true, false, false, false, true, false, false, 0, M * 1, 64, 30), + cellSteamCracked3("Cells", "Severely Steam-Cracked ", " Cell", true, true, true, true, false, false, false, true, false, false, 0, M * 1, 64, 30); + + public static final ImmutableList CELL_TYPES = + ImmutableList.of( + cell, cellMolten, cellPlasma, + cellHydroCracked1, cellHydroCracked2, cellHydroCracked3, + cellSteamCracked1, cellSteamCracked2, cellSteamCracked3); + + public static final ImmutableList CRACKED_CELL_TYPES = + ImmutableList.of( + cellHydroCracked1, cellHydroCracked2, cellHydroCracked3, + cellSteamCracked1, cellSteamCracked2, cellSteamCracked3); + public static volatile int VERSION = 509; static { @@ -531,6 +551,12 @@ public enum OrePrefixes { cell.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2); cellPlasma.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2); cellMolten.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2); + cellHydroCracked1.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2); + cellHydroCracked2.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2); + cellHydroCracked3.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2); + cellSteamCracked1.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2); + cellSteamCracked2.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2); + cellSteamCracked3.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2); oreRedgranite.mSecondaryMaterial = new MaterialStack(Materials.GraniteRed, dust.mMaterialAmount); oreBlackgranite.mSecondaryMaterial = new MaterialStack(Materials.GraniteBlack, dust.mMaterialAmount); oreNetherrack.mSecondaryMaterial = new MaterialStack(Materials.Netherrack, dust.mMaterialAmount); diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java index 48d1bd8a18..57f7073e24 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java @@ -245,16 +245,17 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity public boolean solidFuelOverride(ItemStack stack) { //this could be used for a coal generator for example aswell... ItemData association = GT_OreDictUnificator.getAssociation(stack); - //if it is a gregtech Item, make sure its not a VOLUMETRIC_FLASK, cell, motlen cell or plasma cell, else do vanilla checks - return association != null ? !OrePrefixes.cell.equals(association.mPrefix) && - !OrePrefixes.cellMolten.equals(association.mPrefix) && - !OrePrefixes.cellPlasma.equals(association.mPrefix) && - !GT_Utility.areStacksEqual(ItemList.VOLUMETRIC_FLASK.get(1L), stack, true) : - stack != null && //when the stack is null its not a solid - stack.getItem() != null && //when the item in the stack is null its not a solid - !(stack.getItem() instanceof IFluidContainerItem) && //when the item is a fluid container its not a solid... - !(stack.getItem() instanceof IFluidHandler) && //when the item is a fluid handler its not a solid... - !stack.getItem().getUnlocalizedName().contains("bucket"); //since we cant really check for buckets... + //if it is a gregtech Item, make sure its not a VOLUMETRIC_FLASK or any type of cell, else do vanilla checks + if (association != null) { + return !OrePrefixes.CELL_TYPES.contains(association.mPrefix) && + !GT_Utility.areStacksEqual(ItemList.VOLUMETRIC_FLASK.get(1L), stack, true); + } else { + return stack != null && //when the stack is null its not a solid + stack.getItem() != null && //when the item in the stack is null its not a solid + !(stack.getItem() instanceof IFluidContainerItem) && //when the item is a fluid container its not a solid... + !(stack.getItem() instanceof IFluidHandler) && //when the item is a fluid handler its not a solid... + !stack.getItem().getUnlocalizedName().contains("bucket"); //since we cant really check for buckets... + } } public abstract int getPollution(); diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java index ac9f7bd3d4..a910723069 100644 --- a/src/main/java/gregtech/api/util/GT_ModHandler.java +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -2008,7 +2008,22 @@ public class GT_ModHandler { public static int getCapsuleCellContainerCount(ItemStack aStack) { if (aStack == null) return 0; - return GT_Utility.areStacksEqual(GT_Utility.getContainerForFilledItem(aStack, true), ItemList.Cell_Empty.get(1)) || OrePrefixes.cell.contains(aStack) || OrePrefixes.cellMolten.contains(aStack) || OrePrefixes.cellPlasma.contains(aStack) || GT_Utility.areStacksEqual(aStack, getIC2Item("waterCell", 1, W)) ? 1 : 0; + + if (GT_Utility.areStacksEqual(GT_Utility.getContainerForFilledItem(aStack, true), ItemList.Cell_Empty.get(1))) { + return 1; + } + + if (GT_Utility.areStacksEqual(aStack, getIC2Item("waterCell", 1, W))) { + return 1; + } + + for (OrePrefixes cellType : OrePrefixes.CELL_TYPES) { + if (cellType.contains(aStack)) { + return 1; + } + } + + return 0; } public static class RecipeBits { diff --git a/src/main/java/gregtech/common/GT_Proxy.java b/src/main/java/gregtech/common/GT_Proxy.java index 51aadf574e..3e76335410 100644 --- a/src/main/java/gregtech/common/GT_Proxy.java +++ b/src/main/java/gregtech/common/GT_Proxy.java @@ -1781,8 +1781,8 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { public void addAutoGeneratedHydroCrackedFluids(Materials aMaterial){ Fluid[] crackedFluids = new Fluid[3]; - String[] prefixes = {"lightlyhydrocracked.", "moderatelyhydrocracked.", "severelyhydrocracked."}; - String[] localPrefixes = {"Lightly Hydro-Cracked ", "Moderately Hydro-Cracked ", "Severely Hydro-Cracked "}; + String[] namePrefixes = { "lightlyhydrocracked.", "moderatelyhydrocracked.", "severelyhydrocracked." }; + OrePrefixes[] orePrefixes = { OrePrefixes.cellHydroCracked1, OrePrefixes.cellHydroCracked2, OrePrefixes.cellHydroCracked3 }; GT_Fluid uncrackedFluid = null; if (aMaterial.mFluid != null) { uncrackedFluid = (GT_Fluid) aMaterial.mFluid; @@ -1790,8 +1790,13 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { uncrackedFluid = (GT_Fluid) aMaterial.mGas; } for (int i = 0; i < 3; i++) { - crackedFluids[i] = addFluid(prefixes[i] + aMaterial.mName.toLowerCase(Locale.ENGLISH), uncrackedFluid.mTextureName, - localPrefixes[i] + aMaterial.mDefaultLocalName, null, aMaterial.mRGBa, 2, 775, null, null, 0); + crackedFluids[i] = addFluid( + namePrefixes[i] + aMaterial.mName.toLowerCase(Locale.ENGLISH), uncrackedFluid.mTextureName, + orePrefixes[i].mLocalizedMaterialPre + aMaterial.mDefaultLocalName, + null, aMaterial.mRGBa, 2, 775, + GT_OreDictUnificator.get(orePrefixes[i], aMaterial, 1L), + ItemList.Cell_Empty.get(1L, new Object[0]), 1000); + int hydrogenAmount = 2 * i + 2; GT_Values.RA.addCrackingRecipe(i + 1, new FluidStack(uncrackedFluid, 1000), Materials.Hydrogen.getGas(hydrogenAmount * 1000), new FluidStack(crackedFluids[i], 1000), 40 + 20 * i, 120 + 60 * i); @@ -1805,8 +1810,8 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { public void addAutoGeneratedSteamCrackedFluids(Materials aMaterial){ Fluid[] crackedFluids = new Fluid[3]; - String[] prefixes = {"lightlysteamcracked.", "moderatelysteamcracked.", "severelysteamcracked."}; - String[] localPrefixes = {"Lightly Steam-Cracked ", "Moderately Steam-Cracked ", "Severely Steam-Cracked "}; + String[] namePrefixes = { "lightlysteamcracked.", "moderatelysteamcracked.", "severelysteamcracked." }; + OrePrefixes[] orePrefixes = { OrePrefixes.cellSteamCracked1, OrePrefixes.cellSteamCracked2, OrePrefixes.cellSteamCracked3 }; GT_Fluid uncrackedFluid = null; if (aMaterial.mFluid != null) { uncrackedFluid = (GT_Fluid) aMaterial.mFluid; @@ -1814,9 +1819,14 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { uncrackedFluid = (GT_Fluid) aMaterial.mGas; } for (int i = 0; i < 3; i++) { - crackedFluids[i] = addFluid(prefixes[i] + aMaterial.mName.toLowerCase(Locale.ENGLISH), uncrackedFluid.mTextureName, - localPrefixes[i] + aMaterial.mDefaultLocalName, null, aMaterial.mRGBa, 2, 775, null, null, 0); - GT_Values.RA.addCrackingRecipe(i + 1, new FluidStack(uncrackedFluid, 1000), GT_ModHandler.getSteam(1000), + crackedFluids[i] = addFluid( + namePrefixes[i] + aMaterial.mName.toLowerCase(Locale.ENGLISH), uncrackedFluid.mTextureName, + orePrefixes[i].mLocalizedMaterialPre + aMaterial.mDefaultLocalName, + null, aMaterial.mRGBa, 2, 775, + GT_OreDictUnificator.get(orePrefixes[i], aMaterial, 1L), + ItemList.Cell_Empty.get(1L, new Object[0]), 1000); + + GT_Values.RA.addCrackingRecipe(i + 1, new FluidStack(uncrackedFluid, 1000), GT_ModHandler.getSteam(1000), new FluidStack(crackedFluids[i], 1000), 40 + 20 * i, 240 + 120 * i); GT_Values.RA.addChemicalRecipe(GT_ModHandler.getIC2Item("steamCell", 1L), GT_Utility.getIntegratedCircuit(i + 1), new FluidStack(uncrackedFluid, 1000), new FluidStack(crackedFluids[i], 800), Materials.Empty.getCells(1), 160 + 80 * i, 30); diff --git a/src/main/java/gregtech/common/items/GT_MetaGenerated_Item_04.java b/src/main/java/gregtech/common/items/GT_MetaGenerated_Item_04.java new file mode 100644 index 0000000000..728128ac39 --- /dev/null +++ b/src/main/java/gregtech/common/items/GT_MetaGenerated_Item_04.java @@ -0,0 +1,146 @@ +package gregtech.common.items; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.items.GT_MetaGenerated_Item; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_OreDictUnificator; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +import java.util.BitSet; +import java.util.List; + +import static gregtech.api.enums.GT_Values.M; + +/** Generates cells for cracked fluids. */ +public class GT_MetaGenerated_Item_04 extends GT_MetaGenerated_Item { + public static GT_MetaGenerated_Item_04 INSTANCE; + + private static final int NUM_CRACKED_CELL_TYPES = OrePrefixes.CRACKED_CELL_TYPES.size(); + + private BitSet enabled = new BitSet(); + + public GT_MetaGenerated_Item_04() { + super("metaitem.04", (short) (NUM_CRACKED_CELL_TYPES * 1000), (short) 0); + INSTANCE = this; + + for (Materials tMaterial : GregTech_API.sGeneratedMaterials) { + if (tMaterial == null || !tMaterial.canBeCracked() || tMaterial.mMetaItemSubID < 0 || tMaterial.mMetaItemSubID >= 1000) { + continue; + } + register(tMaterial, tMaterial.mMetaItemSubID); + } + + // We're not going to use these BitSets, so clear them to save memory. + mEnabledItems.clear(); + mVisibleItems.clear(); + } + + private void register(Materials tMaterial, int i) { + int currIndex = NUM_CRACKED_CELL_TYPES * i; + for (OrePrefixes type : OrePrefixes.CRACKED_CELL_TYPES) { + ItemStack tStack = new ItemStack(this, 1, currIndex); + GT_LanguageManager.addStringLocalization(getUnlocalizedName(tStack) + ".name", type.getDefaultLocalNameFormatForItem(tMaterial)); + GT_LanguageManager.addStringLocalization(getUnlocalizedName(tStack) + ".tooltip", tMaterial.getToolTip(type.mMaterialAmount / M)); + + if (type.mIsUnificatable) { + GT_OreDictUnificator.set(type, tMaterial, tStack); + } else { + GT_OreDictUnificator.registerOre(type.get(tMaterial), tStack); + } + + enabled.set(currIndex); + currIndex++; + } + } + + private int getMaterialIndex(int damage) { + return damage / NUM_CRACKED_CELL_TYPES; + } + + /** Returns null for item damage out of bounds. */ + private OrePrefixes getOrePrefix(int damage) { + if (damage < 0 || damage >= NUM_CRACKED_CELL_TYPES * 1000) { + return null; + } + return OrePrefixes.CRACKED_CELL_TYPES.get(damage % NUM_CRACKED_CELL_TYPES); + } + + @Override + public short[] getRGBa(ItemStack aStack) { + Materials tMaterial = GregTech_API.sGeneratedMaterials[getMaterialIndex(aStack.getItemDamage())]; + return tMaterial == null ? Materials._NULL.mRGBa : tMaterial.mRGBa; + } + + @Override + public String getItemStackDisplayName(ItemStack aStack) { + String aName = super.getItemStackDisplayName(aStack); + + int index = getMaterialIndex(aStack.getItemDamage()); + if (index >= 0 && index < 1000) { + return Materials.getLocalizedNameForItem(aName, index); + } + + return aName; + } + + @Override + public ItemStack getContainerItem(ItemStack aStack) { + OrePrefixes prefix = getOrePrefix(aStack.getItemDamage()); + if (prefix != null) { + return prefix.mContainerItem; + } + return null; + } + + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(Item var1, CreativeTabs aCreativeTab, List aList) { + enabled.stream() + .mapToObj(i -> new ItemStack(this, 1, i)) + .forEach(aList::add); + } + + @Override + public final IIcon getIconFromDamage(int aMetaData) { + IIconContainer iconContainer = getIconContainer(aMetaData); + if (iconContainer != null) { + return iconContainer.getIcon(); + } + return null; + } + + @Override + public IIconContainer getIconContainer(int aMetaData) { + int index = getMaterialIndex(aMetaData); + if (index < 0 || index >= 1000) { + return null; + } + + Materials material = GregTech_API.sGeneratedMaterials[index]; + OrePrefixes prefix = getOrePrefix(aMetaData); + if (material != null && prefix != null) { + return material.mIconSet.mTextures[prefix.mTextureIndex]; + } + + return null; + } + + @Override + public int getItemStackLimit(ItemStack aStack) { + OrePrefixes prefix = getOrePrefix(aStack.getItemDamage()); + if (prefix != null) { + return prefix.mDefaultStackSize; + } else { + // If we're here, then something went wrong. Use cell.mDefaultStackSize as a fallback. + return OrePrefixes.cell.mDefaultStackSize; + } + } +} diff --git a/src/main/java/gregtech/loaders/preload/GT_Loader_Item_Block_And_Fluid.java b/src/main/java/gregtech/loaders/preload/GT_Loader_Item_Block_And_Fluid.java index 4fbc25f226..77b65e5b18 100644 --- a/src/main/java/gregtech/loaders/preload/GT_Loader_Item_Block_And_Fluid.java +++ b/src/main/java/gregtech/loaders/preload/GT_Loader_Item_Block_And_Fluid.java @@ -71,6 +71,7 @@ public class GT_Loader_Item_Block_And_Fluid implements Runnable { new GT_MetaGenerated_Item_01(); new GT_MetaGenerated_Item_02(); new GT_MetaGenerated_Item_03(); + new GT_MetaGenerated_Item_04(); new GT_MetaGenerated_Item_99(); new GT_MetaGenerated_Tool_01(); new GT_FluidDisplayItem(); -- cgit From c5696af87dd08b75cf1a3e7d738f82acd060680f Mon Sep 17 00:00:00 2001 From: TimeConqueror Date: Mon, 2 Aug 2021 22:04:38 +0300 Subject: Added some constructors to Hatch Buses to remove some GTPP ASM --- .../GT_MetaTileEntity_Hatch_InputBus.java | 32 ++++++++++++---------- .../GT_MetaTileEntity_Hatch_OutputBus.java | 29 ++++++++++++-------- .../java/gregtech/api/util/extensions/Arrays.java | 32 ++++++++++++++++++++++ 3 files changed, 67 insertions(+), 26 deletions(-) create mode 100644 src/main/java/gregtech/api/util/extensions/Arrays.java (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java index ebda3cccbc..7d9cd4f780 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java @@ -1,14 +1,7 @@ package gregtech.api.metatileentity.implementations; import gregtech.GT_Mod; -import gregtech.api.gui.GT_Container_1by1; -import gregtech.api.gui.GT_Container_2by2; -import gregtech.api.gui.GT_Container_3by3; -import gregtech.api.gui.GT_Container_4by4; -import gregtech.api.gui.GT_GUIContainer_1by1; -import gregtech.api.gui.GT_GUIContainer_2by2; -import gregtech.api.gui.GT_GUIContainer_3by3; -import gregtech.api.gui.GT_GUIContainer_4by4; +import gregtech.api.gui.*; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -17,6 +10,7 @@ import gregtech.api.util.GT_ClientPreference; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; +import gregtech.api.util.extensions.Arrays; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; @@ -30,19 +24,29 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { public boolean disableSort; public boolean disableFilter = false; - public GT_MetaTileEntity_Hatch_InputBus(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, getSlots(aTier), new String[]{ + public GT_MetaTileEntity_Hatch_InputBus(int id, String name, String nameRegional, int tier) { + this(id, name, nameRegional, tier, getSlots(tier)); + } + + public GT_MetaTileEntity_Hatch_InputBus(int id, String name, String nameRegional, int tier, int slots) { + super(id, name, nameRegional, tier, slots, Arrays.of( "Item Input for Multiblocks", "Shift + right click with screwdriver to turn Sort mode on/off", - "Capacity: " + getSlots(aTier) + " stack" + (getSlots(aTier) >= 2 ? "s" : "")}); + "Capacity: " + slots + " stack" + (slots >= 2 ? "s" : ""))); } + @Deprecated + // having too many constructors is bad, don't be so lazy, use GT_MetaTileEntity_Hatch_InputBus(String, int, String[], ITexture[][][]) public GT_MetaTileEntity_Hatch_InputBus(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 9 : 16, aDescription, aTextures); + this(aName, aTier, Arrays.of(aDescription), aTextures); } public GT_MetaTileEntity_Hatch_InputBus(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 9 : 16, aDescription, aTextures); + this(aName, aTier, getSlots(aTier), aDescription, aTextures); + } + + public GT_MetaTileEntity_Hatch_InputBus(String aName, int aTier, int aSlots, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aSlots, aDescription, aTextures); } @Override @@ -176,7 +180,7 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { GT_Utility.sendChatToPlayer(aPlayer, trans("200", "Sort mode: " + (disableSort ? "Disabled" : "Enabled"))); } else { disableFilter = !disableFilter; - GT_Utility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("GT5U.hatch.disableFilter."+disableFilter)); + GT_Utility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("GT5U.hatch.disableFilter." + disableFilter)); } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java index a46157fb36..86e95b2234 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java @@ -1,18 +1,12 @@ package gregtech.api.metatileentity.implementations; -import gregtech.api.gui.GT_Container_1by1; -import gregtech.api.gui.GT_Container_2by2; -import gregtech.api.gui.GT_Container_3by3; -import gregtech.api.gui.GT_Container_4by4; -import gregtech.api.gui.GT_GUIContainer_1by1; -import gregtech.api.gui.GT_GUIContainer_2by2; -import gregtech.api.gui.GT_GUIContainer_3by3; -import gregtech.api.gui.GT_GUIContainer_4by4; +import gregtech.api.gui.*; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Utility; +import gregtech.api.util.extensions.Arrays; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; @@ -23,8 +17,13 @@ import static gregtech.api.util.GT_Utility.moveMultipleItemStacks; public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch { public GT_MetaTileEntity_Hatch_OutputBus(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, getSlots(aTier), new String[]{"Item Output for Multiblocks", - "Capacity: " + getSlots(aTier) + " stack" + (getSlots(aTier) >= 2 ? "s" : "")}); + this(aID, aName, aNameRegional, aTier, getSlots(aTier)); + } + + public GT_MetaTileEntity_Hatch_OutputBus(int id, String name, String nameRegional, int tier, int slots) { + super(id, name, nameRegional, tier, slots, Arrays.of( + "Item Output for Multiblocks", + "Capacity: " + getSlots(tier) + " stack" + (getSlots(tier) >= 2 ? "s" : ""))); } public GT_MetaTileEntity_Hatch_OutputBus(int aID, String aName, String aNameRegional, int aTier, String[] aDescription) { @@ -35,18 +34,24 @@ public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch { super(aID, aName, aNameRegional, aTier, inventorySize, aDescription); } + @Deprecated + // having too many constructors is bad, don't be so lazy, use GT_MetaTileEntity_Hatch_OutputBus(String, int, String[], ITexture[][][]) public GT_MetaTileEntity_Hatch_OutputBus(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 9 : 16, aDescription, aTextures); + this(aName, aTier, getSlots(aTier), Arrays.of(aDescription), aTextures); } public GT_MetaTileEntity_Hatch_OutputBus(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 9 : 16, aDescription, aTextures); + super(aName, aTier, getSlots(aTier), aDescription, aTextures); } public GT_MetaTileEntity_Hatch_OutputBus(String aName, int aTier, String[] aDescription, int inventorySize, ITexture[][][] aTextures) { super(aName, aTier, inventorySize, aDescription, aTextures); } + public GT_MetaTileEntity_Hatch_OutputBus(String name, int tier, int slots, String[] description, ITexture[][][] textures) { + super(name, tier, slots, description, textures); + } + @Override public ITexture[] getTexturesActive(ITexture aBaseTexture) { return new ITexture[]{aBaseTexture, TextureFactory.of(OVERLAY_PIPE_OUT)}; diff --git a/src/main/java/gregtech/api/util/extensions/Arrays.java b/src/main/java/gregtech/api/util/extensions/Arrays.java new file mode 100644 index 0000000000..41efec5587 --- /dev/null +++ b/src/main/java/gregtech/api/util/extensions/Arrays.java @@ -0,0 +1,32 @@ +package gregtech.api.util.extensions; + +public class Arrays { + public static int[] of(int... objects) { + return objects; + } + + public static float[] of(float... objects) { + return objects; + } + + public static double[] of(double... objects) { + return objects; + } + + public static char[] of(char... objects) { + return objects; + } + + public static byte[] of(byte... objects) { + return objects; + } + + public static long[] of(long... objects) { + return objects; + } + + @SafeVarargs + public static T[] of(T... objects) { + return objects; + } +} -- cgit From 878b9ac656aa21727bcd42e4835d0e7f067983ea Mon Sep 17 00:00:00 2001 From: TimeConqueror Date: Tue, 3 Aug 2021 21:03:45 +0300 Subject: Well, the name 'Arrays' seems to be not so good, since it collides with java.util.Arrays --- .../GT_MetaTileEntity_Hatch_InputBus.java | 6 +-- .../GT_MetaTileEntity_Hatch_OutputBus.java | 6 +-- .../gregtech/api/util/extensions/ArrayExt.java | 59 ++++++++++++++++++++++ .../java/gregtech/api/util/extensions/Arrays.java | 32 ------------ 4 files changed, 65 insertions(+), 38 deletions(-) create mode 100644 src/main/java/gregtech/api/util/extensions/ArrayExt.java delete mode 100644 src/main/java/gregtech/api/util/extensions/Arrays.java (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java index 7d9cd4f780..cfb4d33150 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java @@ -10,7 +10,7 @@ import gregtech.api.util.GT_ClientPreference; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; -import gregtech.api.util.extensions.Arrays; +import gregtech.api.util.extensions.ArrayExt; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; @@ -29,7 +29,7 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { } public GT_MetaTileEntity_Hatch_InputBus(int id, String name, String nameRegional, int tier, int slots) { - super(id, name, nameRegional, tier, slots, Arrays.of( + super(id, name, nameRegional, tier, slots, ArrayExt.of( "Item Input for Multiblocks", "Shift + right click with screwdriver to turn Sort mode on/off", "Capacity: " + slots + " stack" + (slots >= 2 ? "s" : ""))); @@ -38,7 +38,7 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { @Deprecated // having too many constructors is bad, don't be so lazy, use GT_MetaTileEntity_Hatch_InputBus(String, int, String[], ITexture[][][]) public GT_MetaTileEntity_Hatch_InputBus(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - this(aName, aTier, Arrays.of(aDescription), aTextures); + this(aName, aTier, ArrayExt.of(aDescription), aTextures); } public GT_MetaTileEntity_Hatch_InputBus(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java index 7f5970d184..f997f5f489 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java @@ -6,7 +6,7 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Utility; -import gregtech.api.util.extensions.Arrays; +import gregtech.api.util.extensions.ArrayExt; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; @@ -21,7 +21,7 @@ public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch { } public GT_MetaTileEntity_Hatch_OutputBus(int id, String name, String nameRegional, int tier, int slots) { - super(id, name, nameRegional, tier, slots, Arrays.of( + super(id, name, nameRegional, tier, slots, ArrayExt.of( "Item Output for Multiblocks", "Capacity: " + getSlots(tier) + " stack" + (getSlots(tier) >= 2 ? "s" : ""))); } @@ -37,7 +37,7 @@ public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch { @Deprecated // having too many constructors is bad, don't be so lazy, use GT_MetaTileEntity_Hatch_OutputBus(String, int, String[], ITexture[][][]) public GT_MetaTileEntity_Hatch_OutputBus(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - this(aName, aTier, getSlots(aTier), Arrays.of(aDescription), aTextures); + this(aName, aTier, getSlots(aTier), ArrayExt.of(aDescription), aTextures); } public GT_MetaTileEntity_Hatch_OutputBus(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { diff --git a/src/main/java/gregtech/api/util/extensions/ArrayExt.java b/src/main/java/gregtech/api/util/extensions/ArrayExt.java new file mode 100644 index 0000000000..faa01cb368 --- /dev/null +++ b/src/main/java/gregtech/api/util/extensions/ArrayExt.java @@ -0,0 +1,59 @@ +package gregtech.api.util.extensions; + +import java.util.function.IntFunction; + +public class ArrayExt { + public static int[] of(int... objects) { + return objects; + } + + public static float[] of(float... objects) { + return objects; + } + + public static double[] of(double... objects) { + return objects; + } + + public static char[] of(char... objects) { + return objects; + } + + public static byte[] of(byte... objects) { + return objects; + } + + public static long[] of(long... objects) { + return objects; + } + + @SafeVarargs + public static T[] of(T... objects) { + return objects; + } + + public static T[] withoutTrailingNulls(T[] array, IntFunction arrayFactory) { + int firstNull = -1; + for (int i = 0; i < array.length; i++) { + if (array[i] == null) { + if (firstNull == -1) { + firstNull = i; + } + } else { + firstNull = -1; + } + } + + if (firstNull == -1) { + T[] newArray = arrayFactory.apply(array.length); + System.arraycopy(array, 0, newArray, 0, array.length); + return newArray; + } else if (firstNull == 0) { + return arrayFactory.apply(0); + } else { + T[] newArray = arrayFactory.apply(firstNull); + System.arraycopy(array, 0, newArray, 0, firstNull); + return newArray; + } + } +} diff --git a/src/main/java/gregtech/api/util/extensions/Arrays.java b/src/main/java/gregtech/api/util/extensions/Arrays.java deleted file mode 100644 index 41efec5587..0000000000 --- a/src/main/java/gregtech/api/util/extensions/Arrays.java +++ /dev/null @@ -1,32 +0,0 @@ -package gregtech.api.util.extensions; - -public class Arrays { - public static int[] of(int... objects) { - return objects; - } - - public static float[] of(float... objects) { - return objects; - } - - public static double[] of(double... objects) { - return objects; - } - - public static char[] of(char... objects) { - return objects; - } - - public static byte[] of(byte... objects) { - return objects; - } - - public static long[] of(long... objects) { - return objects; - } - - @SafeVarargs - public static T[] of(T... objects) { - return objects; - } -} -- cgit From b9468785aa264ba0c1fcf295bb15260bb47c90c0 Mon Sep 17 00:00:00 2001 From: TimeConqueror Date: Tue, 3 Aug 2021 22:34:50 +0300 Subject: GT_Recipe: speedup --- .../api/objects/iterators/ArrayIterator.java | 24 ++++++++++++++ .../api/objects/iterators/MergedIterator.java | 30 ++++++++++++++++++ .../api/objects/iterators/NonNullIterator.java | 36 +++++++++++++++++++++ src/main/java/gregtech/api/util/GT_Recipe.java | 37 +++++++++++----------- src/main/java/gregtech/api/util/GT_Utility.java | 8 +++++ .../gregtech/api/util/extensions/ArrayExt.java | 23 ++++++++++++++ .../gregtech/api/util/extensions/IteratorExt.java | 23 ++++++++++++++ .../basic/GT_MetaTileEntity_Disassembler.java | 11 ++----- 8 files changed, 166 insertions(+), 26 deletions(-) create mode 100644 src/main/java/gregtech/api/objects/iterators/ArrayIterator.java create mode 100644 src/main/java/gregtech/api/objects/iterators/MergedIterator.java create mode 100644 src/main/java/gregtech/api/objects/iterators/NonNullIterator.java create mode 100644 src/main/java/gregtech/api/util/extensions/IteratorExt.java (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/objects/iterators/ArrayIterator.java b/src/main/java/gregtech/api/objects/iterators/ArrayIterator.java new file mode 100644 index 0000000000..267a132ad5 --- /dev/null +++ b/src/main/java/gregtech/api/objects/iterators/ArrayIterator.java @@ -0,0 +1,24 @@ +package gregtech.api.objects.iterators; + +import java.util.Iterator; + +public class ArrayIterator implements Iterator { + private final T[] arr; + private int offset; + + public ArrayIterator(T[] arr) { + this.arr = arr; + } + + @Override + public boolean hasNext() { + return offset != arr.length; + } + + @Override + public T next() { + T out = arr[offset]; + offset++; + return out; + } +} diff --git a/src/main/java/gregtech/api/objects/iterators/MergedIterator.java b/src/main/java/gregtech/api/objects/iterators/MergedIterator.java new file mode 100644 index 0000000000..77fac8d22f --- /dev/null +++ b/src/main/java/gregtech/api/objects/iterators/MergedIterator.java @@ -0,0 +1,30 @@ +package gregtech.api.objects.iterators; + +import java.util.Iterator; + +public class MergedIterator implements Iterator { + private final Iterator[] inners; + private int current; + + @SafeVarargs + public MergedIterator(Iterator... iterators) { + inners = iterators; + current = 0; + } + + public boolean hasNext() { + while (current < inners.length && !inners[current].hasNext()) { + current++; + } + + return current < inners.length; + } + + public T next() { + while (current < inners.length && !inners[current].hasNext()) { + current++; + } + + return inners[current].next(); + } +} diff --git a/src/main/java/gregtech/api/objects/iterators/NonNullIterator.java b/src/main/java/gregtech/api/objects/iterators/NonNullIterator.java new file mode 100644 index 0000000000..22dd33ba2b --- /dev/null +++ b/src/main/java/gregtech/api/objects/iterators/NonNullIterator.java @@ -0,0 +1,36 @@ +package gregtech.api.objects.iterators; + +import java.util.Iterator; + +public class NonNullIterator implements Iterator { + private final Iterator internal; + private T last = null; + + public NonNullIterator(Iterator in) { + this.internal = in; + } + + @Override + public boolean hasNext() { + while (last == null) { + if (internal.hasNext()) { + last = internal.next(); + } else { + return false; + } + } + + return true; + } + + @Override + public T next() { + while (last == null) { + last = internal.next(); + } + + T temp = last; + last = null; + return temp; + } +} diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 19f46dfd15..98a2d9635d 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -9,6 +9,7 @@ import gregtech.api.objects.GT_FluidStack; import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.ItemData; import gregtech.api.objects.MaterialStack; +import gregtech.api.util.extensions.ArrayExt; import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Replicator; import gregtech.nei.GT_NEI_DefaultHandler.FixedPositionedStack; import ic2.core.Ic2Items; @@ -23,7 +24,6 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidContainerItem; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import static gregtech.api.enums.GT_Values.*; @@ -97,7 +97,8 @@ public class GT_Recipe implements Comparable { mEnabled = aRecipe.mEnabled; mHidden = aRecipe.mHidden; } - protected GT_Recipe(boolean aOptimize, ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecialItems, int[] aChances, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) { + + public GT_Recipe(boolean aOptimize, ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecialItems, int[] aChances, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue) { if (aInputs == null) aInputs = new ItemStack[0]; if (aOutputs == null) @@ -111,10 +112,10 @@ public class GT_Recipe implements Comparable { if (aChances.length < aOutputs.length) aChances = Arrays.copyOf(aChances, aOutputs.length); - aInputs = GT_Utility.getArrayListWithoutTrailingNulls(aInputs).toArray(new ItemStack[0]); - aOutputs = GT_Utility.getArrayListWithoutTrailingNulls(aOutputs).toArray(new ItemStack[0]); - aFluidInputs = GT_Utility.getArrayListWithoutNulls(aFluidInputs).toArray(new FluidStack[0]); - aFluidOutputs = GT_Utility.getArrayListWithoutNulls(aFluidOutputs).toArray(new FluidStack[0]); + aInputs = ArrayExt.withoutTrailingNulls(aInputs, ItemStack[]::new); + aOutputs = ArrayExt.withoutTrailingNulls(aOutputs, ItemStack[]::new); + aFluidInputs = ArrayExt.withoutNulls(aFluidInputs, FluidStack[]::new); + aFluidOutputs = ArrayExt.withoutNulls(aFluidOutputs, FluidStack[]::new); GT_OreDictUnificator.setStackArray(true, aInputs); GT_OreDictUnificator.setStackArray(true, aOutputs); @@ -1627,12 +1628,12 @@ public class GT_Recipe implements Comparable { } } - - public static class GT_Recipe_Map_LargeChemicalReactor extends GT_Recipe_Map{ - private static int TOTAL_INPUT_COUNT = 6; - private static int OUTPUT_COUNT = 2; - private static int FLUID_OUTPUT_COUNT = 4; - + + public static class GT_Recipe_Map_LargeChemicalReactor extends GT_Recipe_Map { + private static final int TOTAL_INPUT_COUNT = 6; + private static final int OUTPUT_COUNT = 2; + private static final int FLUID_OUTPUT_COUNT = 4; + public GT_Recipe_Map_LargeChemicalReactor() { super(new HashSet<>(1000), "gt.recipe.largechemicalreactor", "Large Chemical Reactor", null, RES_PATH_GUI + "basicmachines/Default", 2, OUTPUT_COUNT, 0, 0, 1, E, 1, E, true, true); } @@ -1648,7 +1649,7 @@ public class GT_Recipe implements Comparable { if (aInputs == null) { aInputs = new ItemStack[0]; } else { - aInputs = GT_Utility.getArrayListWithoutTrailingNulls(aInputs).toArray(new ItemStack[0]); + aInputs = ArrayExt.withoutTrailingNulls(aInputs, ItemStack[]::new); } for (ItemStack input : aInputs) { @@ -1688,7 +1689,7 @@ public class GT_Recipe implements Comparable { if (aOutputs == null) { aOutputs = new ItemStack[0]; } else { - aOutputs = GT_Utility.getArrayListWithoutTrailingNulls(aOutputs).toArray(new ItemStack[0]); + aOutputs = ArrayExt.withoutTrailingNulls(aOutputs, ItemStack[]::new); } for (ItemStack output : aOutputs) { @@ -1734,9 +1735,9 @@ public class GT_Recipe implements Comparable { for (int i = 0; i < itemLimit; i++, j++) { if (this.mInputs == null || (this.mInputs[i] == null && (i == 0 && itemLimit == 1))) { if (this.mOutputs != null && this.mOutputs.length > 0 && this.mOutputs[0] != null) - GT_Log.out.println("recipe " + this.toString() + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!"); + GT_Log.out.println("recipe " + this + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!"); else - GT_Log.out.println("recipe " + this.toString() + " has errored!"); + GT_Log.out.println("recipe " + this + " has errored!"); new Exception("Recipe Fixme").printStackTrace(GT_Log.out); } @@ -1751,9 +1752,9 @@ public class GT_Recipe implements Comparable { for (int i = 0; i < fluidLimit; i++, j++) { if (this.mFluidInputs == null || this.mFluidInputs[i] == null) { if (this.mOutputs != null && this.mOutputs.length > 0 && this.mOutputs[0] != null) - GT_Log.out.println("recipe " + this.toString() + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!"); + GT_Log.out.println("recipe " + this + " Output 0:" + this.mOutputs[0].getDisplayName() + " has errored!"); else - GT_Log.out.println("recipe " + this.toString() + " has errored!"); + GT_Log.out.println("recipe " + this + " has errored!"); new Exception("Recipe Fixme").printStackTrace(GT_Log.out); } diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 12ec2427ce..94195d76ce 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -24,6 +24,7 @@ import gregtech.api.net.GT_Packet_Sound; import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.ItemData; import gregtech.api.threads.GT_Runnable_Sound; +import gregtech.api.util.extensions.ArrayExt; import gregtech.common.GT_Proxy; import ic2.api.recipe.IRecipeInput; import ic2.api.recipe.RecipeInputItemStack; @@ -81,6 +82,7 @@ import java.text.DecimalFormatSymbols; import java.text.NumberFormat; import java.util.*; import java.util.Map.Entry; +import java.util.function.IntFunction; import static gregtech.GT_Mod.GT_FML_LOGGER; import static gregtech.api.enums.GT_Values.*; @@ -1236,6 +1238,9 @@ public class GT_Utility { return false; } + /** + * Note: use {@link ArrayExt#withoutNulls(Object[], IntFunction)} if you want an array as a result. + */ public static ArrayList getArrayListWithoutNulls(T... aArray) { if (aArray == null) return new ArrayList<>(); ArrayList rList = new ArrayList<>(Arrays.asList(aArray)); @@ -1243,6 +1248,9 @@ public class GT_Utility { return rList; } + /** + * Note: use {@link ArrayExt#withoutTrailingNulls(Object[], IntFunction)} if you want an array as a result. + */ public static ArrayList getArrayListWithoutTrailingNulls(T... aArray) { if (aArray == null) return new ArrayList<>(); ArrayList rList = new ArrayList<>(Arrays.asList(aArray)); diff --git a/src/main/java/gregtech/api/util/extensions/ArrayExt.java b/src/main/java/gregtech/api/util/extensions/ArrayExt.java index faa01cb368..9b39f74518 100644 --- a/src/main/java/gregtech/api/util/extensions/ArrayExt.java +++ b/src/main/java/gregtech/api/util/extensions/ArrayExt.java @@ -32,6 +32,29 @@ public class ArrayExt { return objects; } + @SuppressWarnings("ForLoopReplaceableByForEach") + public static T[] withoutNulls(T[] array, IntFunction arrayFactory) { + int count = 0; + for (int i = 0; i < array.length; i++) { + if (array[i] != null) { + count++; + } + } + + T[] newArr = arrayFactory.apply(count); + if (count == 0) return newArr; + + int j = 0; + for (int i = 0; i < array.length; i++) { + if (array[i] != null) { + newArr[j] = array[i]; + j++; + } + } + + return newArr; + } + public static T[] withoutTrailingNulls(T[] array, IntFunction arrayFactory) { int firstNull = -1; for (int i = 0; i < array.length; i++) { diff --git a/src/main/java/gregtech/api/util/extensions/IteratorExt.java b/src/main/java/gregtech/api/util/extensions/IteratorExt.java new file mode 100644 index 0000000000..1a29a7b41a --- /dev/null +++ b/src/main/java/gregtech/api/util/extensions/IteratorExt.java @@ -0,0 +1,23 @@ +package gregtech.api.util.extensions; + +import gregtech.api.objects.iterators.ArrayIterator; +import gregtech.api.objects.iterators.MergedIterator; +import gregtech.api.objects.iterators.NonNullIterator; + +import java.util.Iterator; + +public class IteratorExt { + @SafeVarargs + public static Iterator merge(Iterator... iterators) { + return new MergedIterator<>(iterators); + } + + public static Iterator withoutNulls(Iterator iterator) { + return new NonNullIterator<>(iterator); + } + + @SafeVarargs + public static ArrayIterator ofArray(T... items) { + return new ArrayIterator<>(items); + } +} diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java index b820dd44fd..02eb893ba0 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java @@ -19,18 +19,13 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; +import gregtech.api.util.extensions.ArrayExt; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -234,7 +229,7 @@ public class GT_MetaTileEntity_Disassembler extends GT_MetaTileEntity_BasicMachi if (GT_Utility.isStackInvalid(recipe.inputs[i]) || recipe.inputs[i].stackSize < 1) recipe.inputs[i] = null; - recipe.inputs = GT_Utility.getArrayListWithoutNulls(recipe.inputs).toArray(new ItemStack[0]); + recipe.inputs = ArrayExt.withoutNulls(recipe.inputs, ItemStack[]::new); } private int checkRecipeMap() { -- cgit From fa39d5af8adaf20adeba17bbf951111938f8218f Mon Sep 17 00:00:00 2001 From: TimeConqueror Date: Tue, 3 Aug 2021 22:54:08 +0300 Subject: Sped up ArrayExt#withoutTrailingNulls by iterating from the last element --- src/main/java/gregtech/api/util/extensions/ArrayExt.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/extensions/ArrayExt.java b/src/main/java/gregtech/api/util/extensions/ArrayExt.java index 9b39f74518..51486bc036 100644 --- a/src/main/java/gregtech/api/util/extensions/ArrayExt.java +++ b/src/main/java/gregtech/api/util/extensions/ArrayExt.java @@ -57,13 +57,11 @@ public class ArrayExt { public static T[] withoutTrailingNulls(T[] array, IntFunction arrayFactory) { int firstNull = -1; - for (int i = 0; i < array.length; i++) { + for (int i = array.length - 1; i >= 0; i--) { if (array[i] == null) { - if (firstNull == -1) { - firstNull = i; - } + firstNull = i; } else { - firstNull = -1; + break; } } -- cgit From 35937ca89911c2b29f0a6027963c7439762045e7 Mon Sep 17 00:00:00 2001 From: TimeConqueror Date: Tue, 3 Aug 2021 23:13:02 +0300 Subject: Removed ArrayIterator and NonNullIterator, because they're redundant --- .../api/objects/iterators/ArrayIterator.java | 24 --------------- .../api/objects/iterators/NonNullIterator.java | 36 ---------------------- .../gregtech/api/util/extensions/IteratorExt.java | 11 ------- 3 files changed, 71 deletions(-) delete mode 100644 src/main/java/gregtech/api/objects/iterators/ArrayIterator.java delete mode 100644 src/main/java/gregtech/api/objects/iterators/NonNullIterator.java (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/objects/iterators/ArrayIterator.java b/src/main/java/gregtech/api/objects/iterators/ArrayIterator.java deleted file mode 100644 index 267a132ad5..0000000000 --- a/src/main/java/gregtech/api/objects/iterators/ArrayIterator.java +++ /dev/null @@ -1,24 +0,0 @@ -package gregtech.api.objects.iterators; - -import java.util.Iterator; - -public class ArrayIterator implements Iterator { - private final T[] arr; - private int offset; - - public ArrayIterator(T[] arr) { - this.arr = arr; - } - - @Override - public boolean hasNext() { - return offset != arr.length; - } - - @Override - public T next() { - T out = arr[offset]; - offset++; - return out; - } -} diff --git a/src/main/java/gregtech/api/objects/iterators/NonNullIterator.java b/src/main/java/gregtech/api/objects/iterators/NonNullIterator.java deleted file mode 100644 index 22dd33ba2b..0000000000 --- a/src/main/java/gregtech/api/objects/iterators/NonNullIterator.java +++ /dev/null @@ -1,36 +0,0 @@ -package gregtech.api.objects.iterators; - -import java.util.Iterator; - -public class NonNullIterator implements Iterator { - private final Iterator internal; - private T last = null; - - public NonNullIterator(Iterator in) { - this.internal = in; - } - - @Override - public boolean hasNext() { - while (last == null) { - if (internal.hasNext()) { - last = internal.next(); - } else { - return false; - } - } - - return true; - } - - @Override - public T next() { - while (last == null) { - last = internal.next(); - } - - T temp = last; - last = null; - return temp; - } -} diff --git a/src/main/java/gregtech/api/util/extensions/IteratorExt.java b/src/main/java/gregtech/api/util/extensions/IteratorExt.java index 1a29a7b41a..d59bb298a4 100644 --- a/src/main/java/gregtech/api/util/extensions/IteratorExt.java +++ b/src/main/java/gregtech/api/util/extensions/IteratorExt.java @@ -1,8 +1,6 @@ package gregtech.api.util.extensions; -import gregtech.api.objects.iterators.ArrayIterator; import gregtech.api.objects.iterators.MergedIterator; -import gregtech.api.objects.iterators.NonNullIterator; import java.util.Iterator; @@ -11,13 +9,4 @@ public class IteratorExt { public static Iterator merge(Iterator... iterators) { return new MergedIterator<>(iterators); } - - public static Iterator withoutNulls(Iterator iterator) { - return new NonNullIterator<>(iterator); - } - - @SafeVarargs - public static ArrayIterator ofArray(T... items) { - return new ArrayIterator<>(items); - } } -- cgit From 7494ea5645fb76aec16f9852ebf3454f1fd197c4 Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Tue, 3 Aug 2021 20:44:17 -0600 Subject: Add disassembler restrictions bypass --- src/main/java/gregtech/api/util/GT_Recipe.java | 2 ++ .../basic/GT_MetaTileEntity_Disassembler.java | 29 +++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 19f46dfd15..e10d58cd75 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -572,6 +572,8 @@ public class GT_Recipe implements Comparable { public static final GT_Recipe_Map sRecyclerRecipes = new GT_Recipe_Map_Recycler(new HashSet<>(0), "ic.recipe.recycler", "Recycler", "ic2.recycler", RES_PATH_GUI + "basicmachines/Recycler", 1, 1, 1, 0, 1, E, 1, E, true, false); public static final GT_Recipe_Map sFurnaceRecipes = new GT_Recipe_Map_Furnace(new HashSet<>(0), "mc.recipe.furnace", "Furnace", "smelting", RES_PATH_GUI + "basicmachines/E_Furnace", 1, 1, 1, 0, 1, E, 1, E, true, false); public static final GT_Recipe_Map sMicrowaveRecipes = new GT_Recipe_Map_Microwave(new HashSet<>(0), "gt.recipe.microwave", "Microwave", "smelting", RES_PATH_GUI + "basicmachines/E_Furnace", 1, 1, 1, 0, 1, E, 1, E, true, false); + + /** Set {@code aSpecialValue = -100} to bypass the disassembler tier check and default recipe duration. */ public static final GT_Recipe_Map sDisassemblerRecipes = new GT_Recipe_Map(new HashSet<>(250), "gt.recipe.disassembler", "Disassembler", null, RES_PATH_GUI + "basicmachines/Disassembler", 1, 9, 1, 0, 1, E, 1, E, true, false); public static final GT_Recipe_Map sScannerFakeRecipes = new GT_Recipe_Map(new HashSet<>(300), "gt.recipe.scanner", "Scanner", null, RES_PATH_GUI + "basicmachines/Scanner", 1, 1, 1, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sRockBreakerFakeRecipes = new GT_Recipe_Map(new HashSet<>(200), "gt.recipe.rockbreaker", "Rock Breaker", null, RES_PATH_GUI + "basicmachines/RockBreaker", 1, 1, 0, 0, 1, E, 1, E, true, true); diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java index b820dd44fd..13eefcd7a6 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java @@ -172,9 +172,6 @@ public class GT_MetaTileEntity_Disassembler extends GT_MetaTileEntity_BasicMachi ) return DID_NOT_FIND_RECIPE; - if (checkTier(is)) - return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; - Integer handleHardOverride = handleHardOverride(is); if (handleHardOverride != null) return handleHardOverride; @@ -241,17 +238,31 @@ public class GT_MetaTileEntity_Disassembler extends GT_MetaTileEntity_BasicMachi GT_Recipe gt_recipe = GT_Recipe.GT_Recipe_Map.sDisassemblerRecipes.findRecipe(this.getBaseMetaTileEntity(), true, this.maxEUInput(), null, this.getAllInputs()); if (gt_recipe == null) return DID_NOT_FIND_RECIPE; - if (gt_recipe.isRecipeInputEqual(false, null, this.getAllInputs())) - return setOutputsAndTime(gt_recipe.mOutputs, gt_recipe.mInputs[0].stackSize) - ? FOUND_AND_SUCCESSFULLY_USED_RECIPE - : FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; + if (gt_recipe.isRecipeInputEqual(false, null, this.getAllInputs())) { + if (gt_recipe.mSpecialValue == -100) { + // Bypass standard disassembler restrictions. + this.getInputAt(0).stackSize -= gt_recipe.mInputs[0].stackSize; + System.arraycopy(gt_recipe.mOutputs, 0, this.mOutputItems, 0, gt_recipe.mOutputs.length); + + this.calculateOverclockedNess(gt_recipe); + return FOUND_AND_SUCCESSFULLY_USED_RECIPE; + } else { + return setOutputsAndTime(gt_recipe.mOutputs, gt_recipe.mInputs[0].stackSize) + ? FOUND_AND_SUCCESSFULLY_USED_RECIPE + : FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; + } + } return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; } private boolean setOutputsAndTime(ItemStack[] inputs, int stackSize){ - if (this.getInputAt(0).stackSize >= stackSize) - this.getInputAt(0).stackSize -= stackSize; + ItemStack machineInput = this.getInputAt(0); + if (checkTier(machineInput)) + return false; + + if (machineInput.stackSize >= stackSize) + machineInput.stackSize -= stackSize; else return false; -- cgit From 05505604c98a63b66171ea8a0ed9a2cdce407d37 Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Sat, 7 Aug 2021 02:06:44 -0600 Subject: Add number formatting for tooltips & recipes --- build.properties | 2 +- .../GT_MetaTileEntity_Hatch_Input.java | 4 +++- .../GT_MetaTileEntity_Hatch_Output.java | 2 +- src/main/java/gregtech/api/util/GT_Utility.java | 27 ++++++++++++++++++++++ .../gregtech/common/blocks/GT_Item_Machines.java | 8 +++---- .../java/gregtech/nei/GT_NEI_AssLineHandler.java | 8 +++---- .../java/gregtech/nei/GT_NEI_DefaultHandler.java | 10 ++++---- 7 files changed, 45 insertions(+), 16 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/build.properties b/build.properties index 9c6f282480..407cf4ff61 100644 --- a/build.properties +++ b/build.properties @@ -1,6 +1,6 @@ minecraft.version=1.7.10 forge.version=10.13.4.1614-1.7.10 -gt.version=5.09.37.06 +gt.version=5.09.37.07 structurelib.version=1.0.6 ae2.version=rv3-beta-22 applecore.version=1.7.10-1.2.1+107.59407 diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Input.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Input.java index e37d2160a2..fd7eb0fc94 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Input.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Input.java @@ -16,7 +16,9 @@ public class GT_MetaTileEntity_Hatch_Input extends GT_MetaTileEntity_Hatch { public GT_Recipe_Map mRecipeMap = null; public GT_MetaTileEntity_Hatch_Input(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 3, new String[]{"Fluid Input for Multiblocks", "Capacity: " + (8000+8000*(aTier*(aTier+1)>>1)) + "L"}); + super(aID, aName, aNameRegional, aTier, 3, new String[]{ + "Fluid Input for Multiblocks", + "Capacity: " + GT_Utility.formatNumbers(8000+8000*(aTier*(aTier+1)>>1)) + "L"}); } public GT_MetaTileEntity_Hatch_Input(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java index 9965b88a17..db80c4685b 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java @@ -27,7 +27,7 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { public GT_MetaTileEntity_Hatch_Output(int aID, String aName, String aNameRegional, int aTier) { super(aID, aName, aNameRegional, aTier, 3, new String[]{ "Fluid Output for Multiblocks", - "Capacity: " + (8000+8000*(aTier*(aTier+1)>>1)) + "L", + "Capacity: " + GT_Utility.formatNumbers(8000+8000*(aTier*(aTier+1)>>1)) + "L", "Right click with screwdriver to restrict output", "Can be restricted to put out Items and/or Steam/No Steam/1 specific Fluid", "Restricted Output Hatches are given priority for Multiblock Fluid output"}); diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 94195d76ce..29aa1a561a 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -2224,9 +2224,36 @@ public class GT_Utility { DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US); DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols(); symbols.setGroupingSeparator(' '); + formatter.setDecimalFormatSymbols(symbols); return formatter.format(aNumber); } + /** + * Formats a positive integer with grouping separators, and also attempts to display it as a (small multiple of a) + * power of 2. + */ + public static String formatPow2(long number) { + String formatted = formatNumbers(number); + if (number == V[V.length - 1]) { + formatted += " (MAX)"; + } else if (number >= 256) { + // Try to figure out if number is a (small multiple of a) power of 2. + long curr = number; + int pow = 0; + while ((curr & 1) == 0) { + curr = curr >>> 1; + pow++; + } + + if (curr == 1) { + formatted += String.format(" (2^%d)", pow); + } else if (curr <= 7) { + formatted += String.format(" (%d*2^%d)", curr, pow); + } + } + return formatted; + } + /* * Check if stack has enough items of given type and subtract from stack, if there's no creative or 111 stack. */ diff --git a/src/main/java/gregtech/common/blocks/GT_Item_Machines.java b/src/main/java/gregtech/common/blocks/GT_Item_Machines.java index c8e77f9b0a..ee99c8a053 100644 --- a/src/main/java/gregtech/common/blocks/GT_Item_Machines.java +++ b/src/main/java/gregtech/common/blocks/GT_Item_Machines.java @@ -70,16 +70,16 @@ public class GT_Item_Machines extends ItemBlock { if (tTileEntity.getEUCapacity() > 0L) { if (tTileEntity.getInputVoltage() > 0L) { int inputTier = GT_Utility.getTier(tTileEntity.getInputVoltage()); - aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_IN", "Voltage IN: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + tTileEntity.getInputVoltage() + " (" + GT_Values.TIER_COLORS[inputTier] + GT_Values.VN[inputTier] + EnumChatFormatting.GREEN +")" + EnumChatFormatting.GRAY); + aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_IN", "Voltage IN: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + GT_Utility.formatPow2(tTileEntity.getInputVoltage()) + " (" + GT_Values.TIER_COLORS[inputTier] + GT_Values.VN[inputTier] + EnumChatFormatting.GREEN +")" + EnumChatFormatting.GRAY); } if (tTileEntity.getOutputVoltage() > 0L) { int outputTier = GT_Utility.getTier(tTileEntity.getOutputVoltage()); - aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_OUT", "Voltage OUT: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + tTileEntity.getOutputVoltage() + " (" + GT_Values.TIER_COLORS[outputTier] + GT_Values.VN[outputTier] + EnumChatFormatting.GREEN + ")" + EnumChatFormatting.GRAY); + aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_OUT", "Voltage OUT: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + GT_Utility.formatPow2(tTileEntity.getOutputVoltage()) + " (" + GT_Values.TIER_COLORS[outputTier] + GT_Values.VN[outputTier] + EnumChatFormatting.GREEN + ")" + EnumChatFormatting.GRAY); } if (tTileEntity.getOutputAmperage() > 1L) { - aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_AMOUNT", "Amperage: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.YELLOW + tTileEntity.getOutputAmperage() + EnumChatFormatting.GRAY); + aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_AMOUNT", "Amperage: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.YELLOW + GT_Utility.formatPow2(tTileEntity.getOutputAmperage()) + EnumChatFormatting.GRAY); } - aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_STORE", "Capacity: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.BLUE + tTileEntity.getEUCapacity() + EnumChatFormatting.GRAY); + aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_STORE", "Capacity: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.BLUE + GT_Utility.formatPow2(tTileEntity.getEUCapacity()) + EnumChatFormatting.GRAY); } } NBTTagCompound aNBT = aStack.getTagCompound(); diff --git a/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java b/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java index c692a2dce1..b9cd8ef687 100644 --- a/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java @@ -235,11 +235,11 @@ public class GT_NEI_AssLineHandler extends TemplateRecipeHandler { String[] recipeDesc = ((CachedDefaultRecipe) this.arecipes.get(aRecipeIndex)).mRecipe.getNeiDesc(); if (recipeDesc == null) { if (tEUt != 0) { - drawText(10, 73, trans("152","Total: ") + ((long)tDuration * tEUt) + " EU", -16777216); - drawText(10, 83, trans("153","Usage: ") + tEUt + " EU/t", -16777216); + drawText(10, 73, trans("152","Total: ") + GT_Utility.formatNumbers((long)tDuration * tEUt) + " EU", -16777216); + drawText(10, 83, trans("153","Usage: ") + GT_Utility.formatNumbers(tEUt) + " EU/t", -16777216); if (this.mRecipeMap.mShowVoltageAmperageInNEI) { - drawText(10, 93, trans("154","Voltage: ") + tEUt / this.mRecipeMap.mAmperage + " EU", -16777216); - drawText(10, 103, trans("155","Amperage: ") + this.mRecipeMap.mAmperage, -16777216); + drawText(10, 93, trans("154","Voltage: ") + GT_Utility.formatNumbers(tEUt / this.mRecipeMap.mAmperage) + " EU", -16777216); + drawText(10, 103, trans("155","Amperage: ") + GT_Utility.formatNumbers(this.mRecipeMap.mAmperage), -16777216); } else { drawText(10, 93, trans("156","Voltage: unspecified"), -16777216); drawText(10, 103, trans("157","Amperage: unspecified"), -16777216); diff --git a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java index a4fc75a24e..2e9a265ff9 100644 --- a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java @@ -217,16 +217,16 @@ public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { String[] recipeDesc = ((CachedDefaultRecipe) this.arecipes.get(aRecipeIndex)).mRecipe.getNeiDesc(); if (recipeDesc == null) { if (tEUt != 0) { - drawText(10, 73, trans("152","Total: ") + ((long)tDuration * tEUt) + " EU", -16777216); - drawText(10, 83, trans("153","Usage: ") + tEUt + " EU/t", -16777216); + drawText(10, 73, trans("152","Total: ") + GT_Utility.formatNumbers((long)tDuration * tEUt) + " EU", -16777216); + drawText(10, 83, trans("153","Usage: ") + GT_Utility.formatNumbers(tEUt) + " EU/t", -16777216); if (this.mRecipeMap.mShowVoltageAmperageInNEI) { byte tier=GT_Utility.getTier(tEUt / this.mRecipeMap.mAmperage); if(tier<0||tier>=16){ - drawText(10, 93, trans("154","Voltage: ") + tEUt / this.mRecipeMap.mAmperage + " EU", 0xffFF0000); + drawText(10, 93, trans("154","Voltage: ") + GT_Utility.formatNumbers(tEUt / this.mRecipeMap.mAmperage) + " EU", 0xffFF0000); //add here gt logger }else{ - drawText(10, 93, trans("154","Voltage: ") + tEUt / this.mRecipeMap.mAmperage + " EU ("+GT_Values.VN[tier]+")", -16777216); - }drawText(10, 103, trans("155","Amperage: ") + this.mRecipeMap.mAmperage, -16777216); + drawText(10, 93, trans("154","Voltage: ") + GT_Utility.formatNumbers(tEUt / this.mRecipeMap.mAmperage) + " EU ("+GT_Values.VN[tier]+")", -16777216); + }drawText(10, 103, trans("155","Amperage: ") + GT_Utility.formatNumbers(this.mRecipeMap.mAmperage), -16777216); } else { drawText(10, 93, trans("156","Voltage: unspecified"), -16777216); drawText(10, 103, trans("157","Amperage: unspecified"), -16777216); -- cgit From 3408222951008c37ad81fbab1aa455501e68026b Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Sat, 7 Aug 2021 02:29:58 -0600 Subject: Also format recipe time --- src/main/java/gregtech/api/util/GT_Utility.java | 9 +++++++++ src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java | 2 +- src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 29aa1a561a..4ae785c50f 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -2228,6 +2228,15 @@ public class GT_Utility { return formatter.format(aNumber); } + public static String formatNumbers(double aNumber) { + DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US); + DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols(); + symbols.setGroupingSeparator(' '); + formatter.setDecimalFormatSymbols(symbols); + formatter.setMaximumFractionDigits(2); + return formatter.format(aNumber); + } + /** * Formats a positive integer with grouping separators, and also attempts to display it as a (small multiple of a) * power of 2. diff --git a/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java b/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java index b9cd8ef687..513b0b7552 100644 --- a/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java @@ -246,7 +246,7 @@ public class GT_NEI_AssLineHandler extends TemplateRecipeHandler { } } if (tDuration > 0) { - drawText(10, 113, trans("158","Time: ")+String.format("%.2f " + trans("161"," secs"), 0.05F * tDuration), -16777216); + drawText(10, 113, trans("158","Time: ") + GT_Utility.formatNumbers(0.05d * tDuration) + trans("161"," secs"), -16777216); } int tSpecial = ((CachedDefaultRecipe) this.arecipes.get(aRecipeIndex)).mRecipe.mSpecialValue; if (tSpecial == -100 && GT_Mod.gregtechproxy.mLowGravProcessing) { diff --git a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java index 2e9a265ff9..f8aa9a015e 100644 --- a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java @@ -233,7 +233,7 @@ public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { } } if (tDuration > 0) { - drawText(10, 113, trans("158","Time: ")+String.format("%.2f " + trans("161"," secs"), 0.05F * tDuration), -16777216); + drawText(10, 113, trans("158","Time: ") + GT_Utility.formatNumbers(0.05d * tDuration) + trans("161"," secs"), -16777216); } int tSpecial = ((CachedDefaultRecipe) this.arecipes.get(aRecipeIndex)).mRecipe.mSpecialValue; if (tSpecial == -100 && GT_Mod.gregtechproxy.mLowGravProcessing) { -- cgit From bbabaa92f82c14f49fbd968f1a14dfdb5c7aeeaa Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Sat, 7 Aug 2021 02:55:54 -0600 Subject: Add warning comment just in case --- src/main/java/gregtech/api/util/GT_Utility.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 4ae785c50f..e57014239c 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -2249,7 +2249,7 @@ public class GT_Utility { // Try to figure out if number is a (small multiple of a) power of 2. long curr = number; int pow = 0; - while ((curr & 1) == 0) { + while ((curr & 1) == 0) { // N.B. this won't terminate if curr == 0 curr = curr >>> 1; pow++; } -- cgit From b470fee172543879f24fd9f43395686db808d045 Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Sat, 7 Aug 2021 05:32:43 -0600 Subject: Make DecimalFormat static --- src/main/java/gregtech/api/util/GT_Utility.java | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 4ae785c50f..d55dbd7d06 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -79,7 +79,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; -import java.text.NumberFormat; import java.util.*; import java.util.Map.Entry; import java.util.function.IntFunction; @@ -95,6 +94,7 @@ import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; * Just a few Utility Functions I use. */ public class GT_Utility { + private static final DecimalFormat decimalFormat = new DecimalFormat(); /** * Forge screwed the Fluid Registry up again, so I make my own, which is also much more efficient than the stupid Stuff over there. */ @@ -108,6 +108,11 @@ public class GT_Utility { public static UUID defaultUuid = null; // maybe default non-null? UUID.fromString("00000000-0000-0000-0000-000000000000"); static { + DecimalFormatSymbols symbols = decimalFormat.getDecimalFormatSymbols(); + symbols.setGroupingSeparator(' '); + decimalFormat.setDecimalFormatSymbols(symbols); + decimalFormat.setMaximumFractionDigits(2); + GregTech_API.sItemStackMappings.add(sFilledContainerToData); GregTech_API.sItemStackMappings.add(sEmptyContainerToFluidToData); } @@ -2221,20 +2226,11 @@ public class GT_Utility { } public static String formatNumbers(long aNumber) { - DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US); - DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols(); - symbols.setGroupingSeparator(' '); - formatter.setDecimalFormatSymbols(symbols); - return formatter.format(aNumber); + return decimalFormat.format(aNumber); } public static String formatNumbers(double aNumber) { - DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US); - DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols(); - symbols.setGroupingSeparator(' '); - formatter.setDecimalFormatSymbols(symbols); - formatter.setMaximumFractionDigits(2); - return formatter.format(aNumber); + return decimalFormat.format(aNumber); } /** -- cgit From 72c54aa140492f25d3ce4a03d61abb7de9642f87 Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Sat, 7 Aug 2021 14:50:43 -0600 Subject: Print powers of 10 instead, for large numbers only --- .../implementations/GT_MetaPipeEntity_Cable.java | 6 +-- src/main/java/gregtech/api/util/GT_Utility.java | 46 ++++++++-------------- .../gregtech/common/blocks/GT_Item_Machines.java | 8 ++-- 3 files changed, 23 insertions(+), 37 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java index c5a33f7ae0..b4396aec3e 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java @@ -329,9 +329,9 @@ public class GT_MetaPipeEntity_Cable extends MetaPipeEntity implements IMetaTile @Override public String[] getDescription() { return new String[]{ - "Max Voltage: %%%" + EnumChatFormatting.GREEN + GT_Utility.formatPow2(mVoltage) + " (" + VN[GT_Utility.getTier(mVoltage)] + ")" + EnumChatFormatting.GRAY, - "Max Amperage: %%%" + EnumChatFormatting.YELLOW + GT_Utility.formatPow2(mAmperage) + EnumChatFormatting.GRAY, - "Loss/Meter/Ampere: %%%" + EnumChatFormatting.RED + GT_Utility.formatPow2(mCableLossPerMeter) + EnumChatFormatting.GRAY + "%%% EU-Volt" + "Max Voltage: %%%" + EnumChatFormatting.GREEN + GT_Utility.formatNumbers(mVoltage) + " (" + VN[GT_Utility.getTier(mVoltage)] + ")" + EnumChatFormatting.GRAY, + "Max Amperage: %%%" + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(mAmperage) + EnumChatFormatting.GRAY, + "Loss/Meter/Ampere: %%%" + EnumChatFormatting.RED + GT_Utility.formatNumbers(mCableLossPerMeter) + EnumChatFormatting.GRAY + "%%% EU-Volt" }; } diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index da5c902c0e..f1f83c3c14 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -94,7 +94,11 @@ import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; * Just a few Utility Functions I use. */ public class GT_Utility { - private static final DecimalFormat decimalFormat = new DecimalFormat(); + /** Formats a number with group separator and at most 2 fraction digits. */ + private static final DecimalFormat basicFormatter = new DecimalFormat(); + /** Formats a number into scientific notation with at most 2 fraction digits. Meant for large numbers. */ + private static final DecimalFormat scientificNotationFormatter = new DecimalFormat("0.##E0"); + /** * Forge screwed the Fluid Registry up again, so I make my own, which is also much more efficient than the stupid Stuff over there. */ @@ -108,10 +112,10 @@ public class GT_Utility { public static UUID defaultUuid = null; // maybe default non-null? UUID.fromString("00000000-0000-0000-0000-000000000000"); static { - DecimalFormatSymbols symbols = decimalFormat.getDecimalFormatSymbols(); + DecimalFormatSymbols symbols = basicFormatter.getDecimalFormatSymbols(); symbols.setGroupingSeparator(' '); - decimalFormat.setDecimalFormatSymbols(symbols); - decimalFormat.setMaximumFractionDigits(2); + basicFormatter.setDecimalFormatSymbols(symbols); + basicFormatter.setMaximumFractionDigits(2); GregTech_API.sItemStackMappings.add(sFilledContainerToData); GregTech_API.sItemStackMappings.add(sEmptyContainerToFluidToData); @@ -2226,35 +2230,17 @@ public class GT_Utility { } public static String formatNumbers(long aNumber) { - return decimalFormat.format(aNumber); + String formatted = basicFormatter.format(aNumber); + if (aNumber >= 1_000_000_000L) { + formatted += " [" + scientificNotationFormatter.format(aNumber) + "]"; + } + return formatted; } public static String formatNumbers(double aNumber) { - return decimalFormat.format(aNumber); - } - - /** - * Formats a positive integer with grouping separators, and also attempts to display it as a (small multiple of a) - * power of 2. - */ - public static String formatPow2(long number) { - String formatted = formatNumbers(number); - if (number == V[V.length - 1]) { - formatted += " (MAX)"; - } else if (number >= 256) { - // Try to figure out if number is a (small multiple of a) power of 2. - long curr = number; - int pow = 0; - while ((curr & 1) == 0) { // N.B. this won't terminate if curr == 0 - curr = curr >>> 1; - pow++; - } - - if (curr == 1) { - formatted += String.format(" (2^%d)", pow); - } else if (curr <= 7) { - formatted += String.format(" (%d*2^%d)", curr, pow); - } + String formatted = basicFormatter.format(aNumber); + if (aNumber >= 1_000_000_000d) { + formatted += " [" + scientificNotationFormatter.format(aNumber) + "]"; } return formatted; } diff --git a/src/main/java/gregtech/common/blocks/GT_Item_Machines.java b/src/main/java/gregtech/common/blocks/GT_Item_Machines.java index 4be48b902d..74e3e3653d 100644 --- a/src/main/java/gregtech/common/blocks/GT_Item_Machines.java +++ b/src/main/java/gregtech/common/blocks/GT_Item_Machines.java @@ -70,16 +70,16 @@ public class GT_Item_Machines extends ItemBlock { if (tTileEntity.getEUCapacity() > 0L) { if (tTileEntity.getInputVoltage() > 0L) { int inputTier = GT_Utility.getTier(tTileEntity.getInputVoltage()); - aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_IN", "Voltage IN: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + GT_Utility.formatPow2(tTileEntity.getInputVoltage()) + " (" + GT_Values.TIER_COLORS[inputTier] + GT_Values.VN[inputTier] + EnumChatFormatting.GREEN +")" + EnumChatFormatting.GRAY); + aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_IN", "Voltage IN: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + GT_Utility.formatNumbers(tTileEntity.getInputVoltage()) + " (" + GT_Values.TIER_COLORS[inputTier] + GT_Values.VN[inputTier] + EnumChatFormatting.GREEN +")" + EnumChatFormatting.GRAY); } if (tTileEntity.getOutputVoltage() > 0L) { int outputTier = GT_Utility.getTier(tTileEntity.getOutputVoltage()); - aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_OUT", "Voltage OUT: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + GT_Utility.formatPow2(tTileEntity.getOutputVoltage()) + " (" + GT_Values.TIER_COLORS[outputTier] + GT_Values.VN[outputTier] + EnumChatFormatting.GREEN + ")" + EnumChatFormatting.GRAY); + aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_OUT", "Voltage OUT: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + GT_Utility.formatNumbers(tTileEntity.getOutputVoltage()) + " (" + GT_Values.TIER_COLORS[outputTier] + GT_Values.VN[outputTier] + EnumChatFormatting.GREEN + ")" + EnumChatFormatting.GRAY); } if (tTileEntity.getOutputAmperage() > 1L) { - aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_AMOUNT", "Amperage: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.YELLOW + GT_Utility.formatPow2(tTileEntity.getOutputAmperage()) + EnumChatFormatting.GRAY); + aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_AMOUNT", "Amperage: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(tTileEntity.getOutputAmperage()) + EnumChatFormatting.GRAY); } - aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_STORE", "Capacity: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.BLUE + GT_Utility.formatPow2(tTileEntity.getEUCapacity()) + EnumChatFormatting.GRAY); + aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_STORE", "Capacity: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.BLUE + GT_Utility.formatNumbers(tTileEntity.getEUCapacity()) + EnumChatFormatting.GRAY); } } NBTTagCompound aNBT = aStack.getTagCompound(); -- cgit From 324c870597aef034712d80571f072cb45d609aee Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Sun, 8 Aug 2021 07:41:35 -0600 Subject: Remove scientific notation formatter --- src/main/java/gregtech/api/util/GT_Utility.java | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index f1f83c3c14..6ac69f55b3 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -95,9 +95,7 @@ import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; */ public class GT_Utility { /** Formats a number with group separator and at most 2 fraction digits. */ - private static final DecimalFormat basicFormatter = new DecimalFormat(); - /** Formats a number into scientific notation with at most 2 fraction digits. Meant for large numbers. */ - private static final DecimalFormat scientificNotationFormatter = new DecimalFormat("0.##E0"); + private static final DecimalFormat decimalFormat = new DecimalFormat(); /** * Forge screwed the Fluid Registry up again, so I make my own, which is also much more efficient than the stupid Stuff over there. @@ -112,10 +110,10 @@ public class GT_Utility { public static UUID defaultUuid = null; // maybe default non-null? UUID.fromString("00000000-0000-0000-0000-000000000000"); static { - DecimalFormatSymbols symbols = basicFormatter.getDecimalFormatSymbols(); + DecimalFormatSymbols symbols = decimalFormat.getDecimalFormatSymbols(); symbols.setGroupingSeparator(' '); - basicFormatter.setDecimalFormatSymbols(symbols); - basicFormatter.setMaximumFractionDigits(2); + decimalFormat.setDecimalFormatSymbols(symbols); + decimalFormat.setMaximumFractionDigits(2); GregTech_API.sItemStackMappings.add(sFilledContainerToData); GregTech_API.sItemStackMappings.add(sEmptyContainerToFluidToData); @@ -2230,19 +2228,11 @@ public class GT_Utility { } public static String formatNumbers(long aNumber) { - String formatted = basicFormatter.format(aNumber); - if (aNumber >= 1_000_000_000L) { - formatted += " [" + scientificNotationFormatter.format(aNumber) + "]"; - } - return formatted; + return decimalFormat.format(aNumber); } public static String formatNumbers(double aNumber) { - String formatted = basicFormatter.format(aNumber); - if (aNumber >= 1_000_000_000d) { - formatted += " [" + scientificNotationFormatter.format(aNumber) + "]"; - } - return formatted; + return decimalFormat.format(aNumber); } /* -- cgit From d577f73e8f33b2c6e04110ceddf35a59bc958716 Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Sun, 8 Aug 2021 10:57:14 -0600 Subject: Add formatting to getCoordinateScan() --- src/main/java/gregtech/api/util/GT_Utility.java | 70 +++++++++++++++++-------- 1 file changed, 48 insertions(+), 22 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 6ac69f55b3..77194a7bff 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -1912,15 +1912,25 @@ public class GT_Utility { Block tBlock = aWorld.getBlock(aX, aY, aZ); - tList.add("----- X: " +EnumChatFormatting.AQUA+ aX +EnumChatFormatting.RESET+ " Y: " +EnumChatFormatting.AQUA+ aY +EnumChatFormatting.RESET+ " Z: " +EnumChatFormatting.AQUA+ aZ +EnumChatFormatting.RESET+ " D: " +EnumChatFormatting.AQUA+ aWorld.provider.dimensionId +EnumChatFormatting.RESET+ " -----"); + tList.add( + "----- X: " + EnumChatFormatting.AQUA + formatNumbers(aX) + EnumChatFormatting.RESET + + " Y: " + EnumChatFormatting.AQUA + formatNumbers(aY) + EnumChatFormatting.RESET + + " Z: " + EnumChatFormatting.AQUA + formatNumbers(aZ) + EnumChatFormatting.RESET + + " D: " + EnumChatFormatting.AQUA + aWorld.provider.dimensionId + EnumChatFormatting.RESET + " -----"); try { if (tTileEntity instanceof IInventory) - tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ ((IInventory) tTileEntity).getInventoryName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET); + tList.add( + trans("162","Name: ") + EnumChatFormatting.BLUE + ((IInventory) tTileEntity).getInventoryName() + EnumChatFormatting.RESET + + trans("163"," MetaData: ") + EnumChatFormatting.AQUA + aWorld.getBlockMetadata(aX, aY, aZ) + EnumChatFormatting.RESET); else - tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ tBlock.getUnlocalizedName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET); - - tList.add(trans("164","Hardness: ") +EnumChatFormatting.YELLOW+ tBlock.getBlockHardness(aWorld, aX, aY, aZ) +EnumChatFormatting.RESET+ trans("165"," Blast Resistance: ") +EnumChatFormatting.YELLOW+ tBlock.getExplosionResistance(aPlayer, aWorld, aX, aY, aZ, aPlayer.posX, aPlayer.posY, aPlayer.posZ) +EnumChatFormatting.RESET); - if (tBlock.isBeaconBase(aWorld, aX, aY, aZ, aX, aY + 1, aZ)) tList.add(EnumChatFormatting.GOLD+ trans("166","Is valid Beacon Pyramid Material") +EnumChatFormatting.RESET); + tList.add( + trans("162","Name: ") + EnumChatFormatting.BLUE + tBlock.getUnlocalizedName() + EnumChatFormatting.RESET + + trans("163"," MetaData: ") + EnumChatFormatting.AQUA + aWorld.getBlockMetadata(aX, aY, aZ) + EnumChatFormatting.RESET); + + tList.add( + trans("164","Hardness: ") + EnumChatFormatting.YELLOW + tBlock.getBlockHardness(aWorld, aX, aY, aZ) + EnumChatFormatting.RESET + + trans("165"," Blast Resistance: ") + EnumChatFormatting.YELLOW + tBlock.getExplosionResistance(aPlayer, aWorld, aX, aY, aZ, aPlayer.posX, aPlayer.posY, aPlayer.posZ) + EnumChatFormatting.RESET); + if (tBlock.isBeaconBase(aWorld, aX, aY, aZ, aX, aY + 1, aZ)) tList.add(EnumChatFormatting.GOLD + trans("166","Is valid Beacon Pyramid Material") + EnumChatFormatting.RESET); } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); } @@ -1930,7 +1940,10 @@ public class GT_Utility { rEUAmount += 500; FluidTankInfo[] tTanks = ((IFluidHandler) tTileEntity).getTankInfo(ForgeDirection.getOrientation(aSide)); if (tTanks != null) for (byte i = 0; i < tTanks.length; i++) { - tList.add(trans("167","Tank ") + i + ": " +EnumChatFormatting.GREEN+ formatNumbers((tTanks[i].fluid == null ? 0 : tTanks[i].fluid.amount)) +EnumChatFormatting.RESET+ " L / " +EnumChatFormatting.YELLOW+ formatNumbers(tTanks[i].capacity) +EnumChatFormatting.RESET+ " L " +EnumChatFormatting.GOLD+ getFluidName(tTanks[i].fluid, true)+EnumChatFormatting.RESET); + tList.add( + trans("167","Tank ") + i + ": " + + EnumChatFormatting.GREEN + formatNumbers((tTanks[i].fluid == null ? 0 : tTanks[i].fluid.amount)) + EnumChatFormatting.RESET + " L / " + + EnumChatFormatting.YELLOW + formatNumbers(tTanks[i].capacity) + EnumChatFormatting.RESET + " L " + EnumChatFormatting.GOLD + getFluidName(tTanks[i].fluid, true) + EnumChatFormatting.RESET); } } } catch (Throwable e) { @@ -1947,8 +1960,12 @@ public class GT_Utility { try { if (tTileEntity instanceof ic2.api.reactor.IReactor) { rEUAmount += 500; - tList.add(trans("168","Heat: ") +EnumChatFormatting.GREEN+ ((ic2.api.reactor.IReactor) tTileEntity).getHeat() +EnumChatFormatting.RESET+ " / " +EnumChatFormatting.YELLOW+ ((ic2.api.reactor.IReactor) tTileEntity).getMaxHeat()+EnumChatFormatting.RESET); - tList.add(trans("169","HEM: ") +EnumChatFormatting.YELLOW+((ic2.api.reactor.IReactor) tTileEntity).getHeatEffectModifier() +EnumChatFormatting.RESET/*+ trans("170"," Base EU Output: ")/* + ((ic2.api.reactor.IReactor)tTileEntity).getOutput()*/); + tList.add( + trans("168","Heat: ") + EnumChatFormatting.GREEN + formatNumbers(((ic2.api.reactor.IReactor) tTileEntity).getHeat()) + EnumChatFormatting.RESET + " / " + + EnumChatFormatting.YELLOW + formatNumbers(((ic2.api.reactor.IReactor) tTileEntity).getMaxHeat()) + EnumChatFormatting.RESET); + tList.add( + trans("169","HEM: ") + EnumChatFormatting.YELLOW + ((ic2.api.reactor.IReactor) tTileEntity).getHeatEffectModifier() + EnumChatFormatting.RESET + /* + trans("170"," Base EU Output: ")/* + ((ic2.api.reactor.IReactor)tTileEntity).getOutput()*/); } } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); @@ -2002,7 +2019,7 @@ public class GT_Utility { try { if (tTileEntity instanceof ic2.api.energy.tile.IEnergyConductor) { rEUAmount += 200; - tList.add(trans("175","Conduction Loss: ") +EnumChatFormatting.YELLOW+ ((ic2.api.energy.tile.IEnergyConductor) tTileEntity).getConductionLoss()+EnumChatFormatting.RESET); + tList.add(trans("175","Conduction Loss: ") + EnumChatFormatting.YELLOW + ((ic2.api.energy.tile.IEnergyConductor) tTileEntity).getConductionLoss() + EnumChatFormatting.RESET); } } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); @@ -2010,7 +2027,9 @@ public class GT_Utility { try { if (tTileEntity instanceof ic2.api.tile.IEnergyStorage) { rEUAmount += 200; - tList.add(trans("176","Contained Energy: ") +EnumChatFormatting.YELLOW+ ((ic2.api.tile.IEnergyStorage) tTileEntity).getStored() +EnumChatFormatting.RESET+ " EU / " +EnumChatFormatting.YELLOW+ ((ic2.api.tile.IEnergyStorage) tTileEntity).getCapacity()+EnumChatFormatting.RESET+" EU"); + tList.add( + trans("176","Contained Energy: ") + EnumChatFormatting.YELLOW + formatNumbers(((ic2.api.tile.IEnergyStorage) tTileEntity).getStored()) + EnumChatFormatting.RESET + " EU / " + + EnumChatFormatting.YELLOW + formatNumbers(((ic2.api.tile.IEnergyStorage) tTileEntity).getCapacity()) + EnumChatFormatting.RESET + " EU"); //aList.add(((ic2.api.tile.IEnergyStorage)tTileEntity).isTeleporterCompatible(ic2.api.Direction.YP)?"Teleporter Compatible":"Not Teleporter Compatible"); } } catch (Throwable e) { @@ -2019,7 +2038,7 @@ public class GT_Utility { try { if (tTileEntity instanceof IUpgradableMachine) { rEUAmount += 500; - if (((IUpgradableMachine) tTileEntity).hasMufflerUpgrade()) tList.add(EnumChatFormatting.GREEN+ trans("177","Has Muffler Upgrade") +EnumChatFormatting.RESET); + if (((IUpgradableMachine) tTileEntity).hasMufflerUpgrade()) tList.add(EnumChatFormatting.GREEN + trans("177","Has Muffler Upgrade") + EnumChatFormatting.RESET); } } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); @@ -2027,7 +2046,7 @@ public class GT_Utility { try { if (tTileEntity instanceof IMachineProgress) { if (((IMachineProgress) tTileEntity).isAllowedToWork()) { - tList.add("Disabled." + EnumChatFormatting.RED + EnumChatFormatting.RESET); + tList.add("Disabled." + EnumChatFormatting.RED + EnumChatFormatting.RESET); } if (((IMachineProgress) tTileEntity).wasShutdown()) { tList.add("Shut down due to power loss." + EnumChatFormatting.RED + EnumChatFormatting.RESET); @@ -2035,7 +2054,8 @@ public class GT_Utility { rEUAmount += 400; int tValue = 0; if (0 < (tValue = ((IMachineProgress) tTileEntity).getMaxProgress())) - tList.add(trans("178","Progress/Load: ") +EnumChatFormatting.GREEN+ formatNumbers(((IMachineProgress) tTileEntity).getProgress()) +EnumChatFormatting.RESET+ " / " +EnumChatFormatting.YELLOW+ formatNumbers(tValue) +EnumChatFormatting.RESET); + tList.add(trans("178","Progress/Load: ") + EnumChatFormatting.GREEN + formatNumbers(((IMachineProgress) tTileEntity).getProgress()) + EnumChatFormatting.RESET + " / " + + EnumChatFormatting.YELLOW + formatNumbers(tValue) + EnumChatFormatting.RESET); } } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); @@ -2051,16 +2071,22 @@ public class GT_Utility { } try { if (tTileEntity instanceof IBasicEnergyContainer && ((IBasicEnergyContainer) tTileEntity).getEUCapacity() > 0) { - tList.add(trans("179","Max IN: ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getInputVoltage() + " (" + GT_Values.VN[getTier(((IBasicEnergyContainer) tTileEntity).getInputVoltage())] + ") " +EnumChatFormatting.RESET+ trans("182"," EU at ") +EnumChatFormatting.RED+((IBasicEnergyContainer)tTileEntity).getInputAmperage()+EnumChatFormatting.RESET+trans("183"," A")); - tList.add(trans("181","Max OUT: ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getOutputVoltage() + " (" + GT_Values.VN[getTier(((IBasicEnergyContainer) tTileEntity).getOutputVoltage())] + ") " +EnumChatFormatting.RESET+ trans("182"," EU at ") +EnumChatFormatting.RED+ ((IBasicEnergyContainer) tTileEntity).getOutputAmperage() +EnumChatFormatting.RESET+ trans("183"," A")); - tList.add(trans("184","Energy: ") +EnumChatFormatting.GREEN+ formatNumbers(((IBasicEnergyContainer) tTileEntity).getStoredEU()) +EnumChatFormatting.RESET+ " EU / " +EnumChatFormatting.YELLOW+ formatNumbers(((IBasicEnergyContainer) tTileEntity).getEUCapacity()) +EnumChatFormatting.RESET+ " EU"); + tList.add( + trans("179","Max IN: ") + EnumChatFormatting.RED + formatNumbers(((IBasicEnergyContainer) tTileEntity).getInputVoltage()) + " (" + GT_Values.VN[getTier(((IBasicEnergyContainer) tTileEntity).getInputVoltage())] + ") " + EnumChatFormatting.RESET + + trans("182"," EU at ") + EnumChatFormatting.RED + formatNumbers(((IBasicEnergyContainer)tTileEntity).getInputAmperage()) + EnumChatFormatting.RESET + trans("183"," A")); + tList.add( + trans("181","Max OUT: ") + EnumChatFormatting.RED + formatNumbers(((IBasicEnergyContainer) tTileEntity).getOutputVoltage()) + " (" + GT_Values.VN[getTier(((IBasicEnergyContainer) tTileEntity).getOutputVoltage())] + ") " + EnumChatFormatting.RESET + + trans("182"," EU at ") + EnumChatFormatting.RED + formatNumbers(((IBasicEnergyContainer) tTileEntity).getOutputAmperage()) + EnumChatFormatting.RESET + trans("183"," A")); + tList.add( + trans("184","Energy: ") + EnumChatFormatting.GREEN + formatNumbers(((IBasicEnergyContainer) tTileEntity).getStoredEU()) + EnumChatFormatting.RESET + " EU / " + + EnumChatFormatting.YELLOW + formatNumbers(((IBasicEnergyContainer) tTileEntity).getEUCapacity()) + EnumChatFormatting.RESET + " EU"); } } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); } try { if (tTileEntity instanceof IGregTechTileEntity) { - tList.add(trans("186","Owned by: ") +EnumChatFormatting.BLUE+ ((IGregTechTileEntity) tTileEntity).getOwnerName()+EnumChatFormatting.RESET); + tList.add(trans("186","Owned by: ") + EnumChatFormatting.BLUE + ((IGregTechTileEntity) tTileEntity).getOwnerName() + EnumChatFormatting.RESET); } } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); @@ -2112,15 +2138,15 @@ public class GT_Utility { if (aPlayer.capabilities.isCreativeMode) { FluidStack tFluid = undergroundOilReadInformation(aWorld.getChunkFromBlockCoords(aX,aZ));//-# to only read if (tFluid!=null) - tList.add(EnumChatFormatting.GOLD+tFluid.getLocalizedName()+EnumChatFormatting.RESET+": " +EnumChatFormatting.YELLOW+ tFluid.amount +EnumChatFormatting.RESET+" L"); + tList.add(EnumChatFormatting.GOLD + tFluid.getLocalizedName() + EnumChatFormatting.RESET + ": " + EnumChatFormatting.YELLOW + formatNumbers(tFluid.amount) + EnumChatFormatting.RESET + " L"); else - tList.add(EnumChatFormatting.GOLD+trans("201","Nothing")+EnumChatFormatting.RESET+": " +EnumChatFormatting.YELLOW+ '0' +EnumChatFormatting.RESET+" L"); + tList.add(EnumChatFormatting.GOLD + trans("201","Nothing") + EnumChatFormatting.RESET + ": " + EnumChatFormatting.YELLOW + '0' + EnumChatFormatting.RESET + " L"); } // if(aPlayer.capabilities.isCreativeMode){ int[] chunkData = GT_Proxy.dimensionWiseChunkData.get(aWorld.provider.dimensionId).get(aWorld.getChunkFromBlockCoords(aX,aZ).getChunkCoordIntPair()); - if(chunkData !=null){ + if(chunkData != null){ if(chunkData[GTPOLLUTION]>0){ - tList.add(trans("202","Pollution in Chunk: ")+EnumChatFormatting.RED+chunkData[GTPOLLUTION]+EnumChatFormatting.RESET+trans("203"," gibbl")); + tList.add(trans("202","Pollution in Chunk: ") + EnumChatFormatting.RED + formatNumbers(chunkData[GTPOLLUTION]) + EnumChatFormatting.RESET + trans("203"," gibbl")); }else{ tList.add(EnumChatFormatting.GREEN+trans("204","No Pollution in Chunk! HAYO!")+EnumChatFormatting.RESET); } -- cgit From 915eafcfcaeb1d3b79d7ee85ac9e7da09a006a8c Mon Sep 17 00:00:00 2001 From: TimeConqueror Date: Tue, 10 Aug 2021 20:19:18 +0300 Subject: Added Damage Source Based on Hot Item (for gloves in GTNHCoreMod) --- .../api/damagesources/GT_DamageSources.java | 19 +++++++++- src/main/java/gregtech/api/util/GT_Utility.java | 18 ++++++--- src/main/java/gregtech/common/GT_Proxy.java | 43 +++++----------------- 3 files changed, 39 insertions(+), 41 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/damagesources/GT_DamageSources.java b/src/main/java/gregtech/api/damagesources/GT_DamageSources.java index fd13b9cfee..45f3fd5323 100644 --- a/src/main/java/gregtech/api/damagesources/GT_DamageSources.java +++ b/src/main/java/gregtech/api/damagesources/GT_DamageSources.java @@ -1,8 +1,11 @@ package gregtech.api.damagesources; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; import net.minecraft.util.*; +import javax.annotation.Nullable; + public class GT_DamageSources { public static DamageSource getElectricDamage() { return ic2.api.info.Info.DMG_ELECTRIC; @@ -33,7 +36,7 @@ public class GT_DamageSources { } private static class DamageSourceCombat extends EntityDamageSource { - private IChatComponent mDeathMessage; + private final IChatComponent mDeathMessage; public DamageSourceCombat(String aType, EntityLivingBase aPlayer, IChatComponent aDeathMessage) { super(aType, aPlayer); @@ -70,6 +73,20 @@ public class GT_DamageSources { } } + public static class DamageSourceHotItem extends DamageSourceHeat { + @Nullable + private final ItemStack stack; + + public DamageSourceHotItem(@Nullable ItemStack cause) { + this.stack = cause; + } + + @Nullable + public ItemStack getDamagingStack() { + return stack; + } + } + public static class DamageSourceExploding extends DamageSource { public DamageSourceExploding() { super("exploded"); diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 77194a7bff..28c6b266ec 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -9,6 +9,7 @@ import com.mojang.authlib.GameProfile; import cpw.mods.fml.common.FMLCommonHandler; import gregtech.api.GregTech_API; import gregtech.api.damagesources.GT_DamageSources; +import gregtech.api.damagesources.GT_DamageSources.DamageSourceHotItem; import gregtech.api.enchants.Enchantment_Radioactivity; import gregtech.api.enums.*; import gregtech.api.events.BlockScanningEvent; @@ -55,10 +56,7 @@ import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityChest; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.MathHelper; +import net.minecraft.util.*; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.common.DimensionManager; @@ -1571,9 +1569,17 @@ public class GT_Utility { return isWearingFullGasHazmat(aEntity); } - public static boolean applyHeatDamage(EntityLivingBase aEntity, float aDamage) { + public static boolean applyHeatDamage(EntityLivingBase entity, float damage) { + return applyHeatDamage(entity, damage, GT_DamageSources.getHeatDamage()); + } + + public static boolean applyHeatDamageFromItem(EntityLivingBase entity, float damage, ItemStack item) { + return applyHeatDamage(entity, damage, new DamageSourceHotItem(item)); + } + + private static boolean applyHeatDamage(EntityLivingBase aEntity, float aDamage, DamageSource source) { if (aDamage > 0 && aEntity != null && aEntity.getActivePotionEffect(Potion.fireResistance) == null && !isWearingFullHeatHazmat(aEntity)) { - aEntity.attackEntityFrom(GT_DamageSources.getHeatDamage(), aDamage); + aEntity.attackEntityFrom(source, aDamage); return true; } return false; diff --git a/src/main/java/gregtech/common/GT_Proxy.java b/src/main/java/gregtech/common/GT_Proxy.java index bff044b4c3..76a7b01e85 100644 --- a/src/main/java/gregtech/common/GT_Proxy.java +++ b/src/main/java/gregtech/common/GT_Proxy.java @@ -1,10 +1,6 @@ package gregtech.common; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.IFuelHandler; -import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.ModContainer; -import cpw.mods.fml.common.ProgressManager; +import cpw.mods.fml.common.*; import cpw.mods.fml.common.eventhandler.Event.Result; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; @@ -15,16 +11,8 @@ import cpw.mods.fml.common.registry.GameRegistry; import forestry.api.genetics.AlleleManager; import gregtech.GT_Mod; import gregtech.api.GregTech_API; -import gregtech.api.enums.ConfigCategories; -import gregtech.api.enums.Dyes; -import gregtech.api.enums.GT_Values; -import gregtech.api.enums.ItemList; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OreDictNames; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.enums.SubTag; +import gregtech.api.enums.*; import gregtech.api.enums.TC_Aspects.TC_AspectStack; -import gregtech.api.enums.ToolDictNames; import gregtech.api.interfaces.IBlockOnWalkOver; import gregtech.api.interfaces.IProjectileItem; import gregtech.api.interfaces.internal.IGT_Mod; @@ -88,22 +76,11 @@ import org.apache.commons.lang3.text.WordUtils; import java.io.File; import java.lang.reflect.InvocationTargetException; import java.text.DateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import java.util.stream.Collectors; import java.util.concurrent.locks.ReentrantLock; +import java.util.stream.Collectors; import static gregtech.api.enums.GT_Values.W; import static gregtech.api.enums.GT_Values.debugEntityCramming; @@ -1520,7 +1497,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { float tHeat = GT_Utility.getHeatDamageFromItem(tStack); if (tHeat != 0.0F) { if (tHeat > 0.0F) { - GT_Utility.applyHeatDamage(aEvent.player, tHeat); + GT_Utility.applyHeatDamageFromItem(aEvent.player, tHeat, tStack); } else { GT_Utility.applyFrostDamage(aEvent.player, -tHeat); } @@ -1640,7 +1617,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { float tHeat = GT_Utility.getHeatDamageFromItem(tStack); if (tHeat != 0.0F) { if (tHeat > 0.0F) { - GT_Utility.applyHeatDamage(aEvent.player, tHeat); + GT_Utility.applyHeatDamageFromItem(aEvent.player, tHeat, tStack); } else { GT_Utility.applyFrostDamage(aEvent.player, -tHeat); } @@ -1795,7 +1772,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { orePrefixes[i].mLocalizedMaterialPre + aMaterial.mDefaultLocalName, null, aMaterial.mRGBa, 2, 775, GT_OreDictUnificator.get(orePrefixes[i], aMaterial, 1L), - ItemList.Cell_Empty.get(1L, new Object[0]), 1000); + ItemList.Cell_Empty.get(1L), 1000); int hydrogenAmount = 2 * i + 2; GT_Values.RA.addCrackingRecipe(i + 1, new FluidStack(uncrackedFluid, 1000), Materials.Hydrogen.getGas(hydrogenAmount * 1000), @@ -1824,7 +1801,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { orePrefixes[i].mLocalizedMaterialPre + aMaterial.mDefaultLocalName, null, aMaterial.mRGBa, 2, 775, GT_OreDictUnificator.get(orePrefixes[i], aMaterial, 1L), - ItemList.Cell_Empty.get(1L, new Object[0]), 1000); + ItemList.Cell_Empty.get(1L), 1000); GT_Values.RA.addCrackingRecipe(i + 1, new FluidStack(uncrackedFluid, 1000), GT_ModHandler.getSteam(1000), new FluidStack(crackedFluids[i], 1000), 40 + 20 * i, 240 + 120 * i); @@ -2142,9 +2119,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { boolean isHeat = GT_Utility.isStackInList(aStack, GregTech_API.sHeatHazmatList); boolean isRadio = GT_Utility.isStackInList(aStack, GregTech_API.sRadioHazmatList); boolean isElectro = GT_Utility.isStackInList(aStack, GregTech_API.sElectroHazmatList); - if(isGas && isBio && isFrost && isHeat && isRadio && isElectro) - return true; - return false; + return isGas && isBio && isFrost && isHeat && isRadio && isElectro; } @SubscribeEvent -- cgit From 53df8347026d0b66acffe0c6285c97bbafdf4834 Mon Sep 17 00:00:00 2001 From: TimeConqueror Date: Thu, 12 Aug 2021 03:35:42 +0300 Subject: Sped up GT_Utility#areUnificationsEqual --- src/main/java/gregtech/api/util/GT_Utility.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 28c6b266ec..17606b85a4 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -898,7 +898,7 @@ public class GT_Utility { } public static boolean areUnificationsEqual(ItemStack aStack1, ItemStack aStack2, boolean aIgnoreNBT) { - return areStacksEqual(GT_OreDictUnificator.get(aStack1), GT_OreDictUnificator.get(aStack2), aIgnoreNBT); + return areStacksEqual(GT_OreDictUnificator.get_nocopy(aStack1), GT_OreDictUnificator.get_nocopy(aStack2), aIgnoreNBT); } public static String getFluidName(Fluid aFluid, boolean aLocalized) { -- cgit From b05f1651f62eb87823f4ed9fe5143931b48150d9 Mon Sep 17 00:00:00 2001 From: TimeConqueror Date: Mon, 16 Aug 2021 02:34:35 +0300 Subject: Removed useless concurrency for some maps --- .../gregtech/api/items/GT_MetaGenerated_Tool.java | 3 ++- .../implementations/GT_MetaPipeEntity_Item.java | 4 +-- .../java/gregtech/api/objects/CollectorUtils.java | 29 ++++++++++++++++++++++ src/main/java/gregtech/api/util/GT_Utility.java | 12 +++------ .../items/behaviors/Behaviour_Plunger_Item.java | 4 +-- 5 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 src/main/java/gregtech/api/objects/CollectorUtils.java (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/items/GT_MetaGenerated_Tool.java b/src/main/java/gregtech/api/items/GT_MetaGenerated_Tool.java index 65e9dfcc39..82f19351a5 100644 --- a/src/main/java/gregtech/api/items/GT_MetaGenerated_Tool.java +++ b/src/main/java/gregtech/api/items/GT_MetaGenerated_Tool.java @@ -47,6 +47,7 @@ import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.world.BlockEvent; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; @@ -645,7 +646,7 @@ public abstract class GT_MetaGenerated_Tool extends GT_MetaBase_Item implements return false; } Materials aMaterial = getPrimaryMaterial(aStack); - ConcurrentHashMap tMap = new ConcurrentHashMap(), tResult = new ConcurrentHashMap(); + HashMap tMap = new HashMap<>(), tResult = new HashMap<>(); if (aMaterial.mEnchantmentTools != null) { tMap.put(aMaterial.mEnchantmentTools.effectId, (int) aMaterial.mEnchantmentToolsLevel); if (aMaterial.mEnchantmentTools == Enchantment.fortune) diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java index a4cc0e407e..edec79fe65 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java @@ -29,8 +29,8 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; -import java.util.concurrent.ConcurrentHashMap; import static gregtech.api.enums.Textures.BlockIcons.PIPE_RESTRICTOR; @@ -174,7 +174,7 @@ public class GT_MetaPipeEntity_Item extends MetaPipeEntity implements IMetaTileE for (boolean temp = true; temp && !isInventoryEmpty() && pipeCapacityCheck(); ) { temp = false; tPipeList.clear(); - for (IMetaTileEntityItemPipe tTileEntity : GT_Utility.sortMapByValuesAcending(IMetaTileEntityItemPipe.Util.scanPipes(this, new ConcurrentHashMap(), 0, false, false)).keySet()) { + for (IMetaTileEntityItemPipe tTileEntity : GT_Utility.sortMapByValuesAcending(IMetaTileEntityItemPipe.Util.scanPipes(this, new HashMap<>(), 0, false, false)).keySet()) { if (temp) break; tPipeList.add(tTileEntity); while (!temp && !isInventoryEmpty() && tTileEntity.sendItemStack(aBaseMetaTileEntity)) diff --git a/src/main/java/gregtech/api/objects/CollectorUtils.java b/src/main/java/gregtech/api/objects/CollectorUtils.java new file mode 100644 index 0000000000..3f89ad0773 --- /dev/null +++ b/src/main/java/gregtech/api/objects/CollectorUtils.java @@ -0,0 +1,29 @@ +package gregtech.api.objects; + +import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.BinaryOperator; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collector; +import java.util.stream.Collectors; + +public class CollectorUtils { + /** + * Returns a merge function, suitable for use in + * {@link Map#merge(Object, Object, BiFunction) Map.merge()} or + * {@link Collectors#toMap(Function, Function, BinaryOperator) toMap()}, which always + * throws {@code IllegalStateException}. This can be used to enforce the + * assumption that the elements being collected are distinct. + * + * @param the type of input arguments to the merge function + * @return a merge function which always throw {@code IllegalStateException} + */ + public static BinaryOperator throwingMerger() { + return (u,v) -> { throw new IllegalStateException(String.format("Duplicate key %s", u)); }; + } + + public static , M extends Map> Collector entriesToMap(Supplier mapSupplier) { + return Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, CollectorUtils.throwingMerger(), mapSupplier); + } +} diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 17606b85a4..be5f978d6e 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -22,6 +22,7 @@ import gregtech.api.items.GT_EnergyArmor_Item; import gregtech.api.items.GT_Generic_Item; import gregtech.api.items.GT_MetaGenerated_Tool; import gregtech.api.net.GT_Packet_Sound; +import gregtech.api.objects.CollectorUtils; import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.ItemData; import gregtech.api.threads.GT_Runnable_Sound; @@ -1752,15 +1753,8 @@ public class GT_Utility { return aMap; } - /** - * Why the fuck do neither Java nor Guava have a Function to do this? - */ - public static LinkedHashMap sortMapByValuesAcending(Map aMap) { - List> tEntrySet = new LinkedList<>(aMap.entrySet()); - tEntrySet.sort(Entry.comparingByValue()); - LinkedHashMap rMap = new LinkedHashMap<>(); - for (Map.Entry tEntry : tEntrySet) rMap.put(tEntry.getKey(), tEntry.getValue()); - return rMap; + public static > LinkedHashMap sortMapByValuesAcending(Map map) { + return map.entrySet().stream().sorted(Entry.comparingByValue()).collect(CollectorUtils.entriesToMap(LinkedHashMap::new)); } /** diff --git a/src/main/java/gregtech/common/items/behaviors/Behaviour_Plunger_Item.java b/src/main/java/gregtech/common/items/behaviors/Behaviour_Plunger_Item.java index 43a95fd2c7..ddb88b80c8 100644 --- a/src/main/java/gregtech/common/items/behaviors/Behaviour_Plunger_Item.java +++ b/src/main/java/gregtech/common/items/behaviors/Behaviour_Plunger_Item.java @@ -14,8 +14,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import java.util.HashMap; import java.util.List; -import java.util.concurrent.ConcurrentHashMap; public class Behaviour_Plunger_Item extends Behaviour_None { private final int mCosts; @@ -34,7 +34,7 @@ public class Behaviour_Plunger_Item extends Behaviour_None { if ((aTileEntity instanceof IGregTechTileEntity)) { IMetaTileEntity tMetaTileEntity = ((IGregTechTileEntity) aTileEntity).getMetaTileEntity(); if ((tMetaTileEntity instanceof IMetaTileEntityItemPipe)) { - for (Object tTileEntity : GT_Utility.sortMapByValuesAcending(IMetaTileEntityItemPipe.Util.scanPipes((IMetaTileEntityItemPipe) tMetaTileEntity, new ConcurrentHashMap(), 0L, false, true)).keySet()) + for (Object tTileEntity : GT_Utility.sortMapByValuesAcending(IMetaTileEntityItemPipe.Util.scanPipes((IMetaTileEntityItemPipe) tMetaTileEntity, new HashMap<>(), 0L, false, true)).keySet()) { int i = 0; -- cgit