diff options
Diffstat (limited to 'src/main/java/gregtech/common')
3 files changed, 64 insertions, 28 deletions
diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_ME.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_ME.java index ee7a3df356..cfd953c3c7 100644 --- a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_ME.java +++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_ME.java @@ -1,7 +1,6 @@ package gregtech.common.tileentities.machines; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_INPUT_HATCH; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_INPUT_HATCH_ACTIVE; +import static gregtech.api.enums.Textures.BlockIcons.*; import java.util.*; import java.util.stream.Collectors; @@ -107,11 +106,13 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_ this.sharedItemGetter = getter; NBTTagList inv = nbt.getTagList("inventory", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < inv.tagCount(); i++) { - itemInventory.add(ItemStack.loadItemStackFromNBT(inv.getCompoundTagAt(i))); + var item = ItemStack.loadItemStackFromNBT(inv.getCompoundTagAt(i)); + if (item != null && item.stackSize > 0) itemInventory.add(item); } NBTTagList fluidInv = nbt.getTagList("fluidInventory", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < fluidInv.tagCount(); i++) { - fluidInventory.add(FluidStack.loadFluidStackFromNBT(fluidInv.getCompoundTagAt(i))); + var fluid = FluidStack.loadFluidStackFromNBT(fluidInv.getCompoundTagAt(i)); + if (fluid != null && fluid.amount > 0) fluidInventory.add(fluid); } } @@ -122,11 +123,27 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_ .getPatternForItem(pattern, world))); } + private boolean isEmpty() { + if (itemInventory.isEmpty() && fluidInventory.isEmpty()) return true; + + for (ItemStack itemStack : itemInventory) { + if (itemStack != null && itemStack.stackSize > 0) return false; + } + + for (FluidStack fluidStack : fluidInventory) { + if (fluidStack != null && fluidStack.amount > 0) return false; + } + + return true; + } + public ItemStack[] getItemInputs() { + if (isEmpty()) return new ItemStack[0]; return ArrayUtils.addAll(itemInventory.toArray(new ItemStack[0]), sharedItemGetter.getSharedItem()); } public FluidStack[] getFluidInputs() { + if (isEmpty()) return new FluidStack[0]; return fluidInventory.toArray(new FluidStack[0]); } @@ -231,7 +248,7 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_ // a hash map for faster lookup of pattern slots, not necessarily all valid. private Map<ICraftingPatternDetails, PatternSlot> patternDetailsPatternSlotMap = new HashMap<>(MAX_PATTERN_COUNT); - private boolean initialPatternSyncDone = false; + private boolean needPatternSync = true; private boolean justHadNewItems = false; private boolean supportFluids; @@ -242,7 +259,7 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_ aID, aName, aNameRegional, - 1, + 6, MAX_INV_COUNT, new String[] { "Advanced item input for Multiblocks", "Processes patterns directly from ME", supportFluids ? "It supports patterns including fluids" @@ -265,26 +282,21 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_ @Override public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_ME_INPUT_HATCH_ACTIVE) }; + return getTexturesInactive(aBaseTexture); } @Override public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_ME_INPUT_HATCH) }; + return new ITexture[] { aBaseTexture, + TextureFactory.of(supportFluids ? OVERLAY_ME_CRAFTING_INPUT_BUFFER : OVERLAY_ME_CRAFTING_INPUT_BUS) }; } @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { super.onPostTick(aBaseMetaTileEntity, aTimer); - if (!initialPatternSyncDone && aTimer % 10 == 0 && getBaseMetaTileEntity().isServerSide()) { - try { - getProxy().getGrid() - .postEvent(new MENetworkCraftingPatternChange(this, getProxy().getNode())); - } catch (GridAccessException ignored) { - return; - } - initialPatternSyncDone = true; + if (needPatternSync && aTimer % 10 == 0 && getBaseMetaTileEntity().isServerSide()) { + needPatternSync = !postMEPatternChange(); } } @@ -336,6 +348,7 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_ getProxy().getNode() .updateState(); } + needPatternSync = true; } @Override @@ -537,6 +550,7 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_ originalPattern.refund(getProxy(), getRequest()); } catch (GridAccessException ignored) {} internalInventory[slot.getSlotIndex()] = null; + needPatternSync = true; } else { return; // nothing has changed } @@ -550,10 +564,7 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_ internalInventory[slot.getSlotIndex()] = patternSlot; patternDetailsPatternSlotMap.put(patternSlot.getPatternDetails(), patternSlot); - try { - getProxy().getGrid() - .postEvent(new MENetworkCraftingPatternChange(this, getProxy().getNode())); - } catch (GridAccessException ignored) {} + needPatternSync = true; } private ItemStack[] getSharedItems() { @@ -698,4 +709,17 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_ME extends GT_MetaTileEntity_ public ItemStack getCrafterIcon() { return getMachineCraftingIcon(); } + + private boolean postMEPatternChange() { + // don't post until it's active + if (!getProxy().isActive()) return false; + try { + getProxy().getGrid() + .postEvent(new MENetworkCraftingPatternChange(this, getProxy().getNode())); + } catch (GridAccessException ignored) { + return false; + } + return true; + } + } diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_Slave.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_Slave.java index 04bf9da06d..51d58a38b1 100644 --- a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_Slave.java +++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_CraftingInput_Slave.java @@ -1,7 +1,6 @@ package gregtech.common.tileentities.machines; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_INPUT_HATCH; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_INPUT_HATCH_ACTIVE; +import static gregtech.api.enums.Textures.BlockIcons.*; import java.util.*; @@ -31,7 +30,7 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_Slave extends GT_MetaTileEnti aID, aName, aNameRegional, - 1, + 6, 0, new String[] { "Slave for Crafting Input Buffer", "Link with Crafting Input Buffer using Data Stick to share inventory", @@ -52,12 +51,12 @@ public class GT_MetaTileEntity_Hatch_CraftingInput_Slave extends GT_MetaTileEnti @Override public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_ME_INPUT_HATCH_ACTIVE) }; + return getTexturesInactive(aBaseTexture); } @Override public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_ME_INPUT_HATCH) }; + return new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_ME_CRAFTING_INPUT_SLAVE) }; } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PlasmaForge.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PlasmaForge.java index d1a2a9dd7f..7beb6e65b6 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PlasmaForge.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PlasmaForge.java @@ -21,6 +21,7 @@ import static java.lang.Math.log; import static java.lang.Math.pow; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import net.minecraft.item.ItemStack; @@ -59,6 +60,8 @@ import gregtech.api.util.GT_ExoticEnergyInputHelper; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; +import gregtech.common.tileentities.machines.IDualInputHatch; +import gregtech.common.tileentities.machines.IDualInputInventory; public class GT_MetaTileEntity_PlasmaForge extends GT_MetaTileEntity_AbstractMultiFurnace<GT_MetaTileEntity_PlasmaForge> implements ISurvivalConstructable { @@ -668,11 +671,21 @@ public class GT_MetaTileEntity_PlasmaForge extends GT_MetaTileEntity_AbstractMul @NotNull public CheckRecipeResult checkProcessing() { CheckRecipeResult recipe_process = processRecipe(getCompactedInputs(), getCompactedFluids()); + if (recipe_process.wasSuccessful()) return recipe_process; + + // If not successful, then try crafting input buffers + for (IDualInputHatch hatch : mDualInputHatches) { + for (Iterator<? extends IDualInputInventory> it = hatch.inventories(); it.hasNext();) { + IDualInputInventory inventory = it.next(); + recipe_process = processRecipe(inventory.getItemInputs(), inventory.getFluidInputs()); + if (recipe_process.wasSuccessful()) { + return recipe_process; + } + } + } // If recipe cannot be found then continuity is broken and reset running time to 0. - if (!recipe_process.wasSuccessful()) { - resetDiscount(); - } + resetDiscount(); return recipe_process; } |