diff --git a/src/main/java/reobf/proghatches/ae/PartAmountMaintainer.java b/src/main/java/reobf/proghatches/ae/PartAmountMaintainer.java index 5074b03..9af4dfa 100644 --- a/src/main/java/reobf/proghatches/ae/PartAmountMaintainer.java +++ b/src/main/java/reobf/proghatches/ae/PartAmountMaintainer.java @@ -102,6 +102,7 @@ public void writeToNBT(NBTTagCompound data) { data.setInteger("rsmode", rsmode); data.setInteger("redstone", redstone); data.setLong("amount", amount); + data.setInteger("interval", interval); // data.setBoolean("lastredstone", lastredstone); if (mark[0] != null) data.setTag("mark", mark[0].writeToNBT(new NBTTagCompound())); // if(upgrade[0]!=null)data.setTag("upgrade", upgrade[0].writeToNBT(new NBTTagCompound())); @@ -121,6 +122,7 @@ public void readFromNBT(NBTTagCompound data) { rsmode = data.getInteger("rsmode"); redstone = data.getInteger("redstone"); amount = data.getLong("amount"); + interval= data.getInteger("interval"); // lastredstone=data.getBoolean("lastredstone" ); if (data.getCompoundTag("mark") .hasNoTags() == false) mark[0] = ItemStack.loadItemStackFromNBT(data.getCompoundTag("mark")); diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/DualInputHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/DualInputHatch.java index 3715633..da17938 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/DualInputHatch.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/DualInputHatch.java @@ -1181,7 +1181,7 @@ public interface VargsFunction { }) .filter(a -> a != null && a.amount > 0) .toArray(FluidStack[]::new); - static VargsFunction filterStack = (s) -> Arrays.stream(s) + public static VargsFunction filterStack = (s) -> Arrays.stream(s) .flatMap(Arrays::stream) .filter(a -> a != null) .toArray(ItemStack[]::new); diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/NBTHatchMECatalyst.java b/src/main/java/reobf/proghatches/gt/metatileentity/NBTHatchMECatalyst.java index b0f7f3b..1da4a19 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/NBTHatchMECatalyst.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/NBTHatchMECatalyst.java @@ -34,370 +34,397 @@ import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.nbthandlers.MTEHatchCatalysts; import gtnhlanth.common.hatch.MTEBusInputFocus; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; import reobf.proghatches.gt.metatileentity.SuperChestME.UnlimitedWrapper; import reobf.proghatches.gt.metatileentity.util.IStoageCellUpdate; import reobf.proghatches.main.registration.Registration; -public class NBTHatchMECatalyst extends MTEHatchCatalysts implements ICellContainer, IGridProxyable, IStoageCellUpdate{ +public class NBTHatchMECatalyst extends MTEHatchCatalysts implements ICellContainer, IGridProxyable, IStoageCellUpdate { public NBTHatchMECatalyst(int id, String name, String nameRegional) { super(id, name, nameRegional); - Registration.items.add(new ItemStack(GregTechAPI.sBlockMachines, 1, id)); + Registration.items.add(new ItemStack(GregTechAPI.sBlockMachines, 1, id)); } + public NBTHatchMECatalyst(String name, String[] descriptionArray, ITexture[][][] textures) { super(name, descriptionArray, textures); - + } -String[] descCache; -@Override -public String[] getDescription() { - return descCache==null?(descCache=reobf.proghatches.main.Config.get("HMEC", ImmutableMap.of())):descCache; -} - /*@Override - public boolean isItemValidForUsageSlot(ItemStack aStack) { - return false; - }*/ + String[] descCache; + + @Override + public String[] getDescription() { + + return descCache == null ? (descCache = reobf.proghatches.main.Config.get("HMEC", ImmutableMap.of())) + : descCache; + } + + /* + * @Override public boolean isItemValidForUsageSlot(ItemStack aStack) { + * return false; } + */ @Override public IGridNode getActionableNode() { - + return getProxy().getNode(); } + @Override public IGridNode getGridNode(ForgeDirection dir) { - + return getProxy().getNode(); } + @Override public void securityBreak() { } - public int getIndex(){ - + + public int getIndex() { + return getInputSlotCount(); } - IMEInventoryHandler handler = new MEInventoryHandler(new UnlimitedWrapper(), StorageChannel.ITEMS) ; - public class UnlimitedWrapper implements IMEInventory { - - public UnlimitedWrapper() { - - } - - @Override - public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src) { - if (type != Actionable.SIMULATE)post(); - - if(input==null){ - return input; - } - if(!isItemValidForUsageSlot(input.getItemStack())){ - return input; - } - - try { - long l = input.getStackSize(); - long compl = 0; - if (l > Integer.MAX_VALUE) { - compl = l - Integer.MAX_VALUE; - } - ItemStack in = input.getItemStack(); - ItemStack thiz = mInventory[getIndex()]; - if (thiz != null && !Platform.isSameItem(in, thiz)) return input; - if (thiz == null) { - thiz = in.copy(); - thiz.stackSize = 0; - } - int space = Math.max(0, cap() - thiz.stackSize); - int transfer = Math.min(space, in.stackSize); - if (type == Actionable.SIMULATE) { - in.stackSize -= transfer; - if (in.stackSize <= 0 && compl == 0) in = null; - AEItemStack ret = AEItemStack.create(in); - if (ret != null) ret.incStackSize(compl); - return ret; - } - if (type == Actionable.MODULATE) { - thiz.stackSize += transfer; - mInventory[getIndex()] = thiz; - in.stackSize -= transfer; - if (in.stackSize <= 0 && compl == 0) in = null; - AEItemStack ret = AEItemStack.create(in); - if (ret != null) ret.incStackSize(compl); - return ret; - - } - - return null; - } finally { - last = AEItemStack.create(mInventory[getIndex()]); - - } - } - - - - @Override - public IAEItemStack extractItems(IAEItemStack input, Actionable type, BaseActionSource src) { - try { - - if (type != Actionable.SIMULATE) post(); - - ItemStack in = input.getItemStack(); - ItemStack thiz = mInventory[getIndex()]; - if (thiz != null && !Platform.isSameItem(in, thiz)) return null; - if (thiz == null) { - return null; - } // thiz=in.copy(); } - int transfer = Math.min(in.stackSize, thiz.stackSize); - if (transfer == 0) return null; - if (type == Actionable.SIMULATE) { - in.stackSize = transfer; - return AEItemStack.create(in); - - } - if (type == Actionable.MODULATE) { - thiz.stackSize -= transfer; - if (thiz.stackSize <= 0) thiz = null; - mInventory[getIndex()] = thiz; - in.stackSize = transfer; - return AEItemStack.create(in); - } - - return null; - } finally { - - last = AEItemStack.create(mInventory[getIndex()]); - } - } - - @Override - public IItemList getAvailableItems(IItemList out) { - if (mInventory[getIndex()] != null) out.addStorage(AEItemStack.create(mInventory[getIndex()])); - return out; - } - - @Override - public StorageChannel getChannel() { - - return StorageChannel.ITEMS; - } - } - - private AEItemStack last; - - private void post() { - - try { - - // this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate()); - // this.getProxy().getGrid().postEvent(new MENetworkStorageEvent(handler0, StorageChannel.ITEMS)); - try { - - if (last != null) { - if (mInventory[getIndex()] != null) { - if (last.equals(mInventory[getIndex()])) { - if (last.getStackSize() == mInventory[getIndex()].stackSize) { - return; - } else { - - this.getProxy() - .getStorage() - .postAlterationOfStoredItems( - StorageChannel.ITEMS, - ImmutableList.of( - last.copy() - .setStackSize(mInventory[getIndex()].stackSize - last.getStackSize())), - new MachineSource(this)); - last = AEItemStack.create(mInventory[getIndex()]); - return; - } - } - - } ; - - this.getProxy() - .getStorage() - .postAlterationOfStoredItems( - StorageChannel.ITEMS, - ImmutableList.of( - last.copy() - .setStackSize(-last.getStackSize())), - new MachineSource(this)); - } - last = AEItemStack.create(mInventory[getIndex()]); - if (last != null) { - this.getProxy() - .getStorage() - .postAlterationOfStoredItems( - StorageChannel.ITEMS, - ImmutableList.of( - last.copy() - .setStackSize(last.getStackSize())), - new MachineSource(this)); - } - - } catch (final GridAccessException ignore) {} - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } + + IMEInventoryHandler handler = new MEInventoryHandler(new UnlimitedWrapper(), StorageChannel.ITEMS); + + public class UnlimitedWrapper implements IMEInventory { + + public UnlimitedWrapper() { + + } + + @Override + public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src) { + if (type != Actionable.SIMULATE) + post(); + + if (input == null) { + return input; + } + if (!isItemValidForUsageSlot(input.getItemStack())) { + return input; + } + + try { + long l = input.getStackSize(); + long compl = 0; + if (l > Integer.MAX_VALUE) { + compl = l - Integer.MAX_VALUE; + } + ItemStack in = input.getItemStack(); + ItemStack thiz = mInventory[getIndex()]; + if (thiz != null && !Platform.isSameItem(in, thiz)) + return input; + if (thiz == null) { + thiz = in.copy(); + thiz.stackSize = 0; + } + int space = Math.max(0, cap() - thiz.stackSize); + int transfer = Math.min(space, in.stackSize); + if (type == Actionable.SIMULATE) { + in.stackSize -= transfer; + if (in.stackSize <= 0 && compl == 0) + in = null; + AEItemStack ret = AEItemStack.create(in); + if (ret != null) + ret.incStackSize(compl); + return ret; + } + if (type == Actionable.MODULATE) { + thiz.stackSize += transfer; + mInventory[getIndex()] = thiz; + in.stackSize -= transfer; + if (in.stackSize <= 0 && compl == 0) + in = null; + AEItemStack ret = AEItemStack.create(in); + if (ret != null) + ret.incStackSize(compl); + return ret; + + } + + return null; + } finally { + last = AEItemStack.create(mInventory[getIndex()]); + + } + } + + @Override + public IAEItemStack extractItems(IAEItemStack input, Actionable type, BaseActionSource src) { + try { + + if (type != Actionable.SIMULATE) + post(); + + ItemStack in = input.getItemStack(); + ItemStack thiz = mInventory[getIndex()]; + if (thiz != null && !Platform.isSameItem(in, thiz)) + return null; + if (thiz == null) { + return null; + } // thiz=in.copy(); } + int transfer = Math.min(in.stackSize, thiz.stackSize); + if (transfer == 0) + return null; + if (type == Actionable.SIMULATE) { + in.stackSize = transfer; + return AEItemStack.create(in); + + } + if (type == Actionable.MODULATE) { + thiz.stackSize -= transfer; + if (thiz.stackSize <= 0) + thiz = null; + mInventory[getIndex()] = thiz; + in.stackSize = transfer; + return AEItemStack.create(in); + } + + return null; + } finally { + + last = AEItemStack.create(mInventory[getIndex()]); + } + } + + @Override + public IItemList getAvailableItems(IItemList out) { + if (mInventory[getIndex()] != null) + out.addStorage(AEItemStack.create(mInventory[getIndex()])); + return out; + } + + @Override + public StorageChannel getChannel() { + + return StorageChannel.ITEMS; + } + } + + private AEItemStack last; + + private void post() { + + try { + + // this.getProxy().getGrid().postEvent(new + // MENetworkCellArrayUpdate()); + // this.getProxy().getGrid().postEvent(new + // MENetworkStorageEvent(handler0, StorageChannel.ITEMS)); + try { + + if (last != null) { + if (mInventory[getIndex()] != null) { + if (last.equals(mInventory[getIndex()])) { + if (last.getStackSize() == mInventory[getIndex()].stackSize) { + return; + } else { + + this.getProxy().getStorage().postAlterationOfStoredItems(StorageChannel.ITEMS, + ImmutableList.of(last.copy() + .setStackSize(mInventory[getIndex()].stackSize - last.getStackSize())), + new MachineSource(this)); + last = AEItemStack.create(mInventory[getIndex()]); + return; + } + } + + } + ; + + this.getProxy().getStorage().postAlterationOfStoredItems(StorageChannel.ITEMS, + ImmutableList.of(last.copy().setStackSize(-last.getStackSize())), new MachineSource(this)); + } + last = AEItemStack.create(mInventory[getIndex()]); + if (last != null) { + this.getProxy().getStorage().postAlterationOfStoredItems(StorageChannel.ITEMS, + ImmutableList.of(last.copy().setStackSize(last.getStackSize())), new MachineSource(this)); + } + + } catch (final GridAccessException ignore) { + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + @Override public List getCellArray(StorageChannel channel) { - if(channel==StorageChannel.FLUIDS)return ImmutableList.of(); - + if (channel == StorageChannel.FLUIDS) + return ImmutableList.of(); + return ImmutableList.of(handler); } + @Override public int getPriority() { - + return 0; } + @Override public void saveChanges(IMEInventory cellInventory) { markDirty(); - + } + @Override public void cellUpdate() { markDirty(); - update = true; + update = true; } + @Override public DimensionalCoord getLocation() { - - return new DimensionalCoord((TileEntity)this.getBaseMetaTileEntity()); + + return new DimensionalCoord((TileEntity) this.getBaseMetaTileEntity()); } + AENetworkProxy gridProxy; + @Override - public AENetworkProxy getProxy() { - + public AENetworkProxy getProxy() { + if (gridProxy == null) { - gridProxy = new AENetworkProxy(this, "proxy", visualStack(), true); - gridProxy.setFlags(GridFlags.REQUIRE_CHANNEL); - updateValidGridProxySides(); - if (getBaseMetaTileEntity().getWorld() != null) gridProxy.setOwner( - getBaseMetaTileEntity().getWorld() - .getPlayerEntityByName(getBaseMetaTileEntity().getOwnerName())); - } - - return this.gridProxy;} - + gridProxy = new AENetworkProxy(this, "proxy", visualStack(), true); + gridProxy.setFlags(GridFlags.REQUIRE_CHANNEL); + updateValidGridProxySides(); + if (getBaseMetaTileEntity().getWorld() != null) + gridProxy.setOwner(getBaseMetaTileEntity().getWorld() + .getPlayerEntityByName(getBaseMetaTileEntity().getOwnerName())); + } + + return this.gridProxy; + } + private ItemStack visualStack() { - return new ItemStack(GregTechAPI.sBlockMachines, 1, getBaseMetaTileEntity().getMetaTileID()); - } - - @Override - public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { - - super.onFirstTick(aBaseMetaTileEntity); - getProxy().onReady(); - // onColorChangeServer(aBaseMetaTileEntity.getColorization()); - post(); - } boolean wasActive; - boolean update; - int rep; - public void updateStatus() { - - post(); - - } - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - - boolean active = this.getProxy() - .isActive(); - if (!aBaseMetaTileEntity.getWorld().isRemote) { - if (aTick % 40 == 1) { - post(); - } - - if (rep > 0) { - rep--; - update = true; - } - if (this.getBaseMetaTileEntity() - .hasInventoryBeenModified()) { - update = true; - rep = 1; - } ; - - if (update) { - update = false; - updateStatus(); - } - if (wasActive != active) { - wasActive = active; - - try { - this.getProxy() - .getGrid() - .postEvent(new MENetworkCellArrayUpdate()); - } catch (GridAccessException e) { - - } - post(); - } - - - - if (!aBaseMetaTileEntity.getWorld().isRemote && (aTick & 16) != 0) { - this.getBaseMetaTileEntity() - .setActive( - this.getProxy() - .isPowered() && active); - - } - - - - } - super.onPostTick(aBaseMetaTileEntity, aTick); - - if (aBaseMetaTileEntity.getWorld().isRemote) { - return; - } - - boolean needToSort = false; - for (int i = 1; i < mInventory.length; i++) { - ItemStack is = mInventory[i]; - if (is == null) continue; - markDirty(); - if (mInventory[getIndex()] == null) { - mInventory[getIndex()] = is.copy(); - mInventory[i] = null; - } else if (cap() - is.stackSize >= mInventory[getIndex()].stackSize) { - mInventory[getIndex()].stackSize += is.stackSize; - mInventory[i] = null; - } else { - int to = Math.min(cap() - mInventory[getIndex()].stackSize, is.stackSize); - mInventory[getIndex()].stackSize += to; - mInventory[i].stackSize -= to; - needToSort = true; - } - } - if (needToSort) fillStacksIntoFirstSlots(); - - } - private int cap() { - - return 1; + return new ItemStack(GregTechAPI.sBlockMachines, 1, getBaseMetaTileEntity().getMetaTileID()); + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + + super.onFirstTick(aBaseMetaTileEntity); + getProxy().onReady(); + // onColorChangeServer(aBaseMetaTileEntity.getColorization()); + post(); + } + + boolean wasActive; + boolean update; + int rep; + + public void updateStatus() { + + post(); + + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + + boolean active = this.getProxy().isActive(); + if (!aBaseMetaTileEntity.getWorld().isRemote) { + if (aTick % 40 == 1) { + post(); + } + + if (rep > 0) { + rep--; + update = true; + } + if (this.getBaseMetaTileEntity().hasInventoryBeenModified()) { + update = true; + rep = 1; + } + ; + + if (update) { + update = false; + updateStatus(); + } + if (wasActive != active) { + wasActive = active; + + try { + this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate()); + } catch (GridAccessException e) { + + } + post(); + } + + if (!aBaseMetaTileEntity.getWorld().isRemote && (aTick & 16) != 0) { + this.getBaseMetaTileEntity().setActive(this.getProxy().isPowered() && active); + + } + + } + super.onPostTick(aBaseMetaTileEntity, aTick); + + if (aBaseMetaTileEntity.getWorld().isRemote) { + return; + } + + boolean needToSort = false; + for (int i = 1; i < mInventory.length; i++) { + ItemStack is = mInventory[i]; + if (is == null) + continue; + markDirty(); + if (mInventory[getIndex()] == null) { + mInventory[getIndex()] = is.copy(); + mInventory[i] = null; + } else if (cap() - is.stackSize >= mInventory[getIndex()].stackSize) { + mInventory[getIndex()].stackSize += is.stackSize; + mInventory[i] = null; + } else { + int to = Math.min(cap() - mInventory[getIndex()].stackSize, is.stackSize); + mInventory[getIndex()].stackSize += to; + mInventory[i].stackSize -= to; + needToSort = true; + } } - - @Override + if (needToSort) + fillStacksIntoFirstSlots(); + + } + + private int cap() { + + return 1; + } + + @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - + return new NBTHatchMECatalyst(mName, mDescriptionArray, mTextures); } - private void updateValidGridProxySides() { - /* - * if (disabled) { - * getProxy().setValidSides(EnumSet.noneOf(ForgeDirection.class)); - * return; - * } - */ - getProxy().setValidSides(EnumSet.complementOf(EnumSet.of(ForgeDirection.UNKNOWN))); - - } + + private void updateValidGridProxySides() { + /* + * if (disabled) { + * getProxy().setValidSides(EnumSet.noneOf(ForgeDirection.class)); + * return; } + */ + getProxy().setValidSides(EnumSet.complementOf(EnumSet.of(ForgeDirection.UNKNOWN))); + + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + getProxy().writeToNBT(aNBT); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + getProxy().readFromNBT(aNBT); + super.loadNBTData(aNBT); + } + } diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/NBTHatchMEFocus.java b/src/main/java/reobf/proghatches/gt/metatileentity/NBTHatchMEFocus.java index abba9a6..2725fbb 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/NBTHatchMEFocus.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/NBTHatchMEFocus.java @@ -33,370 +33,396 @@ import gregtech.api.metatileentity.MetaTileEntity; import gtnhlanth.common.hatch.MTEBusInputFocus; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; import reobf.proghatches.gt.metatileentity.SuperChestME.UnlimitedWrapper; import reobf.proghatches.gt.metatileentity.util.IStoageCellUpdate; import reobf.proghatches.main.registration.Registration; -public class NBTHatchMEFocus extends MTEBusInputFocus implements ICellContainer, IGridProxyable, IStoageCellUpdate{ +public class NBTHatchMEFocus extends MTEBusInputFocus implements ICellContainer, IGridProxyable, IStoageCellUpdate { public NBTHatchMEFocus(int id, String name, String nameRegional) { super(id, name, nameRegional); - Registration.items.add(new ItemStack(GregTechAPI.sBlockMachines, 1, id)); + Registration.items.add(new ItemStack(GregTechAPI.sBlockMachines, 1, id)); } + public NBTHatchMEFocus(String name, String[] descriptionArray, ITexture[][][] textures) { super(name, descriptionArray, textures); - + } -String[] descCache; -@Override -public String[] getDescription() { - return descCache==null?(descCache=reobf.proghatches.main.Config.get("HMEF", ImmutableMap.of())):descCache; -} - /*@Override - public boolean isItemValidForUsageSlot(ItemStack aStack) { - return false; - }*/ + String[] descCache; + + @Override + public String[] getDescription() { + + return descCache == null ? (descCache = reobf.proghatches.main.Config.get("HMEF", ImmutableMap.of())) + : descCache; + } + + /* + * @Override public boolean isItemValidForUsageSlot(ItemStack aStack) { + * return false; } + */ @Override public IGridNode getActionableNode() { - + return getProxy().getNode(); } + @Override public IGridNode getGridNode(ForgeDirection dir) { - + return getProxy().getNode(); } + @Override public void securityBreak() { } - public int getIndex(){ - + + public int getIndex() { + return getInputSlotCount(); } - IMEInventoryHandler handler = new MEInventoryHandler(new UnlimitedWrapper(), StorageChannel.ITEMS) ; - public class UnlimitedWrapper implements IMEInventory { - - public UnlimitedWrapper() { - - } - - @Override - public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src) { - if (type != Actionable.SIMULATE)post(); - - if(input==null){ - return input; - } - if(!isItemValidForUsageSlot(input.getItemStack())){ - return input; - } - - try { - long l = input.getStackSize(); - long compl = 0; - if (l > Integer.MAX_VALUE) { - compl = l - Integer.MAX_VALUE; - } - ItemStack in = input.getItemStack(); - ItemStack thiz = mInventory[getIndex()]; - if (thiz != null && !Platform.isSameItem(in, thiz)) return input; - if (thiz == null) { - thiz = in.copy(); - thiz.stackSize = 0; - } - int space = Math.max(0, cap() - thiz.stackSize); - int transfer = Math.min(space, in.stackSize); - if (type == Actionable.SIMULATE) { - in.stackSize -= transfer; - if (in.stackSize <= 0 && compl == 0) in = null; - AEItemStack ret = AEItemStack.create(in); - if (ret != null) ret.incStackSize(compl); - return ret; - } - if (type == Actionable.MODULATE) { - thiz.stackSize += transfer; - mInventory[getIndex()] = thiz; - in.stackSize -= transfer; - if (in.stackSize <= 0 && compl == 0) in = null; - AEItemStack ret = AEItemStack.create(in); - if (ret != null) ret.incStackSize(compl); - return ret; - - } - - return null; - } finally { - last = AEItemStack.create(mInventory[getIndex()]); - - } - } - - - - @Override - public IAEItemStack extractItems(IAEItemStack input, Actionable type, BaseActionSource src) { - try { - - if (type != Actionable.SIMULATE) post(); - - ItemStack in = input.getItemStack(); - ItemStack thiz = mInventory[getIndex()]; - if (thiz != null && !Platform.isSameItem(in, thiz)) return null; - if (thiz == null) { - return null; - } // thiz=in.copy(); } - int transfer = Math.min(in.stackSize, thiz.stackSize); - if (transfer == 0) return null; - if (type == Actionable.SIMULATE) { - in.stackSize = transfer; - return AEItemStack.create(in); - - } - if (type == Actionable.MODULATE) { - thiz.stackSize -= transfer; - if (thiz.stackSize <= 0) thiz = null; - mInventory[getIndex()] = thiz; - in.stackSize = transfer; - return AEItemStack.create(in); - } - - return null; - } finally { - - last = AEItemStack.create(mInventory[getIndex()]); - } - } - - @Override - public IItemList getAvailableItems(IItemList out) { - if (mInventory[getIndex()] != null) out.addStorage(AEItemStack.create(mInventory[getIndex()])); - return out; - } - - @Override - public StorageChannel getChannel() { - - return StorageChannel.ITEMS; - } - } - - private AEItemStack last; - - private void post() { - - try { - - // this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate()); - // this.getProxy().getGrid().postEvent(new MENetworkStorageEvent(handler0, StorageChannel.ITEMS)); - try { - - if (last != null) { - if (mInventory[getIndex()] != null) { - if (last.equals(mInventory[getIndex()])) { - if (last.getStackSize() == mInventory[getIndex()].stackSize) { - return; - } else { - - this.getProxy() - .getStorage() - .postAlterationOfStoredItems( - StorageChannel.ITEMS, - ImmutableList.of( - last.copy() - .setStackSize(mInventory[getIndex()].stackSize - last.getStackSize())), - new MachineSource(this)); - last = AEItemStack.create(mInventory[getIndex()]); - return; - } - } - - } ; - - this.getProxy() - .getStorage() - .postAlterationOfStoredItems( - StorageChannel.ITEMS, - ImmutableList.of( - last.copy() - .setStackSize(-last.getStackSize())), - new MachineSource(this)); - } - last = AEItemStack.create(mInventory[getIndex()]); - if (last != null) { - this.getProxy() - .getStorage() - .postAlterationOfStoredItems( - StorageChannel.ITEMS, - ImmutableList.of( - last.copy() - .setStackSize(last.getStackSize())), - new MachineSource(this)); - } - - } catch (final GridAccessException ignore) {} - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } + + IMEInventoryHandler handler = new MEInventoryHandler(new UnlimitedWrapper(), StorageChannel.ITEMS); + + public class UnlimitedWrapper implements IMEInventory { + + public UnlimitedWrapper() { + + } + + @Override + public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src) { + if (type != Actionable.SIMULATE) + post(); + + if (input == null) { + return input; + } + if (!isItemValidForUsageSlot(input.getItemStack())) { + return input; + } + + try { + long l = input.getStackSize(); + long compl = 0; + if (l > Integer.MAX_VALUE) { + compl = l - Integer.MAX_VALUE; + } + ItemStack in = input.getItemStack(); + ItemStack thiz = mInventory[getIndex()]; + if (thiz != null && !Platform.isSameItem(in, thiz)) + return input; + if (thiz == null) { + thiz = in.copy(); + thiz.stackSize = 0; + } + int space = Math.max(0, cap() - thiz.stackSize); + int transfer = Math.min(space, in.stackSize); + if (type == Actionable.SIMULATE) { + in.stackSize -= transfer; + if (in.stackSize <= 0 && compl == 0) + in = null; + AEItemStack ret = AEItemStack.create(in); + if (ret != null) + ret.incStackSize(compl); + return ret; + } + if (type == Actionable.MODULATE) { + thiz.stackSize += transfer; + mInventory[getIndex()] = thiz; + in.stackSize -= transfer; + if (in.stackSize <= 0 && compl == 0) + in = null; + AEItemStack ret = AEItemStack.create(in); + if (ret != null) + ret.incStackSize(compl); + return ret; + + } + + return null; + } finally { + last = AEItemStack.create(mInventory[getIndex()]); + + } + } + + @Override + public IAEItemStack extractItems(IAEItemStack input, Actionable type, BaseActionSource src) { + try { + + if (type != Actionable.SIMULATE) + post(); + + ItemStack in = input.getItemStack(); + ItemStack thiz = mInventory[getIndex()]; + if (thiz != null && !Platform.isSameItem(in, thiz)) + return null; + if (thiz == null) { + return null; + } // thiz=in.copy(); } + int transfer = Math.min(in.stackSize, thiz.stackSize); + if (transfer == 0) + return null; + if (type == Actionable.SIMULATE) { + in.stackSize = transfer; + return AEItemStack.create(in); + + } + if (type == Actionable.MODULATE) { + thiz.stackSize -= transfer; + if (thiz.stackSize <= 0) + thiz = null; + mInventory[getIndex()] = thiz; + in.stackSize = transfer; + return AEItemStack.create(in); + } + + return null; + } finally { + + last = AEItemStack.create(mInventory[getIndex()]); + } + } + + @Override + public IItemList getAvailableItems(IItemList out) { + if (mInventory[getIndex()] != null) + out.addStorage(AEItemStack.create(mInventory[getIndex()])); + return out; + } + + @Override + public StorageChannel getChannel() { + + return StorageChannel.ITEMS; + } + } + + private AEItemStack last; + + private void post() { + + try { + + // this.getProxy().getGrid().postEvent(new + // MENetworkCellArrayUpdate()); + // this.getProxy().getGrid().postEvent(new + // MENetworkStorageEvent(handler0, StorageChannel.ITEMS)); + try { + + if (last != null) { + if (mInventory[getIndex()] != null) { + if (last.equals(mInventory[getIndex()])) { + if (last.getStackSize() == mInventory[getIndex()].stackSize) { + return; + } else { + + this.getProxy().getStorage().postAlterationOfStoredItems(StorageChannel.ITEMS, + ImmutableList.of(last.copy() + .setStackSize(mInventory[getIndex()].stackSize - last.getStackSize())), + new MachineSource(this)); + last = AEItemStack.create(mInventory[getIndex()]); + return; + } + } + + } + ; + + this.getProxy().getStorage().postAlterationOfStoredItems(StorageChannel.ITEMS, + ImmutableList.of(last.copy().setStackSize(-last.getStackSize())), new MachineSource(this)); + } + last = AEItemStack.create(mInventory[getIndex()]); + if (last != null) { + this.getProxy().getStorage().postAlterationOfStoredItems(StorageChannel.ITEMS, + ImmutableList.of(last.copy().setStackSize(last.getStackSize())), new MachineSource(this)); + } + + } catch (final GridAccessException ignore) { + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + @Override public List getCellArray(StorageChannel channel) { - if(channel==StorageChannel.FLUIDS)return ImmutableList.of(); - + if (channel == StorageChannel.FLUIDS) + return ImmutableList.of(); + return ImmutableList.of(handler); } + @Override public int getPriority() { - + return 0; } + @Override public void saveChanges(IMEInventory cellInventory) { markDirty(); - + } + @Override public void cellUpdate() { markDirty(); - update = true; + update = true; } + @Override public DimensionalCoord getLocation() { - - return new DimensionalCoord((TileEntity)this.getBaseMetaTileEntity()); + + return new DimensionalCoord((TileEntity) this.getBaseMetaTileEntity()); } + AENetworkProxy gridProxy; + @Override - public AENetworkProxy getProxy() { - + public AENetworkProxy getProxy() { + if (gridProxy == null) { - gridProxy = new AENetworkProxy(this, "proxy", visualStack(), true); - gridProxy.setFlags(GridFlags.REQUIRE_CHANNEL); - updateValidGridProxySides(); - if (getBaseMetaTileEntity().getWorld() != null) gridProxy.setOwner( - getBaseMetaTileEntity().getWorld() - .getPlayerEntityByName(getBaseMetaTileEntity().getOwnerName())); - } - - return this.gridProxy;} - + gridProxy = new AENetworkProxy(this, "proxy", visualStack(), true); + gridProxy.setFlags(GridFlags.REQUIRE_CHANNEL); + updateValidGridProxySides(); + if (getBaseMetaTileEntity().getWorld() != null) + gridProxy.setOwner(getBaseMetaTileEntity().getWorld() + .getPlayerEntityByName(getBaseMetaTileEntity().getOwnerName())); + } + + return this.gridProxy; + } + private ItemStack visualStack() { - return new ItemStack(GregTechAPI.sBlockMachines, 1, getBaseMetaTileEntity().getMetaTileID()); - } - - @Override - public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { - - super.onFirstTick(aBaseMetaTileEntity); - getProxy().onReady(); - // onColorChangeServer(aBaseMetaTileEntity.getColorization()); - post(); - } boolean wasActive; - boolean update; - int rep; - public void updateStatus() { - - post(); - - } - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - - boolean active = this.getProxy() - .isActive(); - if (!aBaseMetaTileEntity.getWorld().isRemote) { - if (aTick % 40 == 1) { - post(); - } - - if (rep > 0) { - rep--; - update = true; - } - if (this.getBaseMetaTileEntity() - .hasInventoryBeenModified()) { - update = true; - rep = 1; - } ; - - if (update) { - update = false; - updateStatus(); - } - if (wasActive != active) { - wasActive = active; - - try { - this.getProxy() - .getGrid() - .postEvent(new MENetworkCellArrayUpdate()); - } catch (GridAccessException e) { - - } - post(); - } - - - - if (!aBaseMetaTileEntity.getWorld().isRemote && (aTick & 16) != 0) { - this.getBaseMetaTileEntity() - .setActive( - this.getProxy() - .isPowered() && active); - - } - - - - } - super.onPostTick(aBaseMetaTileEntity, aTick); - - if (aBaseMetaTileEntity.getWorld().isRemote) { - return; - } - - boolean needToSort = false; - for (int i = 1; i < mInventory.length; i++) { - ItemStack is = mInventory[i]; - if (is == null) continue; - markDirty(); - if (mInventory[getIndex()] == null) { - mInventory[getIndex()] = is.copy(); - mInventory[i] = null; - } else if (cap() - is.stackSize >= mInventory[getIndex()].stackSize) { - mInventory[getIndex()].stackSize += is.stackSize; - mInventory[i] = null; - } else { - int to = Math.min(cap() - mInventory[getIndex()].stackSize, is.stackSize); - mInventory[getIndex()].stackSize += to; - mInventory[i].stackSize -= to; - needToSort = true; - } - } - if (needToSort) fillStacksIntoFirstSlots(); - - } - private int cap() { - - return 1; + return new ItemStack(GregTechAPI.sBlockMachines, 1, getBaseMetaTileEntity().getMetaTileID()); + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + + super.onFirstTick(aBaseMetaTileEntity); + getProxy().onReady(); + // onColorChangeServer(aBaseMetaTileEntity.getColorization()); + post(); + } + + boolean wasActive; + boolean update; + int rep; + + public void updateStatus() { + + post(); + + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + + boolean active = this.getProxy().isActive(); + if (!aBaseMetaTileEntity.getWorld().isRemote) { + if (aTick % 40 == 1) { + post(); + } + + if (rep > 0) { + rep--; + update = true; + } + if (this.getBaseMetaTileEntity().hasInventoryBeenModified()) { + update = true; + rep = 1; + } + ; + + if (update) { + update = false; + updateStatus(); + } + if (wasActive != active) { + wasActive = active; + + try { + this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate()); + } catch (GridAccessException e) { + + } + post(); + } + + if (!aBaseMetaTileEntity.getWorld().isRemote && (aTick & 16) != 0) { + this.getBaseMetaTileEntity().setActive(this.getProxy().isPowered() && active); + + } + } - - @Override + super.onPostTick(aBaseMetaTileEntity, aTick); + + if (aBaseMetaTileEntity.getWorld().isRemote) { + return; + } + + boolean needToSort = false; + for (int i = 1; i < mInventory.length; i++) { + ItemStack is = mInventory[i]; + if (is == null) + continue; + markDirty(); + if (mInventory[getIndex()] == null) { + mInventory[getIndex()] = is.copy(); + mInventory[i] = null; + } else if (cap() - is.stackSize >= mInventory[getIndex()].stackSize) { + mInventory[getIndex()].stackSize += is.stackSize; + mInventory[i] = null; + } else { + int to = Math.min(cap() - mInventory[getIndex()].stackSize, is.stackSize); + mInventory[getIndex()].stackSize += to; + mInventory[i].stackSize -= to; + needToSort = true; + } + } + if (needToSort) + fillStacksIntoFirstSlots(); + + } + + private int cap() { + + return 1; + } + + @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - + return new NBTHatchMEFocus(mName, mDescriptionArray, mTextures); } - private void updateValidGridProxySides() { - /* - * if (disabled) { - * getProxy().setValidSides(EnumSet.noneOf(ForgeDirection.class)); - * return; - * } - */ - getProxy().setValidSides(EnumSet.complementOf(EnumSet.of(ForgeDirection.UNKNOWN))); - - } + + private void updateValidGridProxySides() { + /* + * if (disabled) { + * getProxy().setValidSides(EnumSet.noneOf(ForgeDirection.class)); + * return; } + */ + getProxy().setValidSides(EnumSet.complementOf(EnumSet.of(ForgeDirection.UNKNOWN))); + + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + getProxy().writeToNBT(aNBT); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + getProxy().readFromNBT(aNBT); + super.loadNBTData(aNBT); + } } diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/StockingDualInputHatchME.java b/src/main/java/reobf/proghatches/gt/metatileentity/StockingDualInputHatchME.java new file mode 100644 index 0000000..c850ee3 --- /dev/null +++ b/src/main/java/reobf/proghatches/gt/metatileentity/StockingDualInputHatchME.java @@ -0,0 +1,1007 @@ +package reobf.proghatches.gt.metatileentity; + +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_INPUT_HATCH_ACTIVE; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_INPUT_FLUID_HATCH_ACTIVE; +import static kubatech.api.Variables.numberFormat; +import static kubatech.api.Variables.numberFormatScientific; + +import java.math.BigInteger; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.EnumSet; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import com.gtnewhorizons.modularui.api.ModularUITextures; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; +import com.gtnewhorizons.modularui.api.drawable.Text; +import com.gtnewhorizons.modularui.api.drawable.UITexture; +import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; +import com.gtnewhorizons.modularui.api.math.Alignment; +import com.gtnewhorizons.modularui.api.math.Color; +import com.gtnewhorizons.modularui.api.math.Pos2d; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.api.screen.ModularWindow.Builder; +import com.gtnewhorizons.modularui.api.widget.Interactable; +import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.api.widget.Widget.ClickData; +import com.gtnewhorizons.modularui.common.fluid.FluidStackTank; +import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.DynamicTextWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.FluidSlotWidget; +import com.gtnewhorizons.modularui.common.widget.MultiChildWidget; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TabButton; +import com.gtnewhorizons.modularui.common.widget.TabContainer; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.NumericWidget; + +import appeng.api.config.Actionable; +import appeng.api.config.FuzzyMode; +import appeng.api.implementations.IPowerChannelState; +import appeng.api.networking.GridFlags; +import appeng.api.networking.security.IActionHost; +import appeng.api.networking.security.MachineSource; +import appeng.api.storage.IMEMonitor; +import appeng.api.storage.data.IAEFluidStack; +import appeng.api.storage.data.IAEItemStack; +import appeng.me.GridAccessException; +import appeng.me.helpers.AENetworkProxy; +import appeng.me.helpers.IGridProxyable; +import appeng.util.item.AEFluidStack; +import appeng.util.item.AEItemStack; +import codechicken.nei.NEIClientUtils; +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.GregTechAPI; +import gregtech.api.enums.Materials; +import gregtech.api.enums.MaterialsUEVplus; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.gui.modularui.GTUITextures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.MTEHatchInputBus; +import gregtech.api.metatileentity.implementations.MTEMultiBlockBase; +import gregtech.api.objects.GTDualInputs; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.util.GTOreDictUnificator; +import gregtech.api.util.GTUtility; +import gregtech.api.util.shutdown.ShutDownReason; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; +import gregtech.common.gui.modularui.widget.AESlotWidget; +import gregtech.common.tileentities.machines.IDualInputHatch; +import gregtech.common.tileentities.machines.IDualInputInventory; +import kubatech.api.enums.ItemList; +import kubatech.api.tea.TeaNetwork; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; +import reobf.proghatches.gt.metatileentity.util.IRecipeProcessingAwareDualHatch; +import reobf.proghatches.item.ItemProgrammingCircuit; +import reobf.proghatches.main.MyMod; +import reobf.proghatches.main.registration.Registration; + +public class StockingDualInputHatchME extends MTEHatchInputBus + implements IDualInputHatch, IRecipeProcessingAwareDualHatch, IPowerChannelState + +{ + + public StockingDualInputHatchME(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, boolean allowAuto2) { + super(aName, aTier, 1, aDescription, aTextures); + allowAuto=allowAuto2; + } + + public StockingDualInputHatchME(int id, String name, String nameRegional, int tier,boolean a) { + super(id, name, nameRegional, tier, 1, reobf.proghatches.main.Config.get( + "SDIHME", ImmutableMap.of())); + Registration.items.add(new ItemStack(GregTechAPI.sBlockMachines, 1, id)); + allowAuto=a; + } + boolean allowAuto; + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + + return new StockingDualInputHatchME(mName, mTier, mDescriptionArray, mTextures,allowAuto); + } + + @Override + public int getCircuitSlot() { + + return 0; + } + + @Override + public int getCircuitSlotX() { + // TODO Auto-generated method stub + return 153 - 1 - 18 * 4; + } + + @Override + public int getCircuitSlotY() { + // TODO Auto-generated method stub + return super.getCircuitSlotY() + 1; + } + + private boolean autoPullItemList; + private long minAutoPullStackSize; + private int interval=1; + + public ItemStack updateInformationSlot(int aIndex, ItemStack aStack) { + + if (aStack == null) { + inventoryHandlerDisplay.setStackInSlot(aIndex, null); + } else { + AENetworkProxy proxy = getProxy(); + if (!proxy.isActive()) { + inventoryHandlerDisplay.setStackInSlot(aIndex, null); + return null; + } + try { + IMEMonitor sg = proxy.getStorage().getItemInventory(); + IAEItemStack request = AEItemStack.create(i_mark[aIndex]); + request.setStackSize(Integer.MAX_VALUE); + IAEItemStack result = sg.extractItems(request, Actionable.SIMULATE, source); + ItemStack s = (result != null) ? result.getItemStack() : null; + // We want to track changes in any ItemStack to notify any + // connected controllers to make a recipe + // check early + /* + * if (expediteRecipeCheck) { ItemStack previous = + * getStackInSlot(aIndex + SLOT_COUNT); if (s != null) { + * justHadNewItems = !ItemStack.areItemStacksEqual(s, previous); + * } } + */ + inventoryHandlerDisplay.setStackInSlot(aIndex, s); + return s; + } catch (final GridAccessException ignored) { + } + } + + return null; + } + + public void updateInformationSlotF(int index) { + + FluidStack fluidStack = f_mark[index]; + if (fluidStack == null) { + f_display[index] = null; + return; + } + + AENetworkProxy proxy = getProxy(); + if (proxy == null || !proxy.isActive()) { + f_display[index] = null; + return; + } + + try { + IMEMonitor sg = proxy.getStorage().getFluidInventory(); + IAEFluidStack request = AEFluidStack.create(fluidStack); + request.setStackSize(Integer.MAX_VALUE); + IAEFluidStack result = sg.extractItems(request, Actionable.SIMULATE, source); + FluidStack resultFluid = (result != null) ? result.getFluidStack() : null; + // We want to track if any FluidStack is modified to notify any + // connected controllers to make a recipe check + // early + /* + * if (expediteRecipeCheck) { FluidStack previous = + * storedInformationFluids[index]; if (resultFluid != null) { + * justHadNewFluids = !resultFluid.isFluidEqual(previous); } } + */ + f_display[index] = resultFluid; + } catch (final GridAccessException ignored) { + } + + } + + private FluidStackTank createTankForFluidStack(FluidStack[] fluidStacks, int slotIndex, int capacity) { + return new FluidStackTank(() -> fluidStacks[slotIndex], (stack) -> { + if (getBaseMetaTileEntity().isServerSide()) { + return; + } + + fluidStacks[slotIndex] = stack; + }, capacity); + } + + @Override + public void addUIWidgets(Builder builder, UIBuildContext buildContext) { + final SlotWidget[] aeSlotWidgets = new SlotWidget[16]; + builder.setBackground(ModularUITextures.VANILLA_BACKGROUND); + + IDrawable tab1 = new ItemDrawable(gregtech.api.enums.ItemList.Hatch_Input_Bus_ME_Advanced.get(1)) + .withFixedSize(18, 18, 4, 4); + IDrawable tab2 = new ItemDrawable(gregtech.api.enums.ItemList.Hatch_Input_ME_Advanced.get(1)) + .withFixedSize(18, 18, 4, 4); + IDrawable tab3 = new ItemDrawable(GTOreDictUnificator.get(OrePrefixes.gearGt, Materials.Iron, 1)) + .withFixedSize(18, 18, 4, 4); + + builder.widget(new TabContainer().setButtonSize(28, 32) + .addTabButton(new TabButton(0) + .setBackground(true, + ModularUITextures.VANILLA_TAB_RIGHT.getSubArea(0f, 0f, 1f, 1 / 3f).getSubArea(0, 0, + 0.5f, 1f), + tab1) + .setBackground(false, + ModularUITextures.VANILLA_TAB_RIGHT.getSubArea(0f, 0f, 1f, 1 / 3f).getSubArea(0.5f, 0, + 1f, 1f), + tab1) + .setPos(getGUIWidth() - 4, 0)) + .addTabButton(new TabButton(1) + .setBackground(true, + ModularUITextures.VANILLA_TAB_RIGHT.getSubArea(0f, 1 / 3f, 1f, 2 / 3f).getSubArea(0, 0, + 0.5f, 1f), + tab2) + .setBackground(false, + ModularUITextures.VANILLA_TAB_RIGHT.getSubArea(0f, 1 / 3f, 1f, 2 / 3f).getSubArea(0.5f, + 0, 1f, 1f), + tab2) + .setPos(getGUIWidth() - 4, 28)) + .addTabButton(new TabButton(2) + .setBackground(true, + ModularUITextures.VANILLA_TAB_RIGHT.getSubArea(0f, 1 / 3f, 1f, 2 / 3f).getSubArea(0, 0, + 0.5f, 1f), + tab3) + .setBackground(false, + ModularUITextures.VANILLA_TAB_RIGHT.getSubArea(0f, 1 / 3f, 1f, 2 / 3f).getSubArea(0.5f, + 0, 1f, 1f), + tab3) + .setPos(getGUIWidth() - 4, 56)) + .addPage( + new MultiChildWidget() + .addChild( + SlotGroup.ofItemHandler(inventoryHandlerDisplay, 4).startFromSlot(0) + .endAtSlot(15).phantom(true).background(GTUITextures.SLOT_DARK_GRAY) + .widgetCreator(slot -> aeSlotWidgets[slot + .getSlotIndex()] = new AESlotWidget(slot).disableInteraction()) + .build().setPos(97, 9)) + + .addChild(SlotGroup.ofItemHandler(inventoryHandlerMark, 4).startFromSlot(0) + .endAtSlot(15).phantom(true) + .slotCreator(index -> new BaseSlot(inventoryHandlerMark, index, true) { + + @Override + public boolean isEnabled() { + return !autoPullItemList && super.isEnabled(); + } + }).widgetCreator(slot -> (SlotWidget) new SlotWidget(slot) { + + @Override + protected void phantomClick(ClickData clickData, ItemStack cursorStack) { + if (clickData.mouseButton != 0 || !getMcSlot().isEnabled()) + return; + final int aSlotIndex = getMcSlot().getSlotIndex(); + if (cursorStack == null) { + getMcSlot().putStack(null); + } else { + if (containsSuchStack(cursorStack)) + return; + getMcSlot().putStack(GTUtility.copyAmount(1, cursorStack)); + } + if (getBaseMetaTileEntity().isServerSide()) { + final ItemStack newInfo = updateInformationSlot(aSlotIndex, + cursorStack); + aeSlotWidgets[getMcSlot().getSlotIndex()].getMcSlot() + .putStack(newInfo); + } + } + + @Override + public IDrawable[] getBackground() { + IDrawable slot; + if (autoPullItemList) { + slot = GTUITextures.SLOT_DARK_GRAY; + } else { + slot = ModularUITextures.ITEM_SLOT; + } + return new IDrawable[] { slot, GTUITextures.OVERLAY_SLOT_ARROW_ME }; + } + + @Override + public List getExtraTooltip() { + if (autoPullItemList) { + return Collections.singletonList(StatCollector.translateToLocal( + "GT5U.machines.stocking_bus.cannot_set_slot")); + } else { + return Collections.singletonList(StatCollector + .translateToLocal("modularui.phantom.single.clear")); + } + } + + private boolean containsSuchStack(ItemStack tStack) { + for (int i = 0; i < 16; ++i) { + if (GTUtility.areStacksEqual(i_mark[i], tStack, false)) + return true; + } + return false; + } + }.dynamicTooltip(() -> { + if (autoPullItemList) { + return Collections.singletonList(StatCollector.translateToLocal( + "GT5U.machines.stocking_bus.cannot_set_slot")); + } else { + return Collections.emptyList(); + } + }).setUpdateTooltipEveryTick(true)).build().setPos(7, 9)) + + ).addPage(new MultiChildWidget().addChild( + + SlotGroup + .ofFluidTanks(IntStream.range(0, 16) + .mapToObj(index -> createTankForFluidStack(f_mark, index, 1)) + .collect(Collectors.toList()), 4) + .phantom(true) + .widgetCreator((slotIndex, h) -> (FluidSlotWidget) new FluidSlotWidget(h) { + + @Override + protected void tryClickPhantom(ClickData clickData, ItemStack cursorStack) { + if (clickData.mouseButton != 0 || autoPullItemList) + return; + + FluidStack heldFluid = getFluidForPhantomItem(cursorStack); + if (cursorStack == null) { + f_mark[slotIndex] = null; + } else { + if (containsSuchStack(heldFluid)) + return; + f_mark[slotIndex] = heldFluid; + } + if (getBaseMetaTileEntity().isServerSide()) { + updateInformationSlotF(slotIndex); + detectAndSendChanges(false); + } + } + + private boolean containsSuchStack(FluidStack tStack) { + for (int i = 0; i < 16; ++i) { + if (GTUtility.areFluidsEqual(f_mark[i], tStack, false)) { + return true; + } + } + return false; + } + + @Override + protected void tryScrollPhantom(int direction) { + } + + @Override + public IDrawable[] getBackground() { + IDrawable slot; + if (autoPullItemList) { + slot = GTUITextures.SLOT_DARK_GRAY; + } else { + slot = ModularUITextures.FLUID_SLOT; + } + return new IDrawable[] { slot, GTUITextures.OVERLAY_SLOT_ARROW_ME }; + } + + @Override + public void buildTooltip(List tooltip) { + FluidStack fluid = getContent(); + if (fluid != null) { + addFluidNameInfo(tooltip, fluid); + + if (!autoPullItemList) { + tooltip.add(Text.localised("modularui.phantom.single.clear")); + } + } else { + tooltip.add(Text.localised("modularui.fluid.empty") + .format(EnumChatFormatting.WHITE)); + } + + if (autoPullItemList) { + tooltip.add(Text.localised("GT5U.machines.stocking_bus.cannot_set_slot")); + } + } + }.setUpdateTooltipEveryTick(true)).build().setPos(new Pos2d(7, 9)) + + ).addChild(SlotGroup.ofFluidTanks(IntStream.range(0, 16).mapToObj(index -> createTankForFluidStack(f_display, index, Integer.MAX_VALUE)).collect(Collectors.toList()), 4).phantom(true).widgetCreator((slotIndex, h) -> (FluidSlotWidget) new FluidSlotWidget(h) { + + @Override + protected void tryClickPhantom(ClickData clickData, ItemStack cursorStack) { + } + + @Override + protected void tryScrollPhantom(int direction) { + } + + @Override + public void buildTooltip(List tooltip) { + FluidStack fluid = getContent(); + if (fluid != null) { + addFluidNameInfo(tooltip, fluid); + tooltip.add(Text.localised("modularui.fluid.phantom.amount", fluid.amount)); + addAdditionalFluidInfo(tooltip, fluid); + if (!Interactable.hasShiftDown()) { + tooltip.add(Text.EMPTY); + tooltip.add(Text.localised("modularui.tooltip.shift")); + } + } else { + tooltip.add(Text.localised("modularui.fluid.empty").format(EnumChatFormatting.WHITE)); + } + } + }.setUpdateTooltipEveryTick(true)).background(GTUITextures.SLOT_DARK_GRAY).controlsAmount(true).build() + .setPos(new Pos2d(97, 9))) + + ).addPage( + new MultiChildWidget().addChild(TextWidget.localised("GT5U.machines.stocking_bus.refresh_time").setPos(3, 42).setSize(74, 14)).addChild(new NumericWidget().setSetter(val -> interval = (int) val).setGetter(() -> interval).setBounds(1, Integer.MAX_VALUE).setScrollValues(1, 4, 64).setTextAlignment(Alignment.Center).setTextColor(Color.WHITE.normal).setSize(70, 18).setPos(3, 3).setBackground(GTUITextures.BACKGROUND_TEXT_FIELD)) + .addChild(new ButtonWidget().setOnClick((clickData, widget) -> { + if (clickData.mouseButton == 0) { + if(allowAuto) + setAutoPullItemList(!autoPullItemList); + } else if (clickData.mouseButton == 1 && !widget.isClient()) { + /* + * widget.getContext() + * .openSyncedWindow(CONFIG_WINDOW_ID); + */ + } + }).setBackground(() -> { + if (autoPullItemList) { + return new IDrawable[] { GTUITextures.BUTTON_STANDARD_PRESSED, + GTUITextures.OVERLAY_BUTTON_AUTOPULL_ME }; + } else { + return new IDrawable[] { GTUITextures.BUTTON_STANDARD, + GTUITextures.OVERLAY_BUTTON_AUTOPULL_ME_DISABLED }; + } + }).addTooltips( + Arrays.asList(StatCollector.translateToLocal("GT5U.machines.stocking_bus.auto_pull.tooltip.1"), + StatCollector.translateToLocal("GT5U.machines.stocking_bus.auto_pull.tooltip.2"))) + .setSize(16, 16).setPos(80, 3)) + .addChild(new ButtonWidget().setOnClick((clickData, widget) -> { + if (clickData.mouseButton == 0) { + + program=!program; + } else if (clickData.mouseButton == 1 && !widget.isClient()) { + /* + * widget.getContext() + * .openSyncedWindow(CONFIG_WINDOW_ID); + */ + } + }).setBackground(() -> { + if (program) { + return new IDrawable[] { GTUITextures.BUTTON_STANDARD_PRESSED, + new ItemDrawable(GTUtility.getIntegratedCircuit(0)) + /*GTUITextures.OVERLAY_BUTTON_AUTOPULL_ME*/ }; + } else { + return new IDrawable[] { GTUITextures.BUTTON_STANDARD, + new ItemDrawable(GTUtility.getIntegratedCircuit(0))}; + } + }).addTooltips( + Arrays.asList(StatCollector.translateToLocal("hatch.dualinput.stocking.autopull.program") + )) + .setSize(16, 16).setPos(80, 3+20)) + + + + + + )) + + ; + builder.widget(new FakeSyncWidget.BooleanSyncer(() -> program, + s->{program=s;})); + builder.widget(new FakeSyncWidget.BooleanSyncer(() -> autoPullItemList, + StockingDualInputHatchME.this::setAutoPullItemList)); + // return builder; + } + + protected void setAutoPullItemList(boolean pullItemList) { + + autoPullItemList = pullItemList; + if (!autoPullItemList) { + for (int i = 0; i < 16; i++) { + i_mark[i] = null; + f_mark[i] = null; + } + } else { + refreshItemList(); + refreshItemListF(); + } + updateAllInformationSlots(); + } + + protected void refreshItemList() { + AENetworkProxy proxy = getProxy(); + try { + IMEMonitor sg = proxy.getStorage().getItemInventory(); + Iterator iterator = sg.getStorageList().iterator(); + int index = 0; + while (iterator.hasNext() && index < 16) { + IAEItemStack currItem = iterator.next(); + if (currItem.getStackSize() >= minAutoPullStackSize) { + ItemStack itemstack = GTUtility.copyAmount(1, currItem.getItemStack()); + /* + * if (expediteRecipeCheck) { ItemStack previous = + * this.mInventory[index]; if (itemstack != null) { + * justHadNewItems = + * !ItemStack.areItemStacksEqual(itemstack, previous); } } + */ + this.i_mark[index] = itemstack; + index++; + } + } + for (int i = index; i < 16; i++) { + i_mark[i] = null; + } + + } catch (final GridAccessException ignored) { + } + } + + protected void refreshItemListF() { + AENetworkProxy proxy = getProxy(); + try { + IMEMonitor sg = proxy.getStorage().getFluidInventory(); + Iterator iterator = sg.getStorageList().iterator(); + int index = 0; + while (iterator.hasNext() && index < 16) { + IAEFluidStack currItem = iterator.next(); + if (currItem.getStackSize() >= minAutoPullStackSize) { + FluidStack itemstack = GTUtility.copyAmount(1, currItem.getFluidStack()); + /* + * if (expediteRecipeCheck) { ItemStack previous = + * this.mInventory[index]; if (itemstack != null) { + * justHadNewItems = + * !ItemStack.areItemStacksEqual(itemstack, previous); } } + */ + this.f_mark[index] = itemstack; + index++; + } + } + for (int i = index; i < 16; i++) { + f_mark[i] = null; + } + + } catch (final GridAccessException ignored) { + } + } + + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (getBaseMetaTileEntity().isServerSide()) {program(); + if (aTimer % interval == 0 && autoPullItemList) { + refreshItemList(); + refreshItemListF(); + } + if (aTimer % 20 == 0) { + getBaseMetaTileEntity().setActive(isActive()); + } + } + + super.onPostTick(aBaseMetaTileEntity, aTimer); + }; + boolean program; +public void program(){ + + if(program) + try { + + + for(IAEItemStack s:getProxy().getStorage().getItemInventory().getStorageList()) + { + IAEItemStack ext = getProxy().getStorage().getItemInventory().extractItems(s, Actionable.MODULATE, source); + if(ext!=null&&ext.getStackSize()>0){ + ItemStack item = ext.getItemStack(); + item.stackSize=0; + this.setInventorySlotContents(getCircuitSlot(),ItemProgrammingCircuit.getCircuit(item).orElse(null)); + + } + } + + + + } catch (GridAccessException e) { + } +} + MachineSource source = new MachineSource(((IActionHost) getBaseMetaTileEntity())); + boolean recipe; + + @Override + public void startRecipeProcessing() { + recipe = true;program(); + for (int i = 0; i < 16; i++) { + i_shadow[i] = null; + i_saved[i] = 0; + if (i_mark[i] != null) { + + try { + IAEItemStack possible = getProxy().getStorage().getItemInventory().extractItems( + AEItemStack.create(i_mark[i]).setStackSize(Integer.MAX_VALUE), Actionable.SIMULATE, source); + i_shadow[i] = possible == null ? null : possible.getItemStack(); + if (i_shadow[i] != null) + i_saved[i] = i_shadow[i].stackSize; + + } catch (GridAccessException e) { + } + } + } + for (int i = 0; i < 16; i++) { + f_shadow[i] = null; + f_saved[i] = 0; + if (f_mark[i] != null) { + + try { + IAEFluidStack possible = getProxy().getStorage().getFluidInventory().extractItems( + AEFluidStack.create(f_mark[i]).setStackSize(Integer.MAX_VALUE), Actionable.SIMULATE, + source); + f_shadow[i] = possible == null ? null : possible.getFluidStack(); + if (f_shadow[i] != null) + f_saved[i] = f_shadow[i].amount; + + } catch (GridAccessException e) { + } + } + } + } + + @Override + public CheckRecipeResult endRecipeProcessing(MTEMultiBlockBase controller) { + recipe = false; + for (int i = 0; i < 16; i++) { + int current = i_shadow[i] == null ? 0 : i_shadow[i].stackSize; + int original = i_saved[i]; + if (current > original) { + throw new AssertionError("?"); + } + if (current < 0) { + throw new AssertionError("??"); + } + if (current < original) { + int delta = original - current; + if (i_mark[i] == null) { + MyMod.LOG.fatal("marked item missing!"); + controller.stopMachine(ShutDownReasonRegistry.CRITICAL_NONE); + return SimpleCheckRecipeResult.ofFailurePersistOnShutdown("stocking_bus_fail_extraction"); + } + IAEItemStack toextract = AEItemStack.create(i_mark[i]).setStackSize(delta); + try { + IAEItemStack get = getProxy().getStorage().getItemInventory().extractItems(toextract, + Actionable.MODULATE, source); + if (get == null || get.getStackSize() != get.getStackSize()) { + MyMod.LOG.fatal("cannot extract!"); + controller.stopMachine(ShutDownReasonRegistry.CRITICAL_NONE); + return SimpleCheckRecipeResult.ofFailurePersistOnShutdown("stocking_bus_fail_extraction"); + } + } catch (GridAccessException e) { + e.printStackTrace(); + controller.stopMachine(ShutDownReasonRegistry.CRITICAL_NONE); + return SimpleCheckRecipeResult.ofFailurePersistOnShutdown("stocking_bus_fail_extraction"); + } + + } + + } + + for (int i = 0; i < 16; i++) { + int current = f_shadow[i] == null ? 0 : f_shadow[i].amount; + int original = f_saved[i]; + if (current > original) { + throw new AssertionError("?"); + } + if (current < 0) { + throw new AssertionError("??"); + } + if (current < original) { + int delta = original - current; + if (f_mark[i] == null) { + MyMod.LOG.fatal("marked fluid missing!"); + controller.stopMachine(ShutDownReasonRegistry.CRITICAL_NONE); + return SimpleCheckRecipeResult.ofFailurePersistOnShutdown("stocking_bus_fail_extraction"); + } + IAEFluidStack toextract = AEFluidStack.create(f_mark[i]).setStackSize(delta); + try { + IAEFluidStack get = getProxy().getStorage().getFluidInventory().extractItems(toextract, + Actionable.MODULATE, source); + if (get == null || get.getStackSize() != get.getStackSize()) { + MyMod.LOG.fatal("cannot extract!"); + controller.stopMachine(ShutDownReasonRegistry.CRITICAL_NONE); + return SimpleCheckRecipeResult.ofFailurePersistOnShutdown("stocking_bus_fail_extraction"); + } + } catch (GridAccessException e) { + e.printStackTrace(); + controller.stopMachine(ShutDownReasonRegistry.CRITICAL_NONE); + return SimpleCheckRecipeResult.ofFailurePersistOnShutdown("stocking_bus_fail_extraction"); + } + + } + + } + + updateAllInformationSlots(); + return CheckRecipeResultRegistry.SUCCESSFUL; + } + + protected void updateAllInformationSlots() { + for (int index = 0; index < 16; index++) { + updateInformationSlot(index, i_mark[index]); + } + + for (int index = 0; index < 16; index++) { + updateInformationSlotF(index/* , f_mark[index] */); + } + + } + + ItemStack[] i_mark = new ItemStack[16]; + ItemStack[] i_shadow = new ItemStack[16]; + ItemStack[] i_display = new ItemStack[16]; + int[] i_saved = new int[16]; + FluidStack[] f_mark = new FluidStack[16]; + FluidStack[] f_shadow = new FluidStack[16]; + FluidStack[] f_display = new FluidStack[16]; + int[] f_saved = new int[16]; + + @Override + public boolean justUpdated() { + return false; + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + + super.onFirstTick(aBaseMetaTileEntity); + getProxy().onReady(); + + } + + @Override + public Iterator inventories() { + if (!recipe) { + return (Iterator) new ArrayList().iterator();// huh... + } + + return isEmpty() ? (Iterator) new ArrayList().iterator() : getItr(); + } + + public boolean isEmpty() { + for (ItemStack i : i_shadow) { + if (i != null && i.stackSize > 0) + return false; + } + for (FluidStack i : f_shadow) { + if (i != null && i.amount > 0) + return false; + } + return true; + } + + private Iterator getItr() { + + IDualInputInventory xx = new IDualInputInventory() { + + @Override + public boolean isEmpty() { + return false; + } + + @Override + public ItemStack[] getItemInputs() { + return DualInputHatch.filterStack.apply(i_shadow, new ItemStack[] { getStackInSlot(0) }); + } + + @Override + public FluidStack[] getFluidInputs() { + return DualInputHatch.asFluidStack.apply(f_shadow); + } + + @Override + public GTDualInputs getPatternInputs() { + return new GTDualInputs() { + { + inputItems = getItemInputs(); + } + { + inputFluid = getFluidInputs(); + } + }; + } + }; + + return ImmutableSet.of(xx).iterator(); + } + + @Override + public Optional getFirstNonEmptyInventory() { + if (!recipe) { + return Optional.empty();// huh... + } + Iterator x = inventories(); + + return x.hasNext() ? Optional.of(x.next()) : Optional.empty(); + } + + @Override + public boolean supportsFluids() { + return true; + } + + @Override + public ItemStack[] getSharedItems() { + + return new ItemStack[0]; + } + + @Override + public void setProcessingLogic(ProcessingLogic pl) { + } + + AENetworkProxy gridProxy; + + @Override + public AENetworkProxy getProxy() { + + if (gridProxy == null) { + if (getBaseMetaTileEntity() instanceof IGridProxyable) { + gridProxy = new AENetworkProxy((IGridProxyable) getBaseMetaTileEntity(), "proxy", + new ItemStack(GregTechAPI.sBlockMachines, 1, getBaseMetaTileEntity().getMetaTileID()), true); + gridProxy.setFlags(GridFlags.REQUIRE_CHANNEL); + updateValidGridProxySides(); + if (getBaseMetaTileEntity().getWorld() != null) + gridProxy.setOwner(getBaseMetaTileEntity().getWorld() + .getPlayerEntityByName(getBaseMetaTileEntity().getOwnerName())); + } + } + return this.gridProxy; + } + + @Override + public boolean isPowered() { + + return getProxy().isPowered(); + } + + @Override + public boolean isActive() { + + return getProxy().isActive(); + } + + boolean additionalConnection; + + protected void updateValidGridProxySides() { + + if (additionalConnection) { + getProxy().setValidSides(EnumSet.complementOf(EnumSet.of(ForgeDirection.UNKNOWN))); + } else { + getProxy().setValidSides(EnumSet.of(getBaseMetaTileEntity().getFrontFacing())); + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) {allowAuto=aNBT.getBoolean("allowAuto"); + getProxy().writeToNBT(aNBT); + super.saveNBTData(aNBT); + NBTTagList nbtTagList = new NBTTagList(); + for (int i = 0; i < 16; i++) { + FluidStack fluidStack = f_mark[i]; + if (fluidStack == null) { + continue; + } + NBTTagCompound fluidTag = fluidStack.writeToNBT(new NBTTagCompound()); + if (f_mark[i] != null) + fluidTag.setInteger("informationAmount", f_mark[i].amount); + nbtTagList.appendTag(fluidTag); + } + aNBT.setTag("storedFluids", nbtTagList); + + nbtTagList = new NBTTagList(); + for (int i = 0; i < 16; i++) { + ItemStack fluidStack = i_mark[i]; + if (fluidStack == null) { + continue; + } + NBTTagCompound fluidTag = fluidStack.writeToNBT(new NBTTagCompound()); + if (i_mark[i] != null) + fluidTag.setInteger("informationAmount", i_mark[i].stackSize); + nbtTagList.appendTag(fluidTag); + } + aNBT.setTag("storedItems", nbtTagList); + + int[] sizesf = new int[16]; + for (int i = 0; i < 16; ++i) + sizesf[i] = f_display[i] == null ? 0 : f_display[i].amount; + aNBT.setIntArray("sizesF", sizesf); + int[] sizes = new int[16]; + for (int i = 0; i < 16; ++i) + sizes[i] = i_display[i] == null ? 0 : i_display[i].stackSize; + aNBT.setIntArray("sizes", sizes); + aNBT.setBoolean("program", program); + aNBT.setBoolean("autoPull", autoPullItemList); + aNBT.setInteger("interval", interval); + + getProxy().writeToNBT(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) {aNBT.setBoolean("allowAuto", allowAuto); + getProxy().readFromNBT(aNBT); + super.loadNBTData(aNBT); + if (aNBT.hasKey("storedFluids")) { + NBTTagList nbtTagList = aNBT.getTagList("storedFluids", 10); + int c = Math.min(nbtTagList.tagCount(), 16); + for (int i = 0; i < c; i++) { + NBTTagCompound nbtTagCompound = nbtTagList.getCompoundTagAt(i); + FluidStack fluidStack = GTUtility.loadFluid(nbtTagCompound); + f_mark[i] = fluidStack; + + if (nbtTagCompound.hasKey("informationAmount")) { + int informationAmount = nbtTagCompound.getInteger("informationAmount"); + f_mark[i] = GTUtility.copyAmount(informationAmount, fluidStack); + } + } + } + + if (aNBT.hasKey("storedItems")) { + NBTTagList nbtTagList = aNBT.getTagList("storedItems", 10); + int c = Math.min(nbtTagList.tagCount(), 16); + for (int i = 0; i < c; i++) { + NBTTagCompound nbtTagCompound = nbtTagList.getCompoundTagAt(i); + ItemStack fluidStack = GTUtility.loadItem(nbtTagCompound); + i_mark[i] = fluidStack; + + if (nbtTagCompound.hasKey("informationAmount")) { + int informationAmount = nbtTagCompound.getInteger("informationAmount"); + i_mark[i] = GTUtility.copyAmount(informationAmount, fluidStack); + } + } + } + + if (aNBT.hasKey("sizesF")) { + int size[] = aNBT.getIntArray("sizesF"); + for (int i = 0; i < 16; i++) { + if (f_mark[i] != null) { + f_display[i] = f_mark[i].copy(); + f_display[i].amount = size[i]; + + } + + } + } + + if (aNBT.hasKey("sizes")) { + int size[] = aNBT.getIntArray("sizes"); + for (int i = 0; i < 16; i++) { + if (i_mark[i] != null) { + i_display[i] = i_mark[i].copy(); + i_display[i].stackSize = size[i]; + + } + + } + } + program=aNBT.getBoolean("program"); + interval = aNBT.getInteger("interval"); + autoPullItemList = aNBT.getBoolean("autoPull"); + } + + public IItemHandlerModifiable inventoryHandlerMark = new ItemStackHandler(i_mark);; + public IItemHandlerModifiable inventoryHandlerDisplay = new ItemStackHandler(i_display);; +} diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/multi/IngredientDistributor.java b/src/main/java/reobf/proghatches/gt/metatileentity/multi/IngredientDistributor.java index eaad419..ac41471 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/multi/IngredientDistributor.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/multi/IngredientDistributor.java @@ -396,6 +396,7 @@ public IStructureDefinition getStructureDefinition() { @Override protected MultiblockTooltipBuilder createTooltip() { + final MultiblockTooltipBuilder tt = new MultiblockTooltipBuilder(); Config.get(tt, "M_ID"); return tt; diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/part2/MixinMultiPattern.java b/src/main/java/reobf/proghatches/main/mixin/mixins/part2/MixinMultiPattern.java index a6c0f2d..4a1307e 100644 --- a/src/main/java/reobf/proghatches/main/mixin/mixins/part2/MixinMultiPattern.java +++ b/src/main/java/reobf/proghatches/main/mixin/mixins/part2/MixinMultiPattern.java @@ -218,10 +218,10 @@ public void MixinMultiPattern_executeCrafting(IEnergyGrid eg, CraftingGridCache final long max = getMaxSkips(); stop: for (int i = 0; i < max; i = (i < Integer.MAX_VALUE - 10) ? (i + 1) : i) { if (MixinCallback.getter.apply(e.getValue()) <= 1) { - break; + break stop; } if (medium.isBusy()) { - break; + break stop; } if (detail.isCraftable()) { @@ -273,7 +273,7 @@ public void MixinMultiPattern_executeCrafting(IEnergyGrid eg, CraftingGridCache } } ic = null; - break; + break stop; } if (medium.pushPattern(detail, ic)) { MixinCallback.setter.accept(e.getValue(), MixinCallback.getter.apply(e.getValue()) - 1); diff --git a/src/main/java/reobf/proghatches/main/registration/Registration.java b/src/main/java/reobf/proghatches/main/registration/Registration.java index 7df86a8..7cb2143 100644 --- a/src/main/java/reobf/proghatches/main/registration/Registration.java +++ b/src/main/java/reobf/proghatches/main/registration/Registration.java @@ -65,6 +65,7 @@ import reobf.proghatches.gt.metatileentity.RemoteInputHatch; import reobf.proghatches.gt.metatileentity.RestrictedInputBusME; import reobf.proghatches.gt.metatileentity.RestrictedInputHatchME; +import reobf.proghatches.gt.metatileentity.StockingDualInputHatchME; import reobf.proghatches.gt.metatileentity.StorageOutputBus; import reobf.proghatches.gt.metatileentity.StorageOutputHatch; import reobf.proghatches.gt.metatileentity.SuperChestME; @@ -103,7 +104,10 @@ public class Registration implements Runnable { public final static int MEFocusOffset = 82; public final static int DataOrbOffset = 83; public final static int MECatalystOffset = 84; - + public final static int StockingDualInputOffset=85;//-86 + + + public final static int BufferedQuadDualInputHatchOffset = 100;// -115 public final static int LargeProviderOffset = 116; public final static int ChainerOffset = 117; @@ -577,8 +581,14 @@ public boolean supportsFluids() { Config.metaTileEntityOffset + DataOrbOffset, "input.dataorb", LangManager.translateToLocal("input.dataorb.name"), 10); - - + new StockingDualInputHatchME( + Config.metaTileEntityOffset + StockingDualInputOffset, + "hatch.dualinput.stocking.me", + LangManager.translateToLocal("hatch.dualinput.stocking.me.name"), 8, false); + new StockingDualInputHatchME( + Config.metaTileEntityOffset + StockingDualInputOffset+1, + "hatch.dualinput.stocking.autopull.me", + LangManager.translateToLocal("hatch.dualinput.stocking.autopull.me.name"), 10, true); /* * for (int i = 0; i < 4; i++) { diff --git a/src/main/resources/assets/proghatches/lang/en_US.lang b/src/main/resources/assets/proghatches/lang/en_US.lang index 271cf6d..b4766c6 100644 --- a/src/main/resources/assets/proghatches/lang/en_US.lang +++ b/src/main/resources/assets/proghatches/lang/en_US.lang @@ -763,3 +763,6 @@ proghatch.orb_switcher.tooltip.6=Hint: use this to automate Power Plant Catalyst input.catalyst.me.name=Automatable Catalyst Housing (ME) tile.proghatches.orb_switcher.name=Catalyst Item Switcher(WIP) proghatches.amountmaintainer.interval.0=Update interval in tick(s) +hatch.dualinput.stocking.me.name=Stocking Dual Input Hatch (ME) +hatch.dualinput.stocking.autopull.me.name=Advanced Stocking Dual Input Hatch (ME) +hatch.dualinput.stocking.autopull.program=Auto consume Programming Circuit and set the virtual circuit slot diff --git a/src/main/resources/assets/proghatches/lang/en_US/SDIHME.lang b/src/main/resources/assets/proghatches/lang/en_US/SDIHME.lang new file mode 100644 index 0000000..1e26234 --- /dev/null +++ b/src/main/resources/assets/proghatches/lang/en_US/SDIHME.lang @@ -0,0 +1 @@ +Just as its name implies... \ No newline at end of file diff --git a/src/main/resources/assets/proghatches/lang/zh_CN.lang b/src/main/resources/assets/proghatches/lang/zh_CN.lang index 5585c4d..4f98917 100644 --- a/src/main/resources/assets/proghatches/lang/zh_CN.lang +++ b/src/main/resources/assets/proghatches/lang/zh_CN.lang @@ -761,3 +761,6 @@ proghatch.orb_switcher.tooltip.6=提示:用于自动化化工厂催化剂/靶仓 input.catalyst.me.name=自动化催化剂仓(ME) tile.proghatches.orb_switcher.name=催化剂物品切换器(WIP) proghatches.amountmaintainer.interval.0=更新间隔(单位tick) +hatch.dualinput.stocking.me.name=库存二合一输入仓(ME) +hatch.dualinput.stocking.autopull.me.name=进阶库存二合一输入仓(ME) +hatch.dualinput.stocking.autopull.program=自动消耗编程器电路设置虚拟电路槽 diff --git a/src/main/resources/assets/proghatches/lang/zh_CN/SDIHME.lang b/src/main/resources/assets/proghatches/lang/zh_CN/SDIHME.lang new file mode 100644 index 0000000..9e34b2a --- /dev/null +++ b/src/main/resources/assets/proghatches/lang/zh_CN/SDIHME.lang @@ -0,0 +1 @@ +你懂的 \ No newline at end of file