From e0449b11c19bca414deabd67ed40e89cdb0c7645 Mon Sep 17 00:00:00 2001 From: reobf <2215595288@qq.com> Date: Tue, 24 Sep 2024 08:37:10 +0800 Subject: [PATCH] update --- build.gradle | 2 +- .../eucrafting/CoverToMachineAdaptor.java | 5 +- .../BufferedDualInputHatch.java | 180 ++++++++++++++++-- .../gt/metatileentity/DualInputHatch.java | 85 ++++++--- .../metatileentity/MultiCircuitInputBus.java | 54 +++++- .../gt/metatileentity/RemoteInputHatch.java | 6 +- .../multi/IngredientDistributor.java | 3 +- .../proghatches/main/mixin/MixinPlugin.java | 7 +- .../assets/proghatches/lang/en_US.lang | 4 + .../assets/proghatches/lang/zh_CN.lang | 2 + 10 files changed, 299 insertions(+), 49 deletions(-) diff --git a/build.gradle b/build.gradle index ce227af..d6cc584 100644 --- a/build.gradle +++ b/build.gradle @@ -373,7 +373,7 @@ catch (Exception ignored) { // Pulls version first from the VERSION env and then git tag String identifiedVersion = null -String versionOverride = '0.0.19' +String versionOverride = '0.0.19p1' try { // Produce a version based on the tag, or for branches something like 0.2.2-configurable-maven-and-extras.38+43090270b6-dirty if (versionOverride == null) { diff --git a/src/main/java/reobf/proghatches/eucrafting/CoverToMachineAdaptor.java b/src/main/java/reobf/proghatches/eucrafting/CoverToMachineAdaptor.java index ed421cf..2d86e28 100644 --- a/src/main/java/reobf/proghatches/eucrafting/CoverToMachineAdaptor.java +++ b/src/main/java/reobf/proghatches/eucrafting/CoverToMachineAdaptor.java @@ -92,7 +92,10 @@ public CoverToMachineAdaptor(T te,@Nullable InventoryAdaptor invItems, this.invFluids = invFluids; this.te=te; this.fd=fd; - }T te;ForgeDirection fd; private final InventoryAdaptor invItems; + } + T te; + + ForgeDirection fd; private final InventoryAdaptor invItems; private final IFluidHandler invFluids; @Override public Iterator iterator() { diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java index 5a7c06c..b592f0c 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java @@ -14,6 +14,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.Queue; import java.util.function.Consumer; @@ -33,6 +34,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.launchwrapper.Launch; import net.minecraft.nbt.JsonToNBT; @@ -51,8 +53,11 @@ import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.oredict.OreDictionary; +import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Multimap; +import com.google.common.collect.Multiset; import com.gtnewhorizons.modularui.api.ModularUITextures; import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; @@ -81,7 +86,6 @@ import com.gtnewhorizons.modularui.common.widget.SlotWidget; import com.gtnewhorizons.modularui.common.widget.SyncedWidget; import com.gtnewhorizons.modularui.common.widget.TextWidget; - import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -225,6 +229,7 @@ public BufferedDualInputHatch(String aName, int aTier, int aSlots, String[] aDes public class DualInvBuffer implements IDualInputInventory { public long tickFirstClassify=-1; + protected FluidTank[] mStoredFluidInternal; protected ItemStack[] mStoredItemInternal; protected FluidTank[] mStoredFluidInternalSingle; @@ -451,18 +456,7 @@ private boolean isItemStackEqualIngoreAmount(ItemStack p_77959_1_,ItemStack thiz return false ? false : (thiz.getItem() != p_77959_1_.getItem() ? false : (thiz.getItemDamage() != p_77959_1_.getItemDamage() ? false : (thiz.stackTagCompound == null && p_77959_1_.stackTagCompound != null ? false : thiz.stackTagCompound == null || thiz.stackTagCompound.equals(p_77959_1_.stackTagCompound)))); } - private boolean fluidEquals(FluidTank a, FluidTank b) { - // if(a==b)return false; - // if(a==null||b==null)return false; - if (a.getFluidAmount() != b.getFluidAmount()) - return false; - if (a.getFluid() == null && a.getFluid() == null) - return true; - if (a.getFluid() != null && (!a.getFluid().equals(b.getFluid()))) - return false; - - return true; - } + /** * classify() with less check, for better performance @@ -1533,7 +1527,7 @@ public void getWailaBody(ItemStack itemStack, List currenttip, IWailaDat +tag.getInteger("sleepTime") ); - + int idle[]=new int[1]; IntStream.range(0, tag.getInteger("inv_size")).forEach(s -> { NBTTagCompound sub = (NBTTagCompound) tag.getTag("No" + s); boolean noClear = sub.getBoolean("noClear"); @@ -1548,6 +1542,8 @@ public void getWailaBody(ItemStack itemStack, List currenttip, IWailaDat info = LangManager.translateToLocal("programmable_hatches.buffer.waila.001"); break; case 0b010: + idle[0]++; + if(idle[0]>5)return; info = LangManager.translateToLocal("programmable_hatches.buffer.waila.010"); break; case 0b011: @@ -1599,8 +1595,9 @@ public void getWailaBody(ItemStack itemStack, List currenttip, IWailaDat Arrays.stream(lock_fluid.split("\n")).map(ss -> " " + ss).forEach(currenttip::add); }); - ; + if(idle[0]>5) + currenttip.add(LangManager.translateToLocalFormatted("programmable_hatches.buffer.waila.hidden",(idle[0]-5)+"")); } @@ -1620,6 +1617,13 @@ public void updateSlots() { @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + + mergeSame().forEachRemaining(s->{ + + System.out.println(s); + + + }); BaseMetaTileEntity tile = (BaseMetaTileEntity) this.getBaseMetaTileEntity(); if (tile.isServerSide()) { if (!tile.privateAccess() || aPlayer.getDisplayName().equalsIgnoreCase(tile.getOwnerName())) { @@ -1709,11 +1713,153 @@ public boolean isInputEmpty() { } return true; } - @Override + /*@Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side, float aX, float aY, float aZ) { return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ); - } + }*/ + @SuppressWarnings("unchecked") + public Iterator mergeSame(){ + + + class Wrapper{ + DualInvBuffer d; + public Wrapper(DualInvBuffer s) { + d=s; + } + + @Override + public int hashCode() { + int hash=0; + for(int i=0;i>>1; + if(a!=0)hash|=0x80000000; + } + for(int i=0;i>>1; + if(a!=0)hash|=0x80000000; + } + + return hash; + } + + @Override + public boolean equals(Object obj) { + if(obj==this){return true;} + boolean empty=true; + DualInvBuffer a=d; + DualInvBuffer b=((Wrapper) obj).d; + for(int i=0;i0) + empty=false; + + } + for(int i=0;i a=HashMultimap + .create(); + inv0.stream().filter((DualInvBuffer::isAccessibleForMulti)) + .forEach( + s->{ + a.put(new Wrapper(s), s); + } + ); + return (Iterator) a.asMap().values().stream().map( + s->{ + return new IDualInputInventory(){ + void init(){ + Iterator itr = s.iterator(); + int icount=0; + ItemStack[][] idata=new ItemStack[s.size()][]; + int fcount=0; + FluidStack[][] fdata=new FluidStack[s.size()][]; + for(int i=0;i 0 ? optional @@ -170,7 +178,7 @@ public DualInputHatch(int id, String name, String nameRegional, int tier, boole Registration.items.add(new ItemStack(GregTech_API.sBlockMachines, 1, id)); this.mMultiFluid = mMultiFluid; initTierBasedField(); - } + }*/ public DualInputHatch(int id, String name, String nameRegional, int tier, int slot, boolean mMultiFluid, String... optional) { @@ -298,16 +306,25 @@ public void saveNBTData(NBTTagCompound aNBT) { aNBT.setTag("mFluid" + i, mStoredFluid[i].writeToNBT(new NBTTagCompound())); } } - + try{ NBTTagList greggy=aNBT.getTagList("Inventory", 10); - for(int i=0;ishared.broken) + ); + builder.widget(new FakeSyncWidget.BooleanSyncer(()->shared.broken, s->shared.broken=s) + + .setSynced(true, false)); return builder.build(); @@ -1459,7 +1487,7 @@ public void updateSlots() { }else*/ super.updateSlots(); } - private void fillStacksIntoFirstSlotsExtraCircuit() { + /*private void fillStacksIntoFirstSlotsExtraCircuit() { final int L = mInventory.length - 4; HashMap slots = new HashMap<>(L); HashMap stacks = new HashMap<>(L); @@ -1488,14 +1516,16 @@ private void fillStacksIntoFirstSlotsExtraCircuit() { mInventory[slot].stackSize = toSet; slots.merge(sID, toSet, (a, b) -> a - b); } - } + }*/ CheckRecipeResult lastresult; @Override public final CheckRecipeResult endRecipeProcessing(GT_MetaTileEntity_MultiBlockBase controller) { if(recipe){recipe=false; - return lastresult=endRecipeProcessingImpl(controller); + lastresult=endRecipeProcessingImpl(controller); + if(lastresult.wasSuccessful()==false)controller.stopMachine(ShutDownReasonRegistry.CRITICAL_NONE); + return lastresult; } return lastresult; @@ -2015,18 +2045,25 @@ public ArrayList deserListF(NBTTagCompound tag){ } return ls; } - + boolean broken; public ItemStack[] getItems(){ ArrayList all=new ArrayList<>(); all.addAll(circuitInv); - all.addAll(cachedItems); all.add(mInventory[getCircuitSlot()]); + if(recipe==false){broken=true; + return all.toArray(new ItemStack[0]); + } + all.addAll(cachedItems); return all.toArray(new ItemStack[0]); } public FluidStack[] getFluid(){ + if(recipe==false){ + broken=true; + return new FluidStack[0]; + } ArrayList all=new ArrayList<>(); all.addAll(cachedFluid); return all.toArray(new FluidStack[0]);} diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/MultiCircuitInputBus.java b/src/main/java/reobf/proghatches/gt/metatileentity/MultiCircuitInputBus.java index 1456e09..318ffbd 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/MultiCircuitInputBus.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/MultiCircuitInputBus.java @@ -1,24 +1,34 @@ package reobf.proghatches.gt.metatileentity; +import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.function.Consumer; +import java.util.function.Supplier; import java.util.stream.IntStream; import java.util.stream.Stream; import com.google.common.collect.ImmutableMap; +import com.gtnewhorizons.modularui.api.drawable.UITexture; import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.ModularWindow.Builder; +import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; import com.gtnewhorizons.modularui.common.widget.SlotWidget; import gregtech.api.GregTech_API; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.api.util.GT_TooltipDataCache; import gregtech.api.util.GT_Utility; import gregtech.api.util.GT_TooltipDataCache.TooltipData; import net.minecraft.item.ItemStack; @@ -34,10 +44,52 @@ public ItemStackHandler getInventoryHandler() { // TODO Auto-generated method stub return super.getInventoryHandler(); } + +int uiButtonCount; +private Widget createToggleButton(Supplier getter, Consumer setter, UITexture picture, + Supplier tooltipDataSupplier) { + return new CycleButtonWidget().setToggle(getter, setter) + .setStaticTexture(picture) + .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(7 + (uiButtonCount++ * BUTTON_SIZE), 62) + .setSize(BUTTON_SIZE, BUTTON_SIZE) + .setGTTooltip(tooltipDataSupplier); + } +private void addSortStacksButton(ModularWindow.Builder builder) { + builder.widget( + createToggleButton( + () -> !disableSort, + val -> disableSort = !val, + GT_UITextures.OVERLAY_BUTTON_SORTING_MODE, + () -> mTooltipCache.getData(SORTING_MODE_TOOLTIP))); +} + +private void addOneStackLimitButton(ModularWindow.Builder builder) { + builder.widget(createToggleButton(() -> !disableLimited, val -> { + disableLimited = !val; + updateSlots(); + }, GT_UITextures.OVERLAY_BUTTON_ONE_STACK_LIMIT, () -> mTooltipCache.getData(ONE_STACK_LIMIT_TOOLTIP))); +} +private static final String SORTING_MODE_TOOLTIP = "GT5U.machines.sorting_mode.tooltip"; +private static final String ONE_STACK_LIMIT_TOOLTIP = "GT5U.machines.one_stack_limit.tooltip"; +private static final int BUTTON_SIZE = 18; @Override public void addUIWidgets(Builder builder, UIBuildContext buildContext) { - + buildContext.addCloseListener(() -> uiButtonCount = 0); + addSortStacksButton(builder); + addOneStackLimitButton(builder); super.addUIWidgets(builder, buildContext); + + + switch (mTier) { + case 0 : getBaseMetaTileEntity().add1by1Slot(builder); + case 1 : getBaseMetaTileEntity().add2by2Slots(builder); + case 2 : getBaseMetaTileEntity().add3by3Slots(builder); + default : getBaseMetaTileEntity().add4by4Slots(builder); +} + + ProghatchesUtil.attachZeroSizedStackRemover(builder, buildContext); for(int i=1;i<4;i++) builder.widget( diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/RemoteInputHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/RemoteInputHatch.java index eeba267..3234295 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/RemoteInputHatch.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/RemoteInputHatch.java @@ -66,6 +66,7 @@ import gregtech.api.recipe.check.CheckRecipeResultRegistry; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Utility; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gregtech.common.tileentities.machines.IRecipeProcessingAwareHatch; import reobf.proghatches.gt.metatileentity.util.RecursiveLinkExcpetion; import reobf.proghatches.lang.LangManager; @@ -636,8 +637,9 @@ public CheckRecipeResult endRecipeProcessing(GT_MetaTileEntity_MultiBlockBase co }); - if (fail.get()) - return CheckRecipeResultRegistry.CRASH; + if (fail.get()){ + controller.stopMachine(ShutDownReasonRegistry.CRITICAL_NONE); + return CheckRecipeResultRegistry.CRASH;} tmp = null; return CheckRecipeResultRegistry.SUCCESSFUL; 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 57ded8b..72d9c2c 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/multi/IngredientDistributor.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/multi/IngredientDistributor.java @@ -442,8 +442,7 @@ public CheckRecipeResult endRecipeProcessing(GT_MetaTileEntity_MultiBlockBase co */ @SuppressWarnings("unchecked") private boolean distribute() { - //Optional in = getInput(); - //in.ifPresent(s->s.startRecipeProcessing()); + startRecipeProcessing(); Iterator possibleSource=null; try{ diff --git a/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java b/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java index 9a4abf7..3ed3b8b 100644 --- a/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java +++ b/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java @@ -168,8 +168,13 @@ public List getMixins() { if(ff)retLate.add("MixinAEAdaptorSkipStackSizeCheck"); if(ff)retLate.add("MixinAwarenessForDualHatch"); - if (!"true".equals(pp.get("noRemoveUnusedCacheInModularUIContainer"))) + + + /*if (!"true".equals(pp.get("noRemoveUnusedCacheInModularUIContainer"))) if(ff)retLate.add("MixinRemoveUnunsedItemStackCache"); + + */ + if(ff)retLate.add("MixinAE2FCCompat"); if (!"true".equals(pp.get("noRecipeFilterForDualHatch"))) { diff --git a/src/main/resources/assets/proghatches/lang/en_US.lang b/src/main/resources/assets/proghatches/lang/en_US.lang index bbdd3c2..8e5a1e3 100644 --- a/src/main/resources/assets/proghatches/lang/en_US.lang +++ b/src/main/resources/assets/proghatches/lang/en_US.lang @@ -561,3 +561,7 @@ hatch.dualinput.slave.fluid.name=Fluid Input Slave proghatch.chunk_loading_alert.info=Alerting Anchor: Chunk [%s] is not properly unloaded. proghatch.chunk_loading_alert.info.none=Alerting Anchor: No improperly-unloaded chunks. proghatch.waypoint.info=Alerting Anchor Mark +programmable_hatches.buffer.waila.hidden=§rAnd %s more §2Idle§r Buffers... +proghatch.dualhatch.optinv.broken=§4This Multiblock Machine does not support Upgrades! Please create issue if you see this. + + \ 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 a922630..4fe0242 100644 --- a/src/main/resources/assets/proghatches/lang/zh_CN.lang +++ b/src/main/resources/assets/proghatches/lang/zh_CN.lang @@ -559,3 +559,5 @@ hatch.dualinput.slave.fluid.name=流体输入镜像 proghatch.chunk_loading_alert.info=警告锚:位于[%s]的区块未被正确卸载 proghatch.chunk_loading_alert.info.none=警告锚: 没有非正常卸载区块 proghatch.waypoint.info=警告锚标记 +programmable_hatches.buffer.waila.hidden=§r以及%s个空闲的§2就绪§r缓存... +proghatch.dualhatch.optinv.broken=§4这个多方块不兼容升级!如果看到这行字请提issue