diff --git a/README.md b/README.md index d88d55a..bb18ed6 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,3 @@ [![](https://github.com/reobf/Programmable-Hatches-Mod/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/reobf/Programmable-Hatches-Mod/actions/workflows/build-and-test.yml) - diff --git a/build.gradle b/build.gradle index acc0f98..eac98c9 100644 --- a/build.gradle +++ b/build.gradle @@ -372,7 +372,7 @@ catch (Exception ignored) { // Pulls version first from the VERSION env and then git tag String identifiedVersion = null -String versionOverride = '0.0.2' +String versionOverride = '0.0.3' 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/gt/metatileentity/BufferedDualInputHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java index 3ff0b5d..bc29ae0 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java @@ -29,6 +29,7 @@ import net.minecraft.nbt.NBTException; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; +import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; @@ -94,7 +95,7 @@ import reobf.proghatches.main.MyMod; import reobf.proghatches.util.ProghatchesUtil; -public class BufferedDualInputHatch extends DualInputHatch { +public class BufferedDualInputHatch extends DualInputHatch implements IRecipeProcessingAwareDualHatch { public Widget circuitSlot(IItemHandlerModifiable inventory, int slot) { @@ -653,7 +654,7 @@ public static class CallerCheck { } private boolean updateEveryTick; public boolean updateEveryTick(){return updateEveryTick;} -public boolean prevdirty; +//public boolean prevdirty; @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { super.onPostTick(aBaseMetaTileEntity, aTick); @@ -678,7 +679,7 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { inv0.clearRecipeIfNeeded(); } - prevdirty=dirty; + // prevdirty=dirty; dirty=false; } @@ -1041,8 +1042,8 @@ private NBTTagCompound cv(String s) { thiz.disableWorking(); } else { thiz.enableWorking(); - BufferedDualInputHatch bff =(BufferedDualInputHatch) (thiz).getMetaTileEntity(); - bff.dirty=true; + //BufferedDualInputHatch bff =(BufferedDualInputHatch) (thiz).getMetaTileEntity(); + BufferedDualInputHatch.this.dirty=true; } }) .setPlayClickSoundResource( () -> thiz.isAllowedToWork() ? SoundResource.GUI_BUTTON_UP.resourceLocation @@ -1087,7 +1088,8 @@ public void detectAndSendChanges(boolean init) { //flush changes to client //sometimes vanilla detection will fail so sync it manually - if(last+1>=getBaseMetaTileEntity().getTimer()) + // System.out.println(last-getBaseMetaTileEntity().getTimer()); + if(last>=getBaseMetaTileEntity().getTimer()) getWindow().getContext().getContainer().inventorySlots .forEach(s->((Slot)s).onSlotChanged()); @@ -1215,9 +1217,7 @@ public boolean justUpdated() { @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public Optional getFirstNonEmptyInventory() { - dirty=true; - //IRecipeProcessingAwareHatch NOT working on dualhatch, so assume multi-te will consume items after calling this - return (Optional) inv0.stream() + return (Optional) inv0.stream() .filter(not(DualInvBuffer::isEmpty)) .findAny(); } @@ -1228,7 +1228,7 @@ private Predicate not(Predicate s) { @Override public Iterator inventories() { - dirty=true; + return inv0.stream() .filter(not(DualInvBuffer::isEmpty)) .iterator(); @@ -1418,4 +1418,15 @@ public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlaye return super.onRightclick(aBaseMetaTileEntity, aPlayer); } + +@Override +public void startRecipeProcessing() { + +} + +@Override +public CheckRecipeResult endRecipeProcessing(GT_MetaTileEntity_MultiBlockBase controller) { + dirty=true; + return CheckRecipeResultRegistry.SUCCESSFUL; +} } diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/IRecipeProcessingAwareDualHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/IRecipeProcessingAwareDualHatch.java new file mode 100644 index 0000000..7df9329 --- /dev/null +++ b/src/main/java/reobf/proghatches/gt/metatileentity/IRecipeProcessingAwareDualHatch.java @@ -0,0 +1,18 @@ +package reobf.proghatches.gt.metatileentity; + +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.common.tileentities.machines.IDualInputHatch; +import gregtech.common.tileentities.machines.IRecipeProcessingAwareHatch; + +public interface IRecipeProcessingAwareDualHatch extends +/*future GT Multiblock might check IDualInputHatch for 'instanceof IRecipeProcessingAwareHatch', so do not implement in case it's called twice*/ +/*IRecipeProcessingAwareHatch,*/ +IDualInputHatch{ + void startRecipeProcessing() ; + + CheckRecipeResult endRecipeProcessing(GT_MetaTileEntity_MultiBlockBase controller) ; + + +} diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java index 5d6b253..92ff6f6 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java @@ -1,9 +1,11 @@ package reobf.proghatches.gt.metatileentity; +import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; import static reobf.proghatches.main.Config.defaultObj; import java.util.EnumSet; import java.util.Optional; +import java.util.function.Consumer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -16,19 +18,25 @@ import net.minecraft.util.StatCollector; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; import com.glodblock.github.common.item.ItemFluidPacket; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.math.Pos2d; import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.ModularWindow.Builder; +import com.gtnewhorizons.modularui.api.widget.IWidgetBuilder; +import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import appeng.api.AEApi; import appeng.api.implementations.ICraftingPatternItem; import appeng.api.implementations.IPowerChannelState; import appeng.api.networking.GridFlags; @@ -37,6 +45,12 @@ import appeng.api.networking.crafting.ICraftingProvider; import appeng.api.networking.crafting.ICraftingProviderHelper; import appeng.api.networking.events.MENetworkCraftingPatternChange; +import appeng.api.networking.security.BaseActionSource; +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.api.util.AECableType; import appeng.api.util.DimensionalCoord; import appeng.api.util.IInterfaceViewable; @@ -45,8 +59,10 @@ import appeng.me.GridAccessException; import appeng.me.helpers.AENetworkProxy; import appeng.me.helpers.IGridProxyable; +import appeng.util.Platform; import gregtech.GT_Mod; import gregtech.api.GregTech_API; +import gregtech.api.enums.SoundResource; import gregtech.api.enums.Textures.BlockIcons; import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; @@ -134,10 +150,107 @@ public PatternDualInputHatch(int id, String name, String nameRegional, int tier, } ItemStack[] pattern = new ItemStack[36]; - - @Override + + + ButtonWidget createRefundButton(IWidgetBuilder builder) { + + Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { + + + PatternDualInputHatch.this.dirty=true; + try { + PatternDualInputHatch.this.refundAll(); + } catch (Exception e) { + + //e.printStackTrace(); + } + }) + .setPlayClickSound(true) + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_EXPORT) + + + .addTooltips(ImmutableList.of("Return all internally stored items back to AE")) + + .setPos(new Pos2d(getGUIWidth()-18-3,5+16+2)) + .setSize(16, 16); + return (ButtonWidget) button; +} + MachineSource requestSource; + private BaseActionSource getRequest() { + + if (requestSource == null) requestSource = new MachineSource((IActionHost) getBaseMetaTileEntity()); + return requestSource; +} + private void refundAll() throws Exception { + markDirty(); + BaseActionSource src = getRequest(); + IMEMonitor sg = getProxy().getStorage() + .getItemInventory(); + abstract class Inv{abstract ItemStack[] geti();abstract FluidTank[] getf(); } + Consumer consumer= inv->{ + try{ + for (ItemStack itemStack : inv.geti()) { + if (itemStack == null || itemStack.stackSize == 0) continue; + IAEItemStack rest = Platform.poweredInsert( + getProxy().getEnergy(), + sg, + AEApi.instance() + .storage() + .createItemStack(itemStack), + src); + itemStack.stackSize = rest != null && rest.getStackSize() > 0 ? (int) rest.getStackSize() : 0; + } + IMEMonitor fsg = getProxy().getStorage() + .getFluidInventory(); + for (FluidTank fluidStack : inv.getf()) { + if (fluidStack == null || fluidStack.getFluidAmount() == 0) continue; + IAEFluidStack rest = Platform.poweredInsert( + getProxy().getEnergy(), + fsg, + AEApi.instance() + .storage() + .createFluidStack(fluidStack.getFluid()), + src); + fluidStack.setFluid(Optional.ofNullable(rest).map(IAEFluidStack::getFluidStack).orElse(null)); + };} + catch(Exception e){throw new RuntimeException(e);} + }; + + inv0.stream().map(s->new Inv() { + @Override + ItemStack[] geti() { + return s.mStoredItemInternal; + } + + @Override + FluidTank[] getf() { + return s.mStoredFluidInternal; + } + }).forEach(consumer); + ; + consumer.accept(new Inv() { + + @Override + ItemStack[] geti() { + + return mInventory; + } + + @Override + FluidTank[] getf() { + + return mStoredFluid; + } + }); + + } + + + @Override public void addUIWidgets(Builder builder, UIBuildContext buildContext) { buildContext.addSyncedWindow(88, this::createPatternWindow); + + builder.widget(createRefundButton(builder)); builder.widget( new ButtonWidget().setOnClick( (clickData, widget) -> { @@ -151,8 +264,8 @@ public void addUIWidgets(Builder builder, UIBuildContext buildContext) { .addTooltips( ImmutableList.of(StatCollector.translateToLocalFormatted("programmable_hatches.gt.pattern"))) .setSize(16, 16) - .setPos(10 + 16 * 9, 3 + 16 * 2) - + // .setPos(10 + 16 * 9, 3 + 16 * 2) + .setPos(new Pos2d(getGUIWidth()-18-3,5+16+2+16+2)) ); super.addUIWidgets(builder, buildContext); diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/ProgrammingCircuitProvider.java b/src/main/java/reobf/proghatches/gt/metatileentity/ProgrammingCircuitProvider.java index 4687f96..96984d8 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/ProgrammingCircuitProvider.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/ProgrammingCircuitProvider.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.EnumSet; import java.util.List; +import java.util.Objects; import java.util.Optional; import net.minecraft.entity.player.EntityPlayer; @@ -40,6 +41,7 @@ import appeng.api.networking.security.IActionHost; import appeng.api.networking.security.MachineSource; import appeng.api.networking.storage.IStorageGrid; +import appeng.api.storage.IMEMonitor; import appeng.api.storage.data.IAEItemStack; import appeng.api.util.AECableType; import appeng.api.util.DimensionalCoord; @@ -174,14 +176,20 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { } } - - toReturn.forEach( - s -> getStorageGrid().getItemInventory() - .injectItems( - AEItemStack.create(s), - Actionable.MODULATE, - new MachineSource((IActionHost) getBaseMetaTileEntity()))); - toReturn.clear(); + //IMEMonitor ae = getStorageGrid().getItemInventory(); + toReturn.replaceAll( + s -> Optional.ofNullable( + getStorageGrid().getItemInventory() + .injectItems( + AEItemStack.create(s), + Actionable.MODULATE, + new MachineSource((IActionHost) getBaseMetaTileEntity())) + ) + .filter(ss->ss.getStackSize()<=0) + .map(ss->ss.getItemStack()) + .orElse(null) + ); + toReturn.removeIf(Objects::isNull); super.onPostTick(aBaseMetaTileEntity, aTick); } diff --git a/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java b/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java index ec9b61d..b5b4cda 100644 --- a/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java +++ b/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java @@ -95,6 +95,8 @@ public List getMixins() { System.out.println(pp); System.out.println("ccccccccccccccccccccccccccc"); + System.out.println("following warnings like 'Error loading class: xxxx' is normal and safe to ignore"); + // NEE is neither coremod nor mixinmod thus it's not in URL path, so add it to path or mixin will fail loadJarOf(MixinPlugin::hasTrait,"NotEnoughEnergistics"); @@ -104,8 +106,10 @@ public List getMixins() { if(!"true".equals(pp.get("noRemoveUnusedCacheInModularUIContainer"))) ret.add("MixinRemoveUnunsedItemStackCache"); - - if(!"true".equals(pp.get("noRecipeFilterForDualHatch"))){ + + //ret.add("MixinInterface"); + // ret.add("MixinInterfacePart"); + if(!"true".equals(pp.get("noRecipeFilterForDualHatch"))){ ret.add("MixinGTRecipeFilter"); // GT Multiblock will not set recipe filter of DualInputHatch, set it via mixin ret.add("MixinAddProgCircuitExemptToInputFilter");} @@ -114,11 +118,14 @@ public List getMixins() { ret.add("MixinCanCraftExempt"); ret.add("MixinHandleProgrammingOnRecipeStart"); - if(!"true".equals(pp.get("noFixTossBug"))) - ret.add("MixinFixTossWhenClickSlot"); + + if (FMLLaunchHandler.side() .isClient()) { - + + if(!"true".equals(pp.get("noFixTossBug"))) + ret.add("MixinFixTossWhenClickSlot"); + if(!"true".equals(pp.get("noPatternEncodingMixin"))){ ret.add("MixinPatternEncodingCiruitSpecialTreatment");// For ae2fc pattern encoder ret.add("MixinPatternEncodingCiruitSpecialTreatment2"); // For nee pattern encoder @@ -176,7 +183,8 @@ public static boolean hasTrait(Path p) { } - private boolean loadJarOf(final Predicate mod,String trace) { + @SuppressWarnings("deprecation") + private boolean loadJarOf(final Predicate mod,String trace) { try { File jar = findJarOf(mod); if (jar == null) { diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/MixinAwarenessForDualHatch.java b/src/main/java/reobf/proghatches/main/mixin/mixins/MixinAwarenessForDualHatch.java new file mode 100644 index 0000000..d95d1b1 --- /dev/null +++ b/src/main/java/reobf/proghatches/main/mixin/mixins/MixinAwarenessForDualHatch.java @@ -0,0 +1,67 @@ +package reobf.proghatches.main.mixin.mixins; + +import static gregtech.api.util.GT_Utility.filterValidMTEs; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Objects; +import java.util.function.Consumer; + +import net.minecraftforge.common.util.ForgeDirection; + +import org.spongepowered.asm.lib.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.util.GT_Utility; +import gregtech.common.tileentities.machines.IDualInputHatch; +import gregtech.common.tileentities.machines.IRecipeProcessingAwareHatch; +import reobf.proghatches.gt.cover.ProgrammingCover; +import reobf.proghatches.gt.metatileentity.IRecipeProcessingAwareDualHatch; + +@SuppressWarnings("unused") +@Mixin(value = GT_MetaTileEntity_MultiBlockBase.class, remap = false) +public abstract class MixinAwarenessForDualHatch { +@Shadow +public ArrayList mDualInputHatches = new ArrayList<>(); +@Shadow +public CheckRecipeResult checkRecipeResult; +@Inject( method = "startRecipeProcessing",at = { @At(value = "RETURN") }) + public void a(CallbackInfo c){ + for (IDualInputHatch hatch :(mDualInputHatches)) { + if (hatch instanceof IRecipeProcessingAwareDualHatch ) { + ((IRecipeProcessingAwareDualHatch) hatch).startRecipeProcessing(); + } + } + } + + + + @Inject( method = "endRecipeProcessing",at = { @At(value = "RETURN") }) + public void b(CallbackInfo c){ + Consumer setResultIfFailure = result -> { + if (!result.wasSuccessful()) { + this.checkRecipeResult = result; + } + }; + + for (IDualInputHatch hatch : (mDualInputHatches)) { + if (hatch instanceof IRecipeProcessingAwareDualHatch) { + setResultIfFailure.accept(((IRecipeProcessingAwareDualHatch)hatch).endRecipeProcessing( + (GT_MetaTileEntity_MultiBlockBase)(Object)this + )); + } + } + } + + +} diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/MixinInterface.java b/src/main/java/reobf/proghatches/main/mixin/mixins/MixinInterface.java new file mode 100644 index 0000000..3ac49b7 --- /dev/null +++ b/src/main/java/reobf/proghatches/main/mixin/mixins/MixinInterface.java @@ -0,0 +1,44 @@ +package reobf.proghatches.main.mixin.mixins; + +import org.spongepowered.asm.mixin.Implements; +import org.spongepowered.asm.mixin.Interface; +import org.spongepowered.asm.mixin.Mixin; + +import appeng.me.cluster.implementations.CraftingCPUCluster; +import appeng.tile.misc.TileInterface; +import gregtech.api.interfaces.tileentity.IEnergyConnected; +import net.minecraftforge.common.util.ForgeDirection; +@Mixin(value = TileInterface.class, remap = false, priority = 1) +public class MixinInterface implements IEnergyConnected { + + @Override + public byte getColorization() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public byte setColorization(byte aColor) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public long injectEnergyUnits(ForgeDirection side, long aVoltage, long aAmperage) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public boolean inputEnergyFrom(ForgeDirection side) { + // TODO Auto-generated method stub + return true; + } + + @Override + public boolean outputsEnergyTo(ForgeDirection side) { + // TODO Auto-generated method stub + return true; + } + +} diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/MixinInterfacePart.java b/src/main/java/reobf/proghatches/main/mixin/mixins/MixinInterfacePart.java new file mode 100644 index 0000000..cb64eb0 --- /dev/null +++ b/src/main/java/reobf/proghatches/main/mixin/mixins/MixinInterfacePart.java @@ -0,0 +1,29 @@ +package reobf.proghatches.main.mixin.mixins; + +import org.spongepowered.asm.mixin.Mixin; + +import appeng.parts.misc.PartInterface; +import appeng.parts.p2p.IPartGT5Power; +import appeng.tile.misc.TileInterface; +@Mixin(value = PartInterface.class, remap = false, priority = 1) +public class MixinInterfacePart implements IPartGT5Power{ + + @Override + public long injectEnergyUnits(long voltage, long amperage) { + + return 0; + } + + @Override + public boolean inputEnergy() { + + return true; + } + + @Override + public boolean outputsEnergy() { + + return true; + } + +} diff --git a/src/main/java/reobf/proghatches/main/registration/PHRecipes.java b/src/main/java/reobf/proghatches/main/registration/PHRecipes.java index 7b31baf..d83e38e 100644 --- a/src/main/java/reobf/proghatches/main/registration/PHRecipes.java +++ b/src/main/java/reobf/proghatches/main/registration/PHRecipes.java @@ -584,7 +584,7 @@ public void run() { GT_Utility.getIntegratedCircuit(16) ) - .fluidInputs(Materials.EnderPearl.getMolten(4000)) + .fluidInputs(Materials.Enderium.getMolten(144*16)) .itemOutputs(new ItemStack(MyMod.pitem, 1) ) .duration(40 * SECONDS) @@ -601,7 +601,7 @@ public void run() { GT_Utility.getIntegratedCircuit(17) ) - .fluidInputs(Materials.EnderPearl.getMolten(4000)) + .fluidInputs(Materials.Enderium.getMolten(144*16)) .itemOutputs(new ItemStack(MyMod.pstation, 1) ) .duration(40 * SECONDS)