From ec54c206cfbc0fb39419ef3a015d8e96909c52de Mon Sep 17 00:00:00 2001 From: reobf <2215595288@qq.com> Date: Tue, 18 Feb 2025 22:55:14 +0800 Subject: [PATCH] update --- .../BufferedDualInputHatch.java | 201 +++++++++++------- .../metatileentity/PatternDualInputHatch.java | 30 +-- ...rnDualInputHatchInventoryMappingSlave.java | 15 +- .../gt/metatileentity/SuperfluidHatch.java | 4 +- .../metatileentity/bufferutil/ItemStackG.java | 173 +++++++++++++++ .../util/MappingItemHandler.java | 5 +- .../util/MappingItemHandlerG.java | 156 ++++++++++++++ 7 files changed, 482 insertions(+), 102 deletions(-) create mode 100644 src/main/java/reobf/proghatches/gt/metatileentity/bufferutil/ItemStackG.java create mode 100644 src/main/java/reobf/proghatches/gt/metatileentity/util/MappingItemHandlerG.java diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java index e4f1ae5..19f8342 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java @@ -7,7 +7,6 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.reflect.Method; -import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; @@ -17,6 +16,7 @@ import java.util.Map.Entry; import java.util.Optional; import java.util.Random; +import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.IntStream; @@ -100,12 +100,10 @@ import gregtech.api.util.GTTooltipDataCache.TooltipData; import gregtech.api.util.GTUtility; import gregtech.common.tileentities.machines.IDualInputInventory; -import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMaps; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; import reobf.proghatches.gt.metatileentity.BufferedDualInputHatch.Recipe; +import reobf.proghatches.gt.metatileentity.bufferutil.ItemStackG; import reobf.proghatches.gt.metatileentity.util.BaseSlotPatched; import reobf.proghatches.gt.metatileentity.util.FirstObjectHolder; import reobf.proghatches.gt.metatileentity.util.ICraftingV2; @@ -113,6 +111,7 @@ import reobf.proghatches.gt.metatileentity.util.IRecipeProcessingAwareDualHatch; import reobf.proghatches.gt.metatileentity.util.ListeningFluidTank; import reobf.proghatches.gt.metatileentity.util.MappingItemHandler; +import reobf.proghatches.gt.metatileentity.util.MappingItemHandlerG; import reobf.proghatches.gt.metatileentity.util.polyfill.INeoDualInputInventory; import reobf.proghatches.item.ItemProgrammingCircuit; import reobf.proghatches.lang.LangManager; @@ -145,22 +144,22 @@ public int getInventoryFluidLimit() { return (int) ((int) (32000 * Math.pow(2, mTier) / (mMultiFluid ? 4 : 1))); } - public int fluidLimit() { + public long fluidLimit() { return (int) ((int) (128000 * Math.pow(2, mTier) / (mMultiFluid ? 4 : 1))); } - public int itemLimit() { + public long itemLimit() { return (int) (64 * Math.pow(4, Math.max(mTier - 3, 0))); } - private static int fluidLimit(int mTier, boolean mMultiFluid) { + private static long fluidLimit(int mTier, boolean mMultiFluid) { return (int) ((int) (128000 * Math.pow(2, mTier) / (mMultiFluid ? 4 : 1))); } - private static int itemLimit(int mTier) { + private static long itemLimit(int mTier) { return (int) (64 * Math.pow(4, Math.max(mTier - 3, 0))); } @@ -257,23 +256,10 @@ public class DualInvBuffer implements INeoDualInputInventory { * } */ public long tickFirstClassify = -1; - - protected Int2ObjectMap> mExItem=new Int2ObjectArrayMap<>(); - protected Int2ObjectMap> mExFluid=new Int2ObjectArrayMap<>(); - protected ArrayList getExItem(int index){ - if(mExItem.containsKey(index)){ - mExItem.put(index, new ArrayList<>()); - } - return mExItem.get(index); - } - protected ArrayList getExFluid(int index){ - if(mExFluid.containsKey(index)){ - mExFluid.put(index, new ArrayList<>()); - } - return mExFluid.get(index); - } + public void onChange(){} + protected FluidTank[] mStoredFluidInternal; - protected ItemStack[] mStoredItemInternal; + protected ItemStackG[] mStoredItemInternal; protected FluidTank[] mStoredFluidInternalSingle; protected ItemStack[] mStoredItemInternalSingle; public boolean recipeLocked; @@ -287,15 +273,16 @@ protected ArrayList getExFluid(int index){ // public boolean lock; public boolean full() { - for (int index = 0; index < mStoredItemInternalSingle.length; index++) { - ItemStack i = mStoredItemInternal[index]; + + for (int index = 0; index < mStoredItemInternalSingle.length; index++) { + ItemStackG i = mStoredItemInternal[index]; ItemStack si = mStoredItemInternalSingle[index]; if (i != null) { - if (si != null && Integer.MAX_VALUE - i.stackSize < si.stackSize) { + if (si != null && Long.MAX_VALUE - i.stackSize() < si.stackSize) { return true;// over flow! count as full } - if (i.stackSize >= itemLimit()) { + if (i.stackSize() >= itemLimit()) { return true; } } @@ -318,7 +305,7 @@ public boolean full() { public void updateSlots() { for (int i = 0; i < this.i; i++) - if (mStoredItemInternal[i] != null && mStoredItemInternal[i].stackSize <= 0) { + if (mStoredItemInternal[i] != null && mStoredItemInternal[i].stackSize() <= 0) { mStoredItemInternal[i] = null; } for (int i = 0; i < this.f; i++) if (Optional.ofNullable(mStoredFluidInternal[i].getFluid()) @@ -344,7 +331,7 @@ public NBTTagCompound toTag() { } for (int i = 0; i < mStoredItemInternal.length; i++) { if (mStoredItemInternal[i] != null) - tag.setTag("mStoredItemInternal" + i, writeToNBT(mStoredItemInternal[i], new NBTTagCompound())); + tag.setTag("mStoredItemInternal" + i, writeToNBTG(mStoredItemInternal[i], new NBTTagCompound())); } for (int i = 0; i < mStoredItemInternalSingle.length; i++) { if (mStoredItemInternalSingle[i] != null) tag.setTag( @@ -379,7 +366,7 @@ public void fromTag(NBTTagCompound tag) { if (mStoredItemInternal != null) { for (int i = 0; i < mStoredItemInternal.length; i++) { if (tag.hasKey("mStoredItemInternal" + i)) { - mStoredItemInternal[i] = loadItemStackFromNBT(tag.getCompoundTag("mStoredItemInternal" + i)); + mStoredItemInternal[i] = loadItemStackFromNBTG(tag.getCompoundTag("mStoredItemInternal" + i)); } } } @@ -407,7 +394,7 @@ public void init(int item, int fluid) { f = fluid; mStoredFluidInternal = initFluidTack(new FluidTank[fluid]); mStoredFluidInternalSingle = initFluidTack(new FluidTank[fluid]); - mStoredItemInternal = new ItemStack[item + v]; + mStoredItemInternal = new ItemStackG[item + v]; mStoredItemInternalSingle = new ItemStack[item]; } @@ -439,9 +426,9 @@ public boolean isEmpty() { return false; } } - for (ItemStack i : mStoredItemInternal) { + for (ItemStackG i : mStoredItemInternal) { - if (i != null && i.stackSize > 0) { + if (i != null && i.stackSize() > 0) { return false; } } @@ -544,9 +531,9 @@ public void firstClassify(ListeningFluidTank[] fin, ItemStack[] iin) { } for (int ix = 0; ix < i; ix++) { - mStoredItemInternal[ix] = Optional.ofNullable(iin[ix]) + mStoredItemInternal[ix] =ItemStackG.neo( Optional.ofNullable(iin[ix]) .map(ItemStack::copy) - .orElse(null); + .orElse(null)); iin[ix] = null; } /* @@ -559,13 +546,14 @@ public void firstClassify(ListeningFluidTank[] fin, ItemStack[] iin) { markJustHadNewItems(); onClassify(); programLocal(); + onChange(); } private void programLocal() { if (!program) return; ArrayList isa = new ArrayList<>(); for (int i = 0; i < mStoredItemInternal.length; i++) { - ItemStack is = mStoredItemInternal[i]; + ItemStackG is = mStoredItemInternal[i]; if (is == null) continue; if (is.getItem() != MyMod.progcircuit) continue; mStoredItemInternal[i] = null; @@ -574,7 +562,7 @@ private void programLocal() { isa.add( GTUtility.copyAmount( 0, - ItemProgrammingCircuit.getCircuit(is) + ItemProgrammingCircuit.getCircuit(is.getStack()) .orElse(null))); } @@ -583,7 +571,7 @@ private void programLocal() { for (int i = 0; i < v; i++) { if (i < nums) { - mStoredItemInternal[this.i + i] = isa.get(i); + mStoredItemInternal[this.i + i] = ItemStackG.neo(isa.get(i)); } else { mStoredItemInternal[this.i + i] = null; } @@ -615,7 +603,7 @@ public boolean classify(ListeningFluidTank[] fin, ItemStack[] iin, boolean remov } if (ItemStack.areItemStacksEqual(mStoredItemInternalSingle[ix], iin[ix])) { if ((iin[ix] != null && mStoredItemInternal[ix] != null) - && !areItemStacksEqualIngoreAmount(mStoredItemInternal[ix], iin[ix])) { + && !areItemStacksEqualIngoreAmount(mStoredItemInternal[ix].getStack(), iin[ix])) { return false; } } else { @@ -637,8 +625,8 @@ else if (fin[ix].getFluid() != null) fin[ix].setFluidDirect( } for (int ix = 0; ix < i; ix++) { if (mStoredItemInternalSingle[ix] != null) - if (mStoredItemInternal[ix] == null) mStoredItemInternal[ix] = mStoredItemInternalSingle[ix].copy(); - else mStoredItemInternal[ix].stackSize += mStoredItemInternalSingle[ix].stackSize; + if (mStoredItemInternal[ix] == null) mStoredItemInternal[ix] = ItemStackG.neo(mStoredItemInternalSingle[ix].copy()); + else mStoredItemInternal[ix].stackSizeInc( mStoredItemInternalSingle[ix].stackSize); if (removeInputOnSuccess) iin[ix] = null; else if (iin[ix] != null) iin[ix] = iin[ix].copy(); } @@ -658,6 +646,7 @@ else if (fin[ix].getFluid() != null) fin[ix].setFluidDirect( onClassify(); if (program) programLocal(); + onChange(); return true; } @@ -700,7 +689,7 @@ public ItemStack[] getItemInputs() { * bruh; */ - ItemStack[] condensed = filterStack.apply(mStoredItemInternal, shared.getItems()); + ItemStack[] condensed = filterStack.apply(flat(mStoredItemInternal), shared.getItems()); // if(!trunOffEnsure){condensed=ensureIntMax(condensed);} @@ -708,7 +697,9 @@ public ItemStack[] getItemInputs() { } - @Override + + + @Override public FluidStack[] getFluidInputs() { FluidStack[] condensed = asFluidStack.apply(mStoredFluidInternal, shared.getFluid()); // if(!trunOffEnsure){condensed=ensureIntMax(condensed);} @@ -717,14 +708,14 @@ public FluidStack[] getFluidInputs() { } public int space() { - int ret = Integer.MAX_VALUE; + long ret = Integer.MAX_VALUE; boolean found = false; for (int ix = 0; ix < i; ix++) { if (mStoredItemInternalSingle[ix] != null && mStoredItemInternalSingle[ix].stackSize > 0) { - int now = 0; - if (mStoredItemInternal[ix] != null) now = mStoredItemInternal[ix].stackSize; - int tmp = (itemLimit() - now) / mStoredItemInternalSingle[ix].stackSize; + long now = 0; + if (mStoredItemInternal[ix] != null) now = mStoredItemInternal[ix].stackSize(); + long tmp = (itemLimit() - now) / mStoredItemInternalSingle[ix].stackSize; if (tmp < ret) { ret = tmp; found = true; @@ -736,7 +727,7 @@ public int space() { if (mStoredFluidInternalSingle[ix].getFluidAmount() > 0) { int now = mStoredFluidInternal[ix].getFluidAmount(); - int tmp = (fluidLimit() - now) / mStoredFluidInternalSingle[ix].getFluidAmount(); + long tmp = (fluidLimit() - now) / mStoredFluidInternalSingle[ix].getFluidAmount(); if (tmp < ret) { ret = tmp; found = true; @@ -744,7 +735,7 @@ public int space() { } } - if (found) return ret; + if (found) return (int) Math.min(ret, Integer.MAX_VALUE); return 0; } @@ -1064,7 +1055,7 @@ public void setInventorySlotContents(int aIndex, ItemStack aStack) { final int offset = 0; public void add1by1Slot(ModularWindow.Builder builder, int index, IDrawable... background) { - final IItemHandlerModifiable inventoryHandler = new MappingItemHandler( + final IItemHandlerModifiable inventoryHandler = new MappingItemHandlerG( inv0.get(index).mStoredItemInternal, offset, 1).id(1); @@ -1082,7 +1073,7 @@ public void add1by1Slot(ModularWindow.Builder builder, int index, IDrawable... b } public void add2by2Slots(ModularWindow.Builder builder, int index, IDrawable... background) { - final IItemHandlerModifiable inventoryHandler = new MappingItemHandler( + final IItemHandlerModifiable inventoryHandler = new MappingItemHandlerG( inv0.get(index).mStoredItemInternal, offset, 4).id(1); @@ -1100,7 +1091,7 @@ public void add2by2Slots(ModularWindow.Builder builder, int index, IDrawable... } public void add3by3Slots(ModularWindow.Builder builder, int index, IDrawable... background) { - final IItemHandlerModifiable inventoryHandler = new MappingItemHandler( + final IItemHandlerModifiable inventoryHandler = new MappingItemHandlerG( inv0.get(index).mStoredItemInternal, offset, 9).id(1); @@ -1118,7 +1109,7 @@ public void add3by3Slots(ModularWindow.Builder builder, int index, IDrawable... } public void add4by4Slots(ModularWindow.Builder builder, int index, IDrawable... background) { - final IItemHandlerModifiable inventoryHandler = new MappingItemHandler( + final IItemHandlerModifiable inventoryHandler = new MappingItemHandlerG( inv0.get(index).mStoredItemInternal, offset, 16).id(1); @@ -1211,7 +1202,7 @@ protected ModularWindow createWindow(final EntityPlayer player, int index) { Scrollable sc = new Scrollable().setVerticalScroll(); - final IItemHandlerModifiable inventoryHandler = new MappingItemHandler( + final IItemHandlerModifiable inventoryHandler = new MappingItemHandlerG( inv0.get(index).mStoredItemInternal, 0, inv0.get(index).mStoredItemInternal.length).phantom(); @@ -1454,6 +1445,38 @@ public void readOnServer(int id, PacketBuffer buf) throws IOException {} // ProghatchesUtil.removeMultiCache(builder, this); ProghatchesUtil.attachZeroSizedStackRemover(builder, buildContext); + + builder.widget(new SyncedWidget() { + + + Consumer ticker = ss -> { + + for(int i=0;i { } DualInvBuffer buff; - int piority; + long piority; @Override public String toString() { @@ -1637,7 +1660,7 @@ public String toString() { @Override public int compareTo(PiorityBuffer o) { - return -piority + o.piority; + return Long.compare(piority , o.piority); } } @@ -1685,10 +1708,10 @@ public Iterator inventories() { markDirty(); dirty = true; - if (merge) { + /*if (merge) { return mergeSame(); - } + }*/ if (Config.experimentalOptimize) { @@ -1926,7 +1949,7 @@ public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompou (a, b) -> a.append(b)) .toString()); - sub.setInteger("possibleCopies", (rt.broken || (!rt.onceCompared && !inv.isEmpty())) ? -1 : rt.times); + sub.setLong("possibleCopies", (rt.broken || (!rt.onceCompared && !inv.isEmpty())) ? -1 : rt.times); }); super.getWailaNBTData(player, tile, tag, world, x, y, z); @@ -1946,24 +1969,24 @@ private static class IndexedObject { private static class RecipeTracker { boolean broken; - int times; + long times; boolean first = true; boolean onceCompared; - public void track(@Nonnull ItemStack recipe, @Nullable ItemStack storage) { + public void track(@Nonnull ItemStack recipe, @Nullable ItemStackG mStoredItemInternal) { if (recipe.getItem() instanceof ItemProgrammingCircuit) { onceCompared = true; return; } - if (recipe.getItem() != (storage == null ? null : storage.getItem())) { + if (recipe.getItem() != (mStoredItemInternal == null ? null : mStoredItemInternal.getItem())) { broken = true; onceCompared = true; return; } int a = recipe.stackSize; - int b = Optional.ofNullable(storage) - .map(s -> s.stackSize) - .orElse(0); + long b = Optional.ofNullable(mStoredItemInternal) + .map(s -> s.stackSize()) + .orElse(0l); track(a, b, false); } @@ -1984,8 +2007,8 @@ public void track(@Nonnull FluidTank recipe, @Nonnull FluidTank storage) { track(a, b, false); } - public void track(int a, int b, boolean ignoreEmpty) { - int t = 0; + public void track(int a, long b, boolean ignoreEmpty) { + long t = 0; if (a == 0) { broken = true; return; @@ -2014,7 +2037,7 @@ public void track(int a, int b, boolean ignoreEmpty) { } } - public int getPossibleCopies(DualInvBuffer toCheck) { + public long getPossibleCopies(DualInvBuffer toCheck) { DualInvBuffer inv = toCheck; RecipeTracker rt = new RecipeTracker(); @@ -2235,14 +2258,14 @@ public CheckRecipeResult endRecipeProcessingImpl(MTEMultiBlockBase controller) { @Override public void onBlockDestroyed() { - IGregTechTileEntity te = this.getBaseMetaTileEntity(); + /* IGregTechTileEntity te = this.getBaseMetaTileEntity(); World aWorld = te.getWorld(); int aX = te.getXCoord(); short aY = te.getYCoord(); int aZ = te.getZCoord(); for (DualInvBuffer inv : this.inv0) for (int i = 0; i < inv.mStoredItemInternal.length; i++) { - final ItemStack tItem = inv.mStoredItemInternal[i]; - if ((tItem != null) && (tItem.stackSize > 0)) { + final ItemStackG tItem = inv.mStoredItemInternal[i]; + if ((tItem != null) && (tItem.stackSize() > 0)) { final EntityItem tItemEntity = new EntityItem( aWorld, aX + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, @@ -2262,7 +2285,7 @@ public void onBlockDestroyed() { tItem.stackSize = 0; inv.mStoredItemInternal[i] = null; } - } + }*/ super.onBlockDestroyed(); } @@ -2289,7 +2312,7 @@ public boolean isInputEmpty() { * return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, * aZ); } */ - @SuppressWarnings("unchecked") + /*@SuppressWarnings("unchecked") public Iterator mergeSame() { class Wrapper { @@ -2303,9 +2326,7 @@ public Wrapper(DualInvBuffer s) { boolean fast = true;; private int sft(int i, int t) { - /* - * i=(i*17)%32; return (i<>>(32-t)); - */return i ^ t; + return i ^ t; } @Override @@ -2495,7 +2516,7 @@ public FluidStack[] getFluidInputs() { }) .iterator(); } - +*/ static public boolean fluidEquals(FluidTank a, FluidTank b) { // if(a==b)return false; // if(a==null||b==null)return false; @@ -2754,6 +2775,7 @@ public boolean pushPatternCM(ICraftingPatternDetails patternDetails, InventoryCr DualInvBuffer buff = ((BufferedDualInputHatch) master).classifyForce(); if (buff != null) { recordRecipe(buff); + buff.onChange(); } } return true;// hoo ray @@ -2820,5 +2842,26 @@ public void recordRecipe(DualInvBuffer thiz) { check = currentID; } thiz.PID = check; + } + public static NBTTagCompound writeToNBTG(ItemStackG is, NBTTagCompound tag) { + is.writeToNBT(tag); + // tag.setInteger("ICount", is.stackSize); + + return tag; + } + + public static ItemStackG loadItemStackFromNBTG(NBTTagCompound tag) { + + ItemStackG is = ItemStackG.loadItemStackFromNBT(tag); + //is.stackSize = tag.getInteger("ICount"); + return is; } + public static ItemStack[] flat(ItemStackG[] mStoredItemInternal2) { + + return Arrays.asList(mStoredItemInternal2).stream().flatMap(s->Arrays.stream(s.flat())).toArray(ItemStack[]::new); + + + + + } } diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java index 9e76b03..23d7a2e 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java @@ -81,6 +81,7 @@ import mcp.mobius.waila.api.IWailaDataAccessor; import reobf.proghatches.gt.metatileentity.BufferedDualInputHatch.DualInvBuffer; import reobf.proghatches.gt.metatileentity.DualInputHatch.Net; +import reobf.proghatches.gt.metatileentity.bufferutil.ItemStackG; import reobf.proghatches.gt.metatileentity.util.IMultiplePatternPushable; import reobf.proghatches.gt.metatileentity.util.MappingItemHandler; import reobf.proghatches.lang.LangManager; @@ -89,6 +90,9 @@ public class PatternDualInputHatch extends BufferedDualInputHatch implements ICraftingProvider, IGridProxyable, ICustomNameObject, IInterfaceViewable, IPowerChannelState, IActionHost, IMultiplePatternPushable { + + + public PatternDualInputHatch(String mName, byte mTier, String[] mDescriptionArray, ITexture[][][] mTextures, boolean mMultiFluid, int bufferNum) { super(mName, mTier, mDescriptionArray, mTextures, mMultiFluid, bufferNum); @@ -356,7 +360,7 @@ abstract class Inv { @Override ItemStack[] geti() { - return s.mStoredItemInternal; + return flat(s.mStoredItemInternal); } @Override @@ -658,9 +662,9 @@ public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCraf */ DualInvBuffer theBuffer = /* ((BufferedDualInputHatch) master). */classifyForce(); - if(theBuffer!=null) - recordRecipe(theBuffer); - + if(theBuffer!=null){ + recordRecipe(theBuffer);theBuffer.onChange(); + } justHadNewItems = true; return true; } @@ -940,14 +944,14 @@ public void onBlockDestroyed() { } } - public int fluidLimit() { + public long fluidLimit() { - return Integer.MAX_VALUE; + return Long.MAX_VALUE; } - public int itemLimit() { + public long itemLimit() { - return Integer.MAX_VALUE; + return Long.MAX_VALUE; } boolean createInsertion() { @@ -1083,11 +1087,11 @@ public int[] pushPatternMulti(ICraftingPatternDetails patternDetails, InventoryC for (int ix = 0; ix < theBuffer.i; ix++) { if (theBuffer.mStoredItemInternalSingle[ix] != null) { if (theBuffer.mStoredItemInternal[ix] == null) { - theBuffer.mStoredItemInternal[ix] = theBuffer.mStoredItemInternalSingle[ix].copy(); - theBuffer.mStoredItemInternal[ix].stackSize = 0;// circuit? + theBuffer.mStoredItemInternal[ix] = ItemStackG.neo(theBuffer.mStoredItemInternalSingle[ix].copy()); + theBuffer.mStoredItemInternal[ix].stackSize(0);// circuit? } - theBuffer.mStoredItemInternal[ix].stackSize += theBuffer.mStoredItemInternalSingle[ix].stackSize - * todo; + theBuffer.mStoredItemInternal[ix].stackSizeInc( theBuffer.mStoredItemInternalSingle[ix].stackSize + * todo); } } @@ -1105,7 +1109,7 @@ public int[] pushPatternMulti(ICraftingPatternDetails patternDetails, InventoryC } suc += todo; } - + theBuffer.onChange(); } saved += suc; diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatchInventoryMappingSlave.java b/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatchInventoryMappingSlave.java index f9e6e09..d13b97c 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatchInventoryMappingSlave.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatchInventoryMappingSlave.java @@ -78,6 +78,7 @@ import mcp.mobius.waila.api.IWailaDataAccessor; import reobf.proghatches.block.BlockIOHub; import reobf.proghatches.gt.metatileentity.BufferedDualInputHatch.DualInvBuffer; +import reobf.proghatches.gt.metatileentity.bufferutil.ItemStackG; import reobf.proghatches.gt.metatileentity.util.IDataCopyablePlaceHolder; import reobf.proghatches.gt.metatileentity.util.IMultiplePatternPushable; import reobf.proghatches.gt.metatileentity.util.MappingItemHandler; @@ -878,8 +879,8 @@ public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCraf BufferedDualInputHatch m = (BufferedDualInputHatch) master; DualInvBuffer theBuffer = ((BufferedDualInputHatch) master).classifyForce(); - if(theBuffer!=null) - ((BufferedDualInputHatch) master).recordRecipe(theBuffer); + if(theBuffer!=null){ + ((BufferedDualInputHatch) master).recordRecipe(theBuffer);theBuffer.onChange();} // ((BufferedDualInputHatch) master).classifyForce(); } return true;// hoo ray @@ -1141,11 +1142,11 @@ public int[] pushPatternMulti(ICraftingPatternDetails patternDetails, InventoryC for (int ix = 0; ix < theBuffer.i; ix++) { if (theBuffer.mStoredItemInternalSingle[ix] != null) { if (theBuffer.mStoredItemInternal[ix] == null) { - theBuffer.mStoredItemInternal[ix] = theBuffer.mStoredItemInternalSingle[ix].copy(); - theBuffer.mStoredItemInternal[ix].stackSize = 0;// circuit? + theBuffer.mStoredItemInternal[ix] = ItemStackG.neo(theBuffer.mStoredItemInternalSingle[ix].copy()); + theBuffer.mStoredItemInternal[ix].stackSize (0);// circuit? } - theBuffer.mStoredItemInternal[ix].stackSize += theBuffer.mStoredItemInternalSingle[ix].stackSize - * todo; + theBuffer.mStoredItemInternal[ix].stackSizeInc( theBuffer.mStoredItemInternalSingle[ix].stackSize + * todo); } } @@ -1165,7 +1166,7 @@ public int[] pushPatternMulti(ICraftingPatternDetails patternDetails, InventoryC suc += todo; } - + theBuffer.onChange(); } } diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/SuperfluidHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/SuperfluidHatch.java index 46ae335..a585d60 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/SuperfluidHatch.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/SuperfluidHatch.java @@ -53,12 +53,12 @@ public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { } - public int fluidLimit() { + public long fluidLimit() { return 100_000_000; } - public int itemLimit() { + public long itemLimit() { return 64; } diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/bufferutil/ItemStackG.java b/src/main/java/reobf/proghatches/gt/metatileentity/bufferutil/ItemStackG.java new file mode 100644 index 0000000..d53ff69 --- /dev/null +++ b/src/main/java/reobf/proghatches/gt/metatileentity/bufferutil/ItemStackG.java @@ -0,0 +1,173 @@ +package reobf.proghatches.gt.metatileentity.bufferutil; + +import java.util.ArrayList; +import java.util.Iterator; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +//G is for group +public class ItemStackG { + public ArrayList arr = new ArrayList<>(); + + + public static ItemStackG neo(ItemStack is) { + if (is == null) + return null; + return new ItemStackG(is); + } + + private ItemStackG(ItemStack is) { + arr.add(is); + } +public ItemStack getZero(){ + return arr.get(0); + + +} + public NBTTagCompound writeToNBT(NBTTagCompound p_77955_1_) { + + arr.get(0).writeToNBT(p_77955_1_); + p_77955_1_.setInteger("ICount", arr.get(0).stackSize); + + NBTTagList lst = new NBTTagList(); + for (int i = 1; i < arr.size(); i++) { + + NBTTagCompound t = new NBTTagCompound(); + arr.get(i).writeToNBT(t); + t.setInteger("ICount", arr.get(i).stackSize); + lst.appendTag(t); + + } + + p_77955_1_.setTag("therest", lst); + + return p_77955_1_; + } + + public static ItemStackG readFromNBT(NBTTagCompound p_77963_1_) { + + ItemStack is = ItemStack.loadItemStackFromNBT(p_77963_1_); + if (is == null) + return null; + is.stackSize = p_77963_1_.getInteger("ICount"); + ItemStackG to = neo(is); + if (to != null) { + + if (p_77963_1_.hasKey("therest")) { + + NBTTagList lst = (NBTTagList) p_77963_1_.getTag("therest"); + for (int ix = 0; ix < lst.tagCount(); ix++) { + NBTTagCompound TAG = lst.getCompoundTagAt(ix); + + ItemStack isX = ItemStack.loadItemStackFromNBT(TAG); + if (isX != null) { + isX.stackSize = TAG.getInteger("ICount"); + to.arr.add(isX); + } + + } + + } + + } + + return to; + + } + + public long stackSize() { + return arr.stream().mapToLong(s->s.stackSize).sum(); + } + + public Item getItem() { + + return arr.get(0).getItem(); + } + + public ItemStack getStack() { + ItemStack ret=arr.get(0).copy(); + ret.stackSize=(int) Math.min(stackSize(),Integer.MAX_VALUE); + return ret; + } + + public void stackSizeInc(int todo) { + + for(ItemStack is:arr){ + int cando=Math.min( + + Integer.MAX_VALUE + //64 + + + -is.stackSize,todo); + todo-=cando; + is.stackSize+=cando; + if(todo<=0)return; + } + ItemStack i = arr.get(0).copy(); + i.stackSize=todo; + arr.add(i); + + + } + + public static ItemStackG loadItemStackFromNBT(NBTTagCompound tag) { + + return readFromNBT(tag); + } + + public ItemStack[] flat() { + adjust(); + return arr.toArray(new ItemStack[arr.size()]); + } + + + + public void stackSize(int i) { + + if(arr.size()>1){arr.remove(1);} + arr.get(0).stackSize=i; + } + + public static ItemStackG setZero(ItemStackG itemStackG, ItemStack copyStackWithSize) { + + + if(itemStackG==null){ + return neo(copyStackWithSize); + } + if(copyStackWithSize==null) + itemStackG.arr.get(0).stackSize=0; + + else + itemStackG.arr.get(0).stackSize=copyStackWithSize.stackSize; + itemStackG.adjust(); + return itemStackG; + } + + public void adjust(){boolean dirty=false; + for(int i=0;i0){ + int todo=Math.min(Integer.MAX_VALUE-arr.get(i).stackSize, arr.get(i+1).stackSize); + arr.get(i).stackSize+=todo; + arr.get(i+1).stackSize-=todo;dirty=true; + + } + } + + } + + if(dirty){ + Iterator it = arr.iterator();it.next(); + while(it.hasNext()){ + if(it.next().stackSize<=0){it.remove();} + + } + + } + } + +} diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/util/MappingItemHandler.java b/src/main/java/reobf/proghatches/gt/metatileentity/util/MappingItemHandler.java index 0bdbab9..3bf9f23 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/util/MappingItemHandler.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/util/MappingItemHandler.java @@ -1,6 +1,7 @@ package reobf.proghatches.gt.metatileentity.util; import net.minecraft.item.ItemStack; +import reobf.proghatches.gt.metatileentity.bufferutil.ItemStackG; import com.gtnewhorizons.modularui.api.forge.ItemHandlerHelper; @@ -17,7 +18,9 @@ public MappingItemHandler(ItemStack[] is, int index, int num) { this.num = num; } - boolean phantom; + + + boolean phantom; public MappingItemHandler phantom() { phantom = true; diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/util/MappingItemHandlerG.java b/src/main/java/reobf/proghatches/gt/metatileentity/util/MappingItemHandlerG.java new file mode 100644 index 0000000..e3e3a40 --- /dev/null +++ b/src/main/java/reobf/proghatches/gt/metatileentity/util/MappingItemHandlerG.java @@ -0,0 +1,156 @@ +package reobf.proghatches.gt.metatileentity.util; + +import net.minecraft.item.ItemStack; +import reobf.proghatches.gt.metatileentity.bufferutil.ItemStackG; + +import java.util.Optional; + +import com.gtnewhorizons.modularui.api.forge.ItemHandlerHelper; + +import gregtech.api.util.GTUtility; + +public class MappingItemHandlerG + implements com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable, IInterhandlerGroup { + + public Runnable update = () -> {}; + + public MappingItemHandlerG(ItemStackG[] is, int index, int num) { + this.is = is; + this.index = index; + this.num = num; + } + + + + boolean phantom; + + public MappingItemHandlerG phantom() { + phantom = true; + return this; + } + + ItemStackG[] is; + int index, num; + + @Override + public int getSlots() { + + return num + index; + } + + @Override + public ItemStack getStackInSlot(int var1) { + + return Optional.ofNullable(is[var1 - index]).map(s->s.getZero()).orElse(null); + } + + protected int getStackLimit(int slot, ItemStack stack) { + return Math.min(this.getSlotLimit(slot - index), stack.getMaxStackSize()); + } + + @Override + public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { + try { + if (stack == null) { + return null; + } else { + // this.validateSlotIndex(slot); + ItemStack existing = getStackInSlot(slot - index); + int limit = this.getStackLimit(slot - index, stack); + if (existing != null) { + if (!ItemHandlerHelper.canItemStacksStack(stack, existing)) { + return stack; + } + + limit -= existing.stackSize; + } + + if (limit <= 0) { + return stack; + } else { + boolean reachedLimit = stack.stackSize > limit; + if (!simulate) { + if (existing == null) { + is[slot - index] =ItemStackG.neo(reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) + : stack); + + } else { + existing.stackSize += reachedLimit ? limit : stack.stackSize; + } + + // this.onContentsChanged(slot); + } + + return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.stackSize - limit) : null; + } + } + } finally { + update.run(); + } + } + + @Override + public ItemStack extractItem(int slot, int amount, boolean simulate) { + try { + if (amount == 0) { + return null; + } else { + // this.validateSlotIndex(slot); + ItemStack existing = getStackInSlot(slot - index); + if (existing == null) { + return null; + } else { + int toExtract = Math.min(amount, existing.getMaxStackSize()); + if (existing.stackSize <= toExtract) { + if (!simulate) { + is[slot - index] = null; + // this.onContentsChanged(slot); + } + + return existing; + } else { + if (!simulate) { + is[slot - index] =ItemStackG.setZero(is[slot - index],ItemHandlerHelper + .copyStackWithSize(existing, existing.stackSize - toExtract)); + // this.onContentsChanged(slot); + } + + return ItemHandlerHelper.copyStackWithSize(existing, toExtract); + } + } + } + } finally { + update.run(); + } + } + + @Override + public int getSlotLimit(int slot) { + return Integer.MAX_VALUE; + } + + @Override + public void setStackInSlot(int var1, ItemStack var2) { + try { + if (phantom) { + is[var1 - index] =ItemStackG.setZero(is[var1 - index],GTUtility.copyAmount(0, var2)); + + } else is[var1 - index] =ItemStackG.setZero(is[var1 - index],var2); + } finally { + update.run(); + } + } + + public MappingItemHandlerG id(long i) { + id = i; + return this; + } + + long id; + + @Override + public long handlerID() { + return id; + } + +}