diff --git a/dependencies.gradle b/dependencies.gradle index 01334cd..c39675f 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -149,7 +149,7 @@ dependencies { api("com.github.GTNewHorizons:ironchest:6.0.87:dev") - + api("com.github.GTNewHorizons:RemoteIO:2.7.1:dev") //////// diff --git a/src/main/java/reobf/proghatches/ae/BlockAutoFillerMKII.java b/src/main/java/reobf/proghatches/ae/BlockAutoFillerMKII.java index b03502e..8566da3 100644 --- a/src/main/java/reobf/proghatches/ae/BlockAutoFillerMKII.java +++ b/src/main/java/reobf/proghatches/ae/BlockAutoFillerMKII.java @@ -1,15 +1,19 @@ package reobf.proghatches.ae; +import java.util.EnumSet; +import java.util.HashMap; import java.util.List; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentText; import net.minecraft.util.StatCollector; import net.minecraft.world.World; +import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.ForgeDirection; import com.glodblock.github.FluidCraft; @@ -76,5 +80,18 @@ public void addInformation(ItemStack p_77624_1_, List l) { public String getName(ItemStack p_77624_1_) { // TODO Auto-generated method stub return null; + } + @Override + public void onBlockPlacedBy(World worldIn, int x, int y, int z, EntityLivingBase placer, ItemStack itemIn) { + + super.onBlockPlacedBy(worldIn, x, y, z, placer, itemIn); +if(worldIn.isRemote==false) + if (placer instanceof EntityPlayer) { + if (!(placer instanceof FakePlayer)) + ((TileAutoFillerMKII) worldIn.getTileEntity(x, y, z)).mark((EntityPlayer) placer); + } + + + } } diff --git a/src/main/java/reobf/proghatches/ae/BlockCyclicPatternSubmitter.java b/src/main/java/reobf/proghatches/ae/BlockCyclicPatternSubmitter.java index 27b74f7..cbe0161 100644 --- a/src/main/java/reobf/proghatches/ae/BlockCyclicPatternSubmitter.java +++ b/src/main/java/reobf/proghatches/ae/BlockCyclicPatternSubmitter.java @@ -42,7 +42,7 @@ public BlockCyclicPatternSubmitter(Material p_i45386_1_) { public void onBlockPlacedBy(World worldIn, int x, int y, int z, EntityLivingBase placer, ItemStack itemIn) { super.onBlockPlacedBy(worldIn, x, y, z, placer, itemIn); - + if(worldIn.isRemote==false) if (placer instanceof EntityPlayer) { if (!(placer instanceof FakePlayer)) ((TileCyclicPatternSubmitter) worldIn.getTileEntity(x, y, z)).mark((EntityPlayer) placer); diff --git a/src/main/java/reobf/proghatches/ae/TileAutoFillerMKII.java b/src/main/java/reobf/proghatches/ae/TileAutoFillerMKII.java index d00d9ea..b184fc5 100644 --- a/src/main/java/reobf/proghatches/ae/TileAutoFillerMKII.java +++ b/src/main/java/reobf/proghatches/ae/TileAutoFillerMKII.java @@ -5,6 +5,7 @@ import java.util.LinkedList; import java.util.List; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -266,5 +267,10 @@ public NBTTagCompound writeToNBTEventX(NBTTagCompound data) { return data; } + public void mark(EntityPlayer placer) { + getProxy().setOwner((EntityPlayer) placer); + + } + } diff --git a/src/main/java/reobf/proghatches/ae/a.java b/src/main/java/reobf/proghatches/ae/a.java deleted file mode 100644 index 3928378..0000000 --- a/src/main/java/reobf/proghatches/ae/a.java +++ /dev/null @@ -1,10 +0,0 @@ -package reobf.proghatches.ae; - -import java.util.ArrayList; - -public class a{ - - ArrayList s; - - -} diff --git a/src/main/java/reobf/proghatches/gt/cover/WirelessControlCover.java b/src/main/java/reobf/proghatches/gt/cover/WirelessControlCover.java index 6ba550f..4622d2b 100644 --- a/src/main/java/reobf/proghatches/gt/cover/WirelessControlCover.java +++ b/src/main/java/reobf/proghatches/gt/cover/WirelessControlCover.java @@ -34,7 +34,7 @@ import reobf.proghatches.lang.LangManager; import reobf.proghatches.util.ProghatchesUtil; -public class WirelessControlCover extends CoverBehaviorBase implements IControlsWorkCover { +public class WirelessControlCover extends CoverBehaviorBase /*implements IControlsWorkCover*/ { @Override public ModularWindow createWindow(CoverUIBuildContext buildContext) { diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/DualInputHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/DualInputHatch.java index 6d6cdd8..956f42c 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/DualInputHatch.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/DualInputHatch.java @@ -2394,7 +2394,7 @@ public FluidStack[] getDisplayFluid() { private void broken() { MyMod.LOG.fatal("FAILED TO UPDATE ME INPUTS!"); MyMod.LOG.fatal("basemeta:" + getBaseMetaTileEntity()); - + Thread.dumpStack(); if (getBaseMetaTileEntity() != null) { MyMod.LOG.fatal( "same:" + (getBaseMetaTileEntity().getMetaTileEntity() == DualInputHatch.this) @@ -2412,7 +2412,8 @@ public ItemStack[] getItems() { all.addAll(circuitInv); all.add(mInventory[getCircuitSlot()]); if (recipe == false) { - broken(); + if(!broken) + broken(); // Thread.dumpStack(); broken = true; all.removeIf(Objects::isNull); diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/RemoteInputBus.java b/src/main/java/reobf/proghatches/gt/metatileentity/RemoteInputBus.java index 438be70..dd2eefc 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/RemoteInputBus.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/RemoteInputBus.java @@ -588,7 +588,7 @@ public void removePhantom() { int size = a.getSizeInventory(); for (int i = 0; i < size; i++) { - if (a.getStackInSlot(i) != null && a.getStackInSlot(i).stackSize > 0 && i != index)// + if (a.getStackInSlot(i) != null && a.getStackInSlot(i).stackSize == 0 && i != index)// a.decrStackSize(i, 0);// remove 0-sized phantom item } 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 b18b4c8..eaad419 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/multi/IngredientDistributor.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/multi/IngredientDistributor.java @@ -93,1599 +93,1526 @@ import reobf.proghatches.main.registration.Registration; public class IngredientDistributor extends MTEEnhancedMultiBlockBase - implements ISurvivalConstructable { - - public IngredientDistributor(String aName) { - super(aName); - - } - - public static IStructureElement ofFrameAdder(Materials aFrameMaterial, Consumer onadded) { - IStructureElement frame = GTStructureUtility.ofFrame(aFrameMaterial); - - return new IStructureElement() { - - @Override - public boolean check(T t, World world, int x, int y, int z) { - boolean b = frame.check(t, world, x, y, z); - if (b) onadded.accept(t); - return b; - } - - @Override - public com.gtnewhorizon.structurelib.structure.IStructureElement.BlocksToPlace getBlocksToPlace(T t, - World world, int x, int y, int z, ItemStack trigger, AutoPlaceEnvironment env) { - - return frame.getBlocksToPlace(t, world, x, y, z, trigger, env); - } - - @Override - public com.gtnewhorizon.structurelib.structure.IStructureElement.PlaceResult survivalPlaceBlock(T t, - World world, int x, int y, int z, ItemStack trigger, AutoPlaceEnvironment env) { - - return frame.survivalPlaceBlock(t, world, x, y, z, trigger, env); - } - - @SuppressWarnings("deprecation") - @Override - public com.gtnewhorizon.structurelib.structure.IStructureElement.PlaceResult survivalPlaceBlock(T t, - World world, int x, int y, int z, ItemStack trigger, IItemSource s, EntityPlayerMP actor, - Consumer chatter) { - - return frame.survivalPlaceBlock(t, world, x, y, z, trigger, s, actor, chatter); - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - - return frame.spawnHint(aFrameMaterial, world, x, y, z, trigger); - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - - return frame.placeBlock(aFrameMaterial, world, x, y, z, trigger); - } - }; - - } - - public static boolean addDual(IngredientDistributor thiz, IGregTechTileEntity aTileEntity, short aBaseCasingIndex) { - if (aTileEntity == null) return false; - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) return false; - if (aMetaTileEntity instanceof IDualInputHatch) { - IDualInputHatch hatch = (IDualInputHatch) aMetaTileEntity; - hatch.updateTexture(aBaseCasingIndex); - hatch.updateCraftingIcon(thiz.getMachineCraftingIcon()); - if (hatch instanceof DualInputHatch) { - ((DualInputHatch) hatch).setFilter(null); - } - - return thiz.mDualInputHatches.add(hatch); - } - return false; - - } - - CommunicationPortHatch port; - boolean allMEHatch = true; - boolean hasHatchThisLayer; - boolean hasBusThisLayer; - - @Override - public void clearHatches() { - allMEHatch = true; - super.clearHatches(); - } - - @Override - public boolean addOutputBusToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - boolean ok = super.addOutputBusToMachineList(aTileEntity, aBaseCasingIndex); - if (ok && !hasBusThisLayer) { - hasBusThisLayer = true; - } else { - return false; - } - if (ok && !(aTileEntity.getMetaTileEntity() instanceof MTEHatchOutputBusME)) { - allMEHatch = false; - } - return ok; - }; - - @Override - public boolean addOutputHatchToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - boolean ok = super.addOutputHatchToMachineList(aTileEntity, aBaseCasingIndex); - if (ok && !hasHatchThisLayer) { - hasHatchThisLayer = true; - } else { - return false; - } - if (ok && !(aTileEntity.getMetaTileEntity() instanceof MTEHatchOutputME)) { - allMEHatch = false; - } - - return ok; - }; - - boolean isLiteVersion; - - @SuppressWarnings("unchecked") - IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition - .builder() - .addShape( - "first", - StructureUtility.transpose(new String[][] { { "m", "f", "c" }, { "m", "f", "c" }, { "m", "f", "c" } })) - .addShape( - "second", - StructureUtility.transpose(new String[][] { { "m", "f", "c" }, { "~", "c", "c" }, { "m", "c", "c" } })) - .addShape( - "third", - StructureUtility.transpose(new String[][] { { "m", "f", "c" }, { "m", "c", "c" }, { "◎", "c", "c" } })) - .addShape( - "piece", - StructureUtility.transpose(new String[][] { { " ", " ", " " }, { " ", "f", " " }, { "h", "h", "h" } })) - .addShape( - "piece_survival", - StructureUtility.transpose(new String[][] { { " ", " ", " " }, { " ", "f", " " }, { "h", "※", "h" } })) - - .addShape( - "last", - StructureUtility.transpose(new String[][] { { " ", " ", " " }, { " ", "f", " " }, { " ", "f", " " } })) - - .addElement( - 'c', - - ofBlock(GregTechAPI.sBlockCasings4, 12) - - ) - .addElement( - 'f', - StructureUtility.ofChain( - GTStructureUtility.ofFrame(Materials.Terbium), - ofFrameAdder(Materials.Yttrium, s -> ((IngredientDistributor) s).onCheapFrameFound()) - - )) - .addElement( - 'h', - buildHatchAdder(IngredientDistributor.class) - .atLeast( - HatchElement.OutputBus.withAdder(IngredientDistributor::addBus) - .withCount(s -> s.hasBusThisLayer ? 1 : 0), - HatchElement.OutputHatch.withAdder(IngredientDistributor::addHatch) - .withCount(s -> s.hasHatchThisLayer ? 1 : 0)) - // .shouldSkip((a,b)->a.hasBusThisLayer) - .casingIndex(CASING_INDEX) - .dot(1) - .buildAndChain(GregTechAPI.sBlockCasings4, 0)) - .addElement( - '※', - buildHatchAdder(IngredientDistributor.class) - .atLeast( - HatchElement.OutputBus.withAdder(IngredientDistributor::addBus) - .withCount(s -> s.hasBusThisLayer ? 1 : 0), - HatchElement.OutputHatch.withAdder(IngredientDistributor::addHatch) - .withCount(s -> s.hasHatchThisLayer ? 1 : 0)) - .allowOnly(ForgeDirection.DOWN) - // .shouldSkip((a,b)->a.hasBusThisLayer) - .casingIndex(CASING_INDEX) - .dot(1) - .buildAndChain(GregTechAPI.sBlockCasings4, 0)) - - .addElement( - 'm', - buildHatchAdder(IngredientDistributor.class).atLeast(HatchElement.Maintenance, HatchElement.Energy) - .casingIndex(CASING_INDEX) - .dot(3) - .buildAndChain( - buildHatchAdder(IngredientDistributor.class).atLeast(new IHatchElement() { - - @Override - public List> mteClasses() { - - return ImmutableList.of(CommunicationPortHatch.class); - } - - @Override - public IGTHatchAdder adder() { - - return (s, w, u) -> { - if (s == null) return false; - if (s.port != null) return false; - if (w.getMetaTileEntity() instanceof CommunicationPortHatch == false) return false; - s.port = (CommunicationPortHatch) w.getMetaTileEntity(); - if (s.port == null) return false; - s.port.updateTexture(CASING_INDEX); - return true; - - }; - } - - @Override - public String name() { - - return "commport"; - } - - @Override - public long count(IngredientDistributor t) { - - return port == null ? 0 : 1; - } - }) - - .hatchItemFilter(s -> ( - // have to return this or will this not be displayed in NEI 'availale hatches' list - is -> is.getItemDamage() - == Registration.CommunicationPortHatchOffset + Config.metaTileEntityOffset)) - - .casingIndex(CASING_INDEX) - .dot(3) - .build(), - - ofBlock(GregTechAPI.sBlockCasings4, 12))) - - .addElement( - '◎', - buildHatchAdder(IngredientDistributor.class) - - .atLeast( - - new IHatchElement() { - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public List> mteClasses() { - return (List) ImmutableList.of(IDualInputHatch.class); - } - - @Override - public IGTHatchAdder adder() { - return IngredientDistributor::addDual; - } - - @Override - public String name() { - return "dualadder"; - } - - @Override - public long count(IngredientDistributor t) { - - return t.mDualInputHatches.size(); - } - } - - , - HatchElement.InputBus, - HatchElement.InputHatch - - ) - .casingIndex(CASING_INDEX) - .dot(2) - .build() - - ) - .build(); - - public IngredientDistributor(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - Registration.items.add(new ItemStack(GregTechAPI.sBlockMachines, 1, aID)); - - } - - private void onCheapFrameFound() { - isLiteVersion = true; - return; - } - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - - return new IngredientDistributor(mName); - } - - protected static final int CASING_INDEX = 49 + 11 - 12; - - @Override - public ITexture[] getTexture(IGregTechTileEntity baseMetaTileEntity, ForgeDirection side, ForgeDirection facing, - int colorIndex, boolean active, boolean redstoneLevel) { - if (side != facing) { - return new ITexture[] { BlockIcons.getCasingTextureForId(CASING_INDEX) }; - } - return active ? getTexturesActive(BlockIcons.getCasingTextureForId(CASING_INDEX)) - : getTexturesInactive(BlockIcons.getCasingTextureForId(CASING_INDEX)); - } - - public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[] { aBaseTexture, TextureFactory.builder() - .addIcon(OVERLAY_FRONT_VACUUM_FREEZER_ACTIVE) - .extFacing() - .build() - // TextureFactory.builder() - // .setFromBlock(MyMod.iohub, BlockIOHub.magicNO_provider_active_overlay).glow().build() - }; - } - - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[] { aBaseTexture, TextureFactory.builder() - .addIcon(OVERLAY_FRONT_VACUUM_FREEZER) - .extFacing() - .build() - - }; - } - - @Override - public IStructureDefinition getStructureDefinition() { - - return STRUCTURE_DEFINITION; - } - - @Override - protected MultiblockTooltipBuilder createTooltip() { - final MultiblockTooltipBuilder tt = new MultiblockTooltipBuilder(); - Config.get(tt, "M_ID"); - return tt; - } - - @Override - public boolean isCorrectMachinePart(ItemStack aStack) { - - return true; - } - - @Override - public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { - - if (mMachine) return -1; - int b = survivialBuildPiece("first", stackSize, 1, 1, 0, elementBudget, env, false, true); - if (b > 0) return b; - b = survivialBuildPiece("second", stackSize, 0, 1, 0, elementBudget, env, false, true); - if (b > 0) return b; - b = survivialBuildPiece("third", stackSize, -1, 1, 0, elementBudget, env, false, true); - if (b > 0) return b; - - int size = stackSize.stackSize + 1; - int index = -2; - - while (true) { - b = survivialBuildPiece("piece_survival", stackSize, index, 1, 0, elementBudget, env, false, true); - if (b > 0) return b; - index--; - if (--size == 0) break; - - } ; - return survivialBuildPiece("last", stackSize, index, 1, 0, elementBudget, env, false, true); - - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece("first", stackSize, hintsOnly, 1, 1, 0); - buildPiece("second", stackSize, hintsOnly, 0, 1, 0); - buildPiece("third", stackSize, hintsOnly, -1, 1, 0); - int size = stackSize.stackSize + 1; - int index = -2; - while (buildPiece("piece", stackSize, hintsOnly, index, 1, 0)) { - - index--; - if (--size == 0) break; - } ; - buildPiece("last", stackSize, hintsOnly, index, 1, 0); - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - isLiteVersion = false; - port = null; - if (checkPiece("first", 1, 1, 0) && checkPiece("second", 0, 1, 0) && checkPiece("third", -1, 1, 0)) {} else { - return false; - } - int index = -2; - - // if(mDualInputHatches.size()!=1)return false; - hasHatchThisLayer = hasBusThisLayer = false; - while (checkPiece("piece", index, 1, 0)) { - hasHatchThisLayer = hasBusThisLayer = false; - index--; - } ; - - if (port != null && allMEHatch == false) { - return false; - } - return checkPiece("last", index, 1, 0) && this.mEnergyHatches.size() > 0; - - } - - @Override - public int getMaxEfficiency(ItemStack aStack) { - - return 10000; - } - - @Override - public int getDamageToComponent(ItemStack aStack) { - - return 0; - } - - @Override - public boolean explodesOnComponentBreak(ItemStack aStack) { - - return false; - } - - int ready; - - long storedEU; - - /* - * protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inventorySlot) { - * super.drawTexts(screenElements, inventorySlot); - * screenElements.widget( - * TextWidget.dynamicString(()-> - * StatCollector.translateToLocalFormatted("proghatches.ingdistr.eu", cost(),getMaxInputEu()) - * ).setDefaultColor(COLOR_TEXT_WHITE.get()) - * .setEnabled(widget -> { - * return (getBaseMetaTileEntity().isAllowedToWork()); - * })); - * } - */ - - boolean yield; - int count; - int cd; - int cdmax = 1; - - @Override - protected void runMachine(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.runMachine(aBaseMetaTileEntity, aTick); - if (!mMachine) return; - - if (ready > 0 && aBaseMetaTileEntity.isAllowedToWork()) { - boolean trylock = false; - boolean porton = false; - if (port != null && !lockRecipe - && isAllMEOutputEmpty() == true - && (!port.getBaseMetaTileEntity() - .getRedstone() || count > 0) - && !isInputEmpty()) { - count++; - porton = true; - if (count > 100) { - count = 0; - trylock = true; - } - } else { - count = 0; - } - if (port != null) { - yield = (!porton && count == 0 - && port.getBaseMetaTileEntity() - .getRedstone() - && !lockRecipe); - - port.setRS(porton); - } - if (trylock) { - - cd = 0; - cdmax = 1; - } - if ((port != null && lockRecipe && isAllMEOutputEmpty() == false) || port == null || trylock) - if (++cd >= cdmax) { - cd = 0; - if (distribute()) { - ready--; - if (port != null) { - if (trylock) lockRecipe = true; - - } - lastfail = null; - cd = 0; - cdmax = 1; - } else { - if (cdmax < 16) cdmax *= 2; - } - } - - if (port != null) { - if (isAllMEOutputEmpty()) { - lockRecipe = false; - } - } - - } - } - /* - * @SuppressWarnings({ "unchecked", "rawtypes", "unused" }) - * private Optional getInput(){ - * if(mDualInputHatches.size()==1){ - * return (Optional)Optional.ofNullable(mDualInputHatches.get(0)).filter(s->s instanceof - * IRecipeProcessingAwareDualHatch) - * .map(s->new IRecipeProcessingAwareHatch(){ - * public void startRecipeProcessing() { - * ((IRecipeProcessingAwareDualHatch)s).startRecipeProcessing(); - * } - * public CheckRecipeResult endRecipeProcessing(MTEMultiBlockBase controller) { - * return ((IRecipeProcessingAwareDualHatch)s).endRecipeProcessing(controller); - * }}) - * ; - * } - * if(mInputBusses.size()==1){ - * return (Optional)Optional.ofNullable(mInputBusses.get(0)).filter(s->s instanceof IRecipeProcessingAwareHatch); - * } - * if(mInputHatches.size()==1){ - * return (Optional)Optional.ofNullable(mInputHatches.get(0)).filter(s->s instanceof IRecipeProcessingAwareHatch); - * } - * return Optional.empty(); - * } - */ - - public boolean isInputEmpty() { - startRecipeProcessing(); - - try { - if (mDualInputHatches.size() == 1) { - return !mDualInputHatches.get(0) - .getFirstNonEmptyInventory() - .isPresent(); - } - if (mInputBusses.size() == 1) { - MTEHatchInputBus bus = mInputBusses.get(0); - for (int i = 0; i < bus.getSizeInventory(); i++) { - if (bus.getStackInSlot(i) != null || bus.getStackInSlot(i).stackSize > 0) { - return false; - } - } - } - if (mInputHatches.size() == 1) { - ArrayList bus = getStoredFluids(); - for (int i = 0; i < bus.size(); i++) { - if (bus.get(i) != null || bus.get(i).amount > 0) { - return false; - } - } - } - return true; - } finally { - endRecipeProcessing(); - - } - } - - @SuppressWarnings("unchecked") - private boolean distribute() { - - startRecipeProcessing(); - Iterator possibleSource = null; - try { - if (mDualInputHatches.size() == 1) { - IDualInputHatch input = mDualInputHatches.get(0); - possibleSource = (Iterator) input.inventories(); - - } - if (possibleSource == null && mInputHatches.size() == 1) { - ArrayList fluid = getStoredFluids(); - fluid.removeIf(s -> s == null || s.amount <= 0); - if (fluid.size() > 0) { - possibleSource = ImmutableList.of(new INeoDualInputInventory() { - - @Override - public ItemStack[] getItemInputs() { - return new ItemStack[0]; - } - - FluidStack[] obj = null; - - @Override - public FluidStack[] getFluidInputs() { - if (obj != null) return obj; - fluid.removeIf(s -> s == null || s.amount <= 0); - return obj = fluid.toArray(new FluidStack[fluid.size()]); - } - } - - ) - .iterator(); - - } - } - - if (possibleSource == null && mInputBusses.size() == 1) { - ArrayList items = getStoredInputs(); - items.removeIf(s -> s == null || s.stackSize <= 0); - if (items.size() > 0) { - possibleSource = ImmutableList.of(new INeoDualInputInventory() { - - @Override - public ItemStack[] getItemInputs() { - if (obj != null) return obj; - items.removeIf(s -> s == null || s.stackSize <= 0); - return obj = items.toArray(new ItemStack[items.size()]); - } - - ItemStack[] obj = null; - - @Override - public FluidStack[] getFluidInputs() { - return new FluidStack[0]; - } - } - - ) - .iterator(); - - } - } - } finally { - // boolean fail=in.map(s->s.endRecipeProcessing(this)).filter(s->!s.wasSuccessful()).isPresent(); - fail = false; - endRecipeProcessing(); - if (fail) return false; - } - if (possibleSource == null) return false; - Iterator itr = (Iterator) possibleSource; - if (blocking) { - if (allMEHatch) { - while (itr.hasNext()) { - if (moveToOutpusME(itr.next())) { - return true; - } ; - - } - } - return false; - } - while (itr.hasNext()) { - if (moveToOutpus(itr.next(), true)) { - return true; - } ; - - } - return false; - } - - boolean fail; - - public void setResultIfFailure(CheckRecipeResult result) { - if (result.wasSuccessful() == false) fail = true; - super.setResultIfFailure(result); - } - - TransferCheckResult lastfail; - boolean blocking; - int blockingNotAvailableReason; - - private boolean moveToOutpusME(IDualInputInventory opt) { - ItemStack[] i = opt.getItemInputs(); - FluidStack[] f = opt.getFluidInputs(); - - if (i.length > mOutputBusses.size()) return false; - if (f.length > mOutputHatches.size()) return false; - - for (int index = 0; index < mOutputBusses.size(); ++index) { - if (!(mOutputBusses.get(index) instanceof MTEHatchOutputBusME)) { - return false; - } - TransferCheckResult result = checkMEBus( - ((MTEHatchOutputBusME) mOutputBusses.get(index)), - index < i.length ? i[index] : null, - index); - if (!result.isSuccess) { - lastfail = result; - return false; - } ; - } - - for (int index = 0; index < mOutputHatches.size(); ++index) { - if (!(mOutputHatches.get(index) instanceof MTEHatchOutputME)) { - return false; - } - TransferCheckResult result = checkMEHatch( - ((MTEHatchOutputME) mOutputHatches.get(index)), - index < f.length ? f[index] : null, - index); - if (!result.isSuccess) { - lastfail = result; - return false; - } ; - } - - for (int index = 0; index < i.length; ++index) { - try { - IAEItemStack notadded = ((MTEHatchOutputBusME) mOutputBusses.get(index)).getProxy() - .getStorage() - .getItemInventory() - .injectItems( - AEApi.instance() - .storage() - .createItemStack(i[index]), - Actionable.MODULATE, - getActionSourceFor(mOutputBusses.get(index))); - - i[index].stackSize = Optional.ofNullable(notadded) - .map(s -> s.getStackSize()) - .orElse(0l) - .intValue(); - } catch (GridAccessException e) {} - - } - - for (int index = 0; index < f.length; ++index) { - try { - IAEFluidStack notadded = ((MTEHatchOutputME) mOutputHatches.get(index)).getProxy() - .getStorage() - .getFluidInventory() - .injectItems( - AEApi.instance() - .storage() - .createFluidStack(f[index]), - Actionable.MODULATE, - getActionSourceFor(mOutputHatches.get(index))); - - f[index].amount = Optional.ofNullable(notadded) - .map(s -> s.getStackSize()) - .orElse(0l) - .intValue(); - } catch (GridAccessException e) {} - } - mInputBusses.forEach(s -> s.updateSlots()); - mInputHatches.forEach(s -> s.updateSlots()); - - return true; - } - - public static class TransferCheckResultSyncer extends FakeSyncWidget { - - public TransferCheckResultSyncer(Supplier getter, Consumer setter) { - super(getter, setter, TransferCheckResult::ser, TransferCheckResult::deser); - } - } - - static class TransferCheckResult { - - boolean isSuccess; - String reason = ""; - - public String format() { - if (isSuccess) return "";// StatCollector.translateToLocalFormatted("proghatch.ingbuf.success"); - - for (int i = 0; i < args.length; i++) { - if (args[i] instanceof AEFluidStack) { - args[i] = ((AEFluidStack) args[i]).getFluidStack(); - } - if (args[i] instanceof FluidStack) { - args[i] = ((FluidStack) args[i]).getFluid() - .getName() + " " + ((FluidStack) args[i]).amount + "L"; - } - - if (args[i] instanceof AEItemStack) { - args[i] = ((AEItemStack) args[i]).getItemStack(); - } - if (args[i] instanceof ItemStack) { - args[i] = ((ItemStack) args[i]).getDisplayName() + "x" + ((ItemStack) args[i]).stackSize; - } - - } // only called on CLIENT, so it's safe to do like this - - return StatCollector.translateToLocalFormatted("proghatch.ingbuf.fail." + reason, args); - - } - - Object[] args = new Object[0]; - - static TransferCheckResult ofSuccess() { - return new TransferCheckResult() { - - { - isSuccess = true; - } - }; - } - - static TransferCheckResult ofFail(String key, Object... fmt) { - return new TransferCheckResult() { - - { - reason = key; - args = fmt; - } - }; - } - - static TransferCheckResult deser(PacketBuffer pb) { - try { - NBTTagCompound tag = pb.readNBTTagCompoundFromBuffer(); - if (tag.hasNoTags()) return null; - TransferCheckResult ret = new TransferCheckResult(); - ret.isSuccess = tag.getBoolean("s"); - ret.reason = tag.getString("r"); - int len = tag.getInteger("l"); - Object[] arg = new Object[len]; - for (int i = 0; i < len; ++i) { - Object r = null; - int type = tag.getInteger("t" + i); - - if (type == 0) r = tag.getString("o" + i); - if (type == 1) r = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("o" + i)); - if (type == 2) r = AEItemStack.loadItemStackFromNBT(tag.getCompoundTag("o" + i)); - if (type == 3) r = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("o" + i)); - // if(type==4) - // r=AEFluidStack.loadFluidStackFromNBT(tag.getCompoundTag("o"+i)); - - arg[i] = r; - } - ret.args = arg; - return ret; - } catch (IOException e) { - - e.printStackTrace(); - return null; - } - - } - - static void ser(PacketBuffer pb, TransferCheckResult thiz) { - - NBTTagCompound tag = new NBTTagCompound(); - if (thiz == null) { - try { - pb.writeNBTTagCompoundToBuffer(tag); - } catch (IOException e) { - e.printStackTrace(); - } - return; - } - try { - tag.setBoolean("s", thiz.isSuccess); - tag.setString("r", thiz.reason); - tag.setInteger("l", thiz.args.length); - for (int i = 0; i < thiz.args.length; i++) { - Object o = thiz.args[i]; - if (o instanceof String) { - tag.setString("o" + i, o.toString()); - tag.setInteger("t" + i, 0); - } - if (o instanceof ItemStack) { - tag.setTag("o" + i, ((ItemStack) o).writeToNBT(new NBTTagCompound())); - tag.setInteger("t" + i, 1); - } - if (o instanceof AEItemStack) { - NBTTagCompound tmp = new NBTTagCompound(); - ((AEItemStack) o).writeToNBT(tmp); - tag.setTag("o" + i, tmp); - tag.setInteger("t" + i, 2); - } - - if (o instanceof AEFluidStack) { - /* - * NBTTagCompound tmp = new NBTTagCompound(); - * ((AEFluidStack) o).writeToNBT(tmp); - * tag.setTag("o"+i, tmp); - * tag.setInteger("t"+i, 4); - */ - o = ((AEFluidStack) o).getFluidStack(); - } - - if (o instanceof FluidStack) { - tag.setTag("o" + i, ((FluidStack) o).writeToNBT(new NBTTagCompound())); - tag.setInteger("t" + i, 3); - } - - if (o instanceof Number) { - - tag.setString("o" + i, o.toString()); - tag.setInteger("t" + i, 0); - } - - } - - pb.writeNBTTagCompoundToBuffer(tag); - } catch (IOException e) { - - e.printStackTrace(); - } - } - - } - - private ItemStack cp(ItemStack c) { - if (c != null) return c.copy(); - return null; - } - - private IAEItemStack cp(IAEItemStack c) { - if (c != null) return c.copy(); - return null; - } - - private boolean isAllMEOutputEmpty() { - - for (MTEHatchOutputBus o : mOutputBusses) { - if (o instanceof MTEHatchOutputBusME) { - - IItemList itemCache; - try { - itemCache = (IItemList) f.get(o); - if (itemCache.isEmpty() == false) { - return false; - } - itemCache = o.getProxy() - .getStorage() - .getItemInventory() - .getStorageList(); - if (itemCache.isEmpty() == false) { - return false; - } - - } catch (Exception e) { - e.printStackTrace(); - } - } else return false; - } - - for (MTEHatchOutput o : mOutputHatches) { - if (o instanceof MTEHatchOutputME) { - - IItemList itemCache; - try { - itemCache = (IItemList) f2.get(o); - if (itemCache.isEmpty() == false) { - return false; - } - itemCache = o.getProxy() - .getStorage() - .getFluidInventory() - .getStorageList(); - if (itemCache.isEmpty() == false) { - return false; - } - } catch (Exception e) { - e.printStackTrace(); - } - } else return false; - } - return true; - } - - static Field f, f2; - static { - if (f == null) try { - f = MTEHatchOutputBusME.class.getDeclaredField("itemCache"); - f.setAccessible(true); - } catch (Exception e) { - e.printStackTrace(); - } - if (f2 == null) try { - f2 = MTEHatchOutputME.class.getDeclaredField("fluidCache"); - f2.setAccessible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static > T verifyForRealExistance(T tocheck, IMEMonitor tocheckfrom) { - - if (tocheck == null) return tocheck; - - return tocheckfrom.extractItems(tocheck, Actionable.SIMULATE, fakeSource); - - } - - @SuppressWarnings({ "unchecked", "unused" }) - private TransferCheckResult checkMEBus(MTEHatchOutputBusME bus, ItemStack check, int index) { - - try { - IItemList itemCache = (IItemList) f.get(bus); - Iterator itr = itemCache.iterator(); - // if(check!=null) - while (itr.hasNext()) { - IAEItemStack next; - if ((next = itr.next()).isSameType(check) == false && next.getStackSize() > 0) { - if (check == null) return TransferCheckResult.ofFail("cache.diff.bus.null", index, cp(next)); - return TransferCheckResult.ofFail("cache.diff.bus", index, cp(next), cp(check)); - } - } - IMEMonitor itemInventory = bus.getProxy() - .getStorage() - .getItemInventory(); - itr = itemInventory.getStorageList() - .iterator(); - // if(check!=null) - while (itr.hasNext()) { - IAEItemStack next= verifyForRealExistance(itr.next(), itemInventory); - if (next!=null) - if ((next).isSameType(check) == false - && next.getStackSize() > 0) { - if (check == null) return TransferCheckResult.ofFail("net.diff.bus.null", index, cp(next)); - return TransferCheckResult.ofFail("net.diff.bus", index, cp(next), cp(check)); - } - } - if (check != null) { - - IAEItemStack notadded = bus.getProxy() - .getStorage() - .getItemInventory() - .injectItems(AEItemStack.create(check), Actionable.SIMULATE, getActionSourceFor(bus)); - - if (notadded != null && notadded.getStackSize() > 0) return TransferCheckResult.ofFail( - "inject.failure." + (bus.getProxy() - .isPowered() - && bus.getProxy() - .isActive()) - + ".bus", - index, - check.copy(), - notadded.copy()); - } - } catch (Exception e) { - e.printStackTrace(); - return TransferCheckResult.ofFail("crash", e.getClass() + " " + e.getMessage()); - } - - return TransferCheckResult.ofSuccess(); - } - - @SuppressWarnings({ "unchecked", "unused" }) - private TransferCheckResult checkMEHatch(MTEHatchOutputME bus, FluidStack check, int index) { - - try { - IItemList itemCache = (IItemList) f2.get(bus); - Iterator itr = itemCache.iterator(); - // if(check!=null) - while (itr.hasNext()) { - IAEFluidStack next= itr.next(); - if(next!=null) - if (!sameType(next , (check)) && next.getStackSize() > 0) { - if (check == null) return TransferCheckResult.ofFail("cache.diff.hatch.null", index, cp(next)); - return TransferCheckResult.ofFail("cache.diff.hatch", index, cp(next), cp(check)); - } - } - IMEMonitor itemInventory = bus.getProxy() - .getStorage() - .getFluidInventory(); - itr = itemInventory.getStorageList() - .iterator(); - // if(check!=null) - while (itr.hasNext()) { - IAEFluidStack next= verifyForRealExistance(itr.next(), itemInventory); - if (next!=null) - if (!sameType(next , (check)) - && next.getStackSize() > 0) { - if (check == null) return TransferCheckResult.ofFail("net.diff.hatch.null", index, cp(next)); - return TransferCheckResult.ofFail("net.diff.hatch", index, cp(next), cp(check)); - } - } - if (check != null) { - IAEFluidStack notadded = bus.getProxy() - .getStorage() - .getFluidInventory() - .injectItems(AEFluidStack.create(check), Actionable.SIMULATE, getActionSourceFor(bus)); - if (notadded != null && notadded.getStackSize() > 0) return TransferCheckResult.ofFail( - "inject.failure." + (bus.getProxy() - .isPowered() - && bus.getProxy() - .isActive()) - + ".hatch", - index, - check.copy(), - notadded.copy()); - } - } catch (Exception e) { - e.printStackTrace(); - return TransferCheckResult.ofFail("crash", e.getClass() + " " + e.getMessage()); - } - - return TransferCheckResult.ofSuccess(); - } - - private IAEFluidStack cp(IAEFluidStack c) { - - if (c != null) return c.copy(); - return null; - } - - private FluidStack cp(FluidStack c) { - - if (c != null) return c.copy(); - return null; - } - - static BaseActionSource fakeSource = new BaseActionSource(); - - static Method[] cache; - - static BaseActionSource getActionSourceFor(Object o) { - if (cache == null) try { - cache = new Method[2]; - cache[0] = MTEHatchOutputBusME.class.getDeclaredMethod("getRequest"); - cache[1] = MTEHatchOutputME.class.getDeclaredMethod("getRequest"); - cache[0].setAccessible(true); - cache[1].setAccessible(true); - } catch (NoSuchMethodException e) { - cache = new Method[0];; - e.printStackTrace(); - } - if (cache.length == 0) return fakeSource; - - try { - if (o instanceof MTEHatchOutputBusME) return (BaseActionSource) cache[0].invoke(o); - if (o instanceof MTEHatchOutputME) return (BaseActionSource) cache[1].invoke(o); - } catch (Exception e) { - e.printStackTrace(); - } - - throw new RuntimeException("err"); - } - - private static boolean sameType(IAEFluidStack a, FluidStack b) { - if (a == null) return false; - if (b == null) return false; - if (a.getFluid() != b.getFluid()) return false; - if (a.getTagCompound() == null) { - if (b.tag == null) return true; - else return false; - } else { - if (b.tag == null) return false; - } - return a.getTagCompound() - .getNBTTagCompoundCopy() - .equals(b.tag); - } - - private boolean moveToOutpus(IDualInputInventory opt, boolean checkSpace) { - ItemStack[] i = opt.getItemInputs(); - i = Arrays.stream(i) - .filter(s -> s.stackSize > 0) - .toArray(ItemStack[]::new); - FluidStack[] f = opt.getFluidInputs(); - boolean anyDiff = false; - if (i.length > mOutputBusses.size()) { - lastfail = TransferCheckResult.ofFail("insufficient.length.bus", i.length, mOutputBusses.size()); - return false; - } - if (f.length > mOutputHatches.size()) { - lastfail = TransferCheckResult.ofFail("insufficient.length.hatch", f.length, mOutputHatches.size()); - return false; - } - - if (checkSpace) { - for (int index = 0; index < i.length; ++index) { - if (mOutputBusses.get(index) instanceof MTEHatchOutputBusME) { - if (i[index] != null) { - MTEHatchOutputBusME bus = (MTEHatchOutputBusME) mOutputBusses.get(index); - try { - IAEItemStack notadded = null; - notadded = (bus).getProxy() - .getStorage() - .getItemInventory() - .injectItems( - AEItemStack.create(i[index]), - Actionable.SIMULATE, - getActionSourceFor(bus)); - - if (notadded != null && notadded.getStackSize() > 0) { - TransferCheckResult ret = TransferCheckResult.ofFail( - "inject.failure." + (bus.getProxy() - .isPowered() - && bus.getProxy() - .isActive()) - + ".bus", - index, - i[index].copy(), - notadded.copy()); - if (!ret.isSuccess) { - lastfail = ret; - return false; - } - } - } catch (GridAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - continue; - } - MTEHatchOutputBus bus = mOutputBusses.get(index); - int acc = 0; - for (int x = 0; x < bus.getSizeInventory(); x++) { - if (bus.isValidSlot(x)) acc += space(i[index], bus.getStackInSlot(x)); - } - if (acc < i[index].stackSize) { - - lastfail = TransferCheckResult.ofFail("insufficient.space.bus", index, i[index].copy(), acc); - return false; - } - - } - for (int index = 0; index < f.length; ++index) { - if (mOutputHatches.get(index) instanceof MTEHatchOutputME) { - if (f[index] != null) { - MTEHatchOutputME bus = (MTEHatchOutputME) mOutputHatches.get(index); - try { - IAEFluidStack notadded = null; - notadded = (bus).getProxy() - .getStorage() - .getFluidInventory() - .injectItems( - AEFluidStack.create(f[index]), - Actionable.SIMULATE, - getActionSourceFor(bus)); - - if (notadded != null && notadded.getStackSize() > 0) { - TransferCheckResult ret = TransferCheckResult.ofFail( - "inject.failure." + (bus.getProxy() - .isPowered() - && bus.getProxy() - .isActive()) - + ".hatch", - index, - i[index].copy(), - notadded.copy()); - if (!ret.isSuccess) { - lastfail = ret; - return false; - } - } - } catch (GridAccessException e) { - e.printStackTrace(); - } - } - continue; - } - MTEHatchOutput hatch = mOutputHatches.get(index); - int acc = 0; - acc += space(f[index], hatch); - if (acc < f[index].amount) { - lastfail = TransferCheckResult.ofFail("insufficient.space.hatch", index, f[index].copy(), acc); - return false; - } - } - } - - for (int index = 0; index < i.length; ++index) { - if (mOutputBusses.get(index) instanceof MTEHatchOutputBusME) { - int before = i[index].stackSize; - - try { - IAEItemStack notadd = ((MTEHatchOutputBusME) mOutputBusses.get(index)).getProxy() - .getStorage() - .getItemInventory() - .injectItems( - AEApi.instance() - .storage() - .createItemStack(i[index]), - Actionable.MODULATE, - getActionSourceFor(mOutputBusses.get(index))); - if (notadd != null) i[index].stackSize = (int) notadd.getStackSize(); - else i[index].stackSize = 0; - } catch (Exception e) { - - e.printStackTrace(); - } - - // i[index].stackSize=((MTEHatchOutputBusME)mOutputBusses.get(index)).store(i[index]); - - if (i[index].stackSize != before) anyDiff = true; - - continue; - } - MTEHatchOutputBus bus = mOutputBusses.get(index); - int diff = storeAll(bus, i[index].copy()); - if (diff > 0) anyDiff = true; - i[index].stackSize -= diff; - } - - for (int index = 0; index < f.length; ++index) { - if (mOutputHatches.get(index) instanceof MTEHatchOutputME) { - int before = f[index].amount; - // f[index].amount-=((MTEHatchOutputME)mOutputHatches.get(index)).tryFillAE(f[index]); - try { - IAEFluidStack notadd = ((MTEHatchOutputME) mOutputHatches.get(index)).getProxy() - .getStorage() - .getFluidInventory() - .injectItems( - AEApi.instance() - .storage() - .createFluidStack(f[index]), - Actionable.MODULATE, - getActionSourceFor(mOutputHatches.get(index))); - if (notadd != null) f[index].amount = (int) notadd.getStackSize(); - else f[index].amount = 0; - } catch (Exception e) { - - e.printStackTrace(); - } - - if (f[index].amount != before) anyDiff = true; - - continue; - } - MTEHatchOutput hatch = mOutputHatches.get(index); - int diff = hatch.fill(f[index], true); - if (diff > 0) anyDiff = true; - f[index].amount -= diff; - - } - mInputBusses.forEach(s -> s.updateSlots()); - mInputHatches.forEach(s -> s.updateSlots()); - - return anyDiff; - } - - private static int storeAll(MTEHatchOutputBus bus, ItemStack aStack) { - bus.markDirty(); - int consumed = 0; - for (int i = 0, mInventoryLength = bus.mInventory.length; i < mInventoryLength && aStack.stackSize > 0; i++) { - ItemStack tSlot = bus.mInventory[i]; - if (GTUtility.isStackInvalid(tSlot)) { - int tRealStackLimit = Math.min(bus.getInventoryStackLimit(), aStack.getMaxStackSize()); - if (aStack.stackSize <= tRealStackLimit) { - bus.mInventory[i] = aStack; - consumed += aStack.stackSize; - return consumed; - } - bus.mInventory[i] = aStack.splitStack(tRealStackLimit); - consumed += tRealStackLimit; - } else { - int tRealStackLimit = Math.min(bus.getInventoryStackLimit(), tSlot.getMaxStackSize()); - if (tSlot.stackSize < tRealStackLimit && tSlot.isItemEqual(aStack) - && ItemStack.areItemStackTagsEqual(tSlot, aStack)) { - if (aStack.stackSize + tSlot.stackSize <= tRealStackLimit) { - bus.mInventory[i].stackSize += aStack.stackSize; - consumed += aStack.stackSize; - return consumed; - } else { - // more to serve - consumed += tRealStackLimit - tSlot.stackSize; - aStack.stackSize -= tRealStackLimit - tSlot.stackSize; - bus.mInventory[i].stackSize = tRealStackLimit; - - } - } - } - } - return consumed; - } - - private static int space(FluidStack in, IFluidStore store) { - return store.fill(in, false); - - } - - private static int space(ItemStack in, ItemStack store) { - if (store == null) { - return in.getMaxStackSize(); - } - if (in.getItem() == store.getItem() && in.getItemDamage() == store.getItemDamage() - && ItemStack.areItemStackTagsEqual(in, store)) { - - return in.getMaxStackSize() - store.stackSize; - } - - return 0; - - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - ready = aNBT.getInteger("ready"); - blocking = aNBT.getBoolean("blocking"); - emptyRun = aNBT.getBoolean("emptyRun"); - allMEHatch = aNBT.getBoolean("allMEHatch"); - count = aNBT.getInteger("count"); - cd = aNBT.getInteger("cd"); - cdmax = aNBT.getInteger("cdmax"); - lockRecipe = aNBT.getBoolean("lockRecipe"); - isLiteVersion = aNBT.getBoolean("isLiteVersion"); - super.loadNBTData(aNBT); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("ready", ready); - aNBT.setBoolean("blocking", blocking); - aNBT.setBoolean("emptyRun", emptyRun); - aNBT.setBoolean("allMEHatch", allMEHatch); - aNBT.setBoolean("isLiteVersion", isLiteVersion); - aNBT.setInteger("count", count); - aNBT.setInteger("cd", cd); - aNBT.setInteger("cdmax", cdmax); - aNBT.setBoolean("lockRecipe", lockRecipe); - super.saveNBTData(aNBT); - } - - boolean lockRecipe; - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - - if (mMachine && !aBaseMetaTileEntity.getWorld().isRemote) { - if (isLiteVersion) { - blocking = false; - blockingNotAvailableReason = 1; - } - if (blocking == false && port != null && aBaseMetaTileEntity.isAllowedToWork()) { - - LargeProgrammingCircuitProvider.shut(this, "proghatch.commport"); - } - if (!aBaseMetaTileEntity.getWorld().isRemote && mMachine) { - if (!allMEHatch) { - blocking = false; - blockingNotAvailableReason = 2; - } - if (mMaxProgresstime > 0 && mProgresstime + 1 >= mMaxProgresstime) { - if (ready <= 0 && !emptyRun) ready++; - - } - } - - if (blocking) blockingNotAvailableReason = 0; - } - - super.onPostTick(aBaseMetaTileEntity, aTick); - } - - boolean emptyRun; - - @Override - public CheckRecipeResult checkProcessing() { - mEfficiency = 10000; - final long inputVoltage = getMaxInputVoltage(); - calculateOverclockedNessMultiInternal(120, 100, 1, inputVoltage, false); - - mEUt /= -1; - if (ready > 0) { - mEUt = 0; - emptyRun = true; - return SimpleCheckRecipeResult.ofSuccess("proghatches.ingredientdistr.ready"); - } - emptyRun = false; - return SimpleCheckRecipeResult.ofSuccess("proghatches.ingredientdistr.charging"); - } - - @Override - public void addUIWidgets(com.gtnewhorizons.modularui.api.screen.ModularWindow.Builder builder, - UIBuildContext buildContext) { - builder.widget(new TransferCheckResultSyncer(() -> this.lastfail, s -> this.lastfail = s)); - builder.widget( - new DrawableWidget().setDrawable(GTUITextures.PICTURE_SCREEN_BLACK) - .setPos(4, 4) - .setSize(190, 85)); - final SlotWidget inventorySlot = new SlotWidget(inventoryHandler, 1); - builder.widget( - inventorySlot.setPos(173, 167) - .setBackground(GTUITextures.SLOT_DARK_GRAY)); - - final DynamicPositionedColumn screenElements = new DynamicPositionedColumn(); - drawTexts(screenElements, inventorySlot); - builder.widget( - new Scrollable().setVerticalScroll() - .widget(screenElements) - .setPos(10, 7) - .setSize(182, 79)); - - builder.widget(createPowerSwitchButton(builder)) - .widget(createBlockingModeButton(builder)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> blocking, val -> { blocking = val; }).setSynced(true, true)) - .widget( - new FakeSyncWidget.BooleanSyncer(() -> lockRecipe, val -> { lockRecipe = val; }).setSynced(true, false)) - .widget( - new FakeSyncWidget.BooleanSyncer(() -> port != null, val -> { clientport = val; }) - .setSynced(true, false)) - - .widget(new FakeSyncWidget.IntegerSyncer(() -> count, val -> { count = val; }).setSynced(true, false)) - .widget(new FakeSyncWidget.IntegerSyncer(() -> cd, val -> { cd = val; }).setSynced(true, false)) - .widget(new FakeSyncWidget.IntegerSyncer(() -> cdmax, val -> { cdmax = val; }).setSynced(true, false)) - .widget(new FakeSyncWidget.BooleanSyncer(() -> yield, val -> { yield = val; }).setSynced(true, false)) - .widget( - new FakeSyncWidget.IntegerSyncer( - () -> blockingNotAvailableReason, - val -> { blockingNotAvailableReason = val; }).setSynced(true, false)); - - } - - ButtonWidget createBlockingModeButton(IWidgetBuilder builder) { - - Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { blocking = !blocking; }) - .setPlayClickSoundResource( - () -> blocking ? SoundResource.GUI_BUTTON_UP.resourceLocation - : SoundResource.GUI_BUTTON_DOWN.resourceLocation) - .setBackground(() -> { - if (blocking) { - return new IDrawable[] { GTUITextures.BUTTON_STANDARD_PRESSED, - GTUITextures.OVERLAY_BUTTON_POWER_SWITCH_ON }; - } else { - return new IDrawable[] { GTUITextures.BUTTON_STANDARD, - GTUITextures.OVERLAY_BUTTON_POWER_SWITCH_OFF }; - } - }) - - .addTooltip(StatCollector.translateToLocal("proghatches.ingredientdistr.blocking")) - - .setTooltipShowUpDelay(TOOLTIP_DELAY) - .setPos(getVoidingModeButtonPos()) - .setSize(16, 16); - - IntStream.range(0, Integer.valueOf(StatCollector.translateToLocal("proghatches.ingredientdistr.blocking.desc"))) - .forEach( - s -> button.addTooltip(LangManager.translateToLocal("proghatches.ingredientdistr.blocking.desc." + s))); - - return (ButtonWidget) button; - } - - public static boolean addHatch(IngredientDistributor thiz, IGregTechTileEntity aTileEntity, short s) { - if (thiz.hasHatchThisLayer) { - return false; - } - return thiz.addOutputHatchToMachineList(aTileEntity, s); - } - - public static boolean addBus(IngredientDistributor thiz, IGregTechTileEntity aTileEntity, short s) { - if (thiz.hasBusThisLayer) { - return false; - } - return thiz.addOutputBusToMachineList(aTileEntity, s); - } - - boolean clientport; - - protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inventorySlot) { - - super.drawTexts(screenElements, inventorySlot); - screenElements.setSpace(0); - screenElements.setPos(0, 0); - // make it look same on 2.7.2- - // 2.7.2- set it to a non zero value - screenElements.widget(new TextWidget().setStringSupplier(() -> lastfail == null ? "" : lastfail.format() - - ) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> { return (getBaseMetaTileEntity().isAllowedToWork()) && lastfail != null; })); - - screenElements.widget(new TextWidget().setStringSupplier(() -> { - if (yield) return StatCollector.translateToLocal("proghatch.ingbuf.yield"); - if (count > 0) return StatCollector.translateToLocal("proghatch.ingbuf.acquring"); - if (lockRecipe) return StatCollector.translateToLocal("proghatch.ingbuf.locked"); - - return StatCollector.translateToLocal("proghatch.ingbuf.idle"); - } - - ) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> clientport)); - - screenElements.widget(TextWidget.dynamicString(() -> "lock:" + lockRecipe - - ) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> clientport)); - - screenElements.widget(TextWidget.dynamicString(() -> "count:" + count - - ) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> clientport)); - - screenElements.widget(TextWidget.dynamicString(() -> cd + "/" + cdmax - - ) - .setDefaultColor(COLOR_TEXT_WHITE.get()) - .setEnabled(widget -> clientport)); - - screenElements.widget( - new TextWidget().setStringSupplier( - () -> StatCollector.translateToLocal( - - "proghatch.ingbuf.noblocking.reason." + blockingNotAvailableReason) + implements ISurvivalConstructable { + + public IngredientDistributor(String aName) { + super(aName); + + } + + public static IStructureElement ofFrameAdder(Materials aFrameMaterial, Consumer onadded) { + IStructureElement frame = GTStructureUtility.ofFrame(aFrameMaterial); + + return new IStructureElement() { + + @Override + public boolean check(T t, World world, int x, int y, int z) { + boolean b = frame.check(t, world, x, y, z); + if (b) + onadded.accept(t); + return b; + } + + @Override + public com.gtnewhorizon.structurelib.structure.IStructureElement.BlocksToPlace getBlocksToPlace(T t, + World world, int x, int y, int z, ItemStack trigger, AutoPlaceEnvironment env) { + + return frame.getBlocksToPlace(t, world, x, y, z, trigger, env); + } + + @Override + public com.gtnewhorizon.structurelib.structure.IStructureElement.PlaceResult survivalPlaceBlock(T t, + World world, int x, int y, int z, ItemStack trigger, AutoPlaceEnvironment env) { + + return frame.survivalPlaceBlock(t, world, x, y, z, trigger, env); + } + + @SuppressWarnings("deprecation") + @Override + public com.gtnewhorizon.structurelib.structure.IStructureElement.PlaceResult survivalPlaceBlock(T t, + World world, int x, int y, int z, ItemStack trigger, IItemSource s, EntityPlayerMP actor, + Consumer chatter) { + + return frame.survivalPlaceBlock(t, world, x, y, z, trigger, s, actor, chatter); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + + return frame.spawnHint(aFrameMaterial, world, x, y, z, trigger); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + + return frame.placeBlock(aFrameMaterial, world, x, y, z, trigger); + } + }; + + } + + public static boolean addDual(IngredientDistributor thiz, IGregTechTileEntity aTileEntity, short aBaseCasingIndex) { + if (aTileEntity == null) + return false; + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) + return false; + if (aMetaTileEntity instanceof IDualInputHatch) { + IDualInputHatch hatch = (IDualInputHatch) aMetaTileEntity; + hatch.updateTexture(aBaseCasingIndex); + hatch.updateCraftingIcon(thiz.getMachineCraftingIcon()); + if (hatch instanceof DualInputHatch) { + ((DualInputHatch) hatch).setFilter(null); + } + + return thiz.mDualInputHatches.add(hatch); + } + return false; + + } + + CommunicationPortHatch port; + boolean allMEHatch = true; + boolean hasHatchThisLayer; + boolean hasBusThisLayer; + + @Override + public void clearHatches() { + allMEHatch = true; + super.clearHatches(); + } + + @Override + public boolean addOutputBusToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + boolean ok = super.addOutputBusToMachineList(aTileEntity, aBaseCasingIndex); + if (ok && !hasBusThisLayer) { + hasBusThisLayer = true; + } else { + return false; + } + if (ok && !(aTileEntity.getMetaTileEntity() instanceof MTEHatchOutputBusME)) { + allMEHatch = false; + } + return ok; + }; + + @Override + public boolean addOutputHatchToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + boolean ok = super.addOutputHatchToMachineList(aTileEntity, aBaseCasingIndex); + if (ok && !hasHatchThisLayer) { + hasHatchThisLayer = true; + } else { + return false; + } + if (ok && !(aTileEntity.getMetaTileEntity() instanceof MTEHatchOutputME)) { + allMEHatch = false; + } + + return ok; + }; + + boolean isLiteVersion; + + @SuppressWarnings("unchecked") + IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition + . builder() + .addShape("first", + StructureUtility + .transpose(new String[][] { { "m", "f", "c" }, { "m", "f", "c" }, { "m", "f", "c" } })) + .addShape("second", + StructureUtility + .transpose(new String[][] { { "m", "f", "c" }, { "~", "c", "c" }, { "m", "c", "c" } })) + .addShape("third", + StructureUtility + .transpose(new String[][] { { "m", "f", "c" }, { "m", "c", "c" }, { "◎", "c", "c" } })) + .addShape("piece", + StructureUtility + .transpose(new String[][] { { " ", " ", " " }, { " ", "f", " " }, { "h", "h", "h" } })) + .addShape("piece_survival", StructureUtility + .transpose(new String[][] { { " ", " ", " " }, { " ", "f", " " }, { "h", "※", "h" } })) + + .addShape("last", StructureUtility + .transpose(new String[][] { { " ", " ", " " }, { " ", "f", " " }, { " ", "f", " " } })) + + .addElement('c', + + ofBlock(GregTechAPI.sBlockCasings4, 12) + + ).addElement('f', StructureUtility.ofChain(GTStructureUtility.ofFrame(Materials.Terbium), ofFrameAdder(Materials.Yttrium, s -> ((IngredientDistributor) s).onCheapFrameFound()) + + )).addElement('h', buildHatchAdder(IngredientDistributor.class).atLeast(HatchElement.OutputBus.withAdder(IngredientDistributor::addBus).withCount(s -> s.hasBusThisLayer ? 1 : 0), HatchElement.OutputHatch.withAdder(IngredientDistributor::addHatch).withCount(s -> s.hasHatchThisLayer ? 1 : 0)) + // .shouldSkip((a,b)->a.hasBusThisLayer) + .casingIndex( + CASING_INDEX) + .dot(1).buildAndChain(GregTechAPI.sBlockCasings4, 0)) + .addElement('※', + buildHatchAdder(IngredientDistributor.class) + .atLeast( + HatchElement.OutputBus.withAdder(IngredientDistributor::addBus) + .withCount(s -> s.hasBusThisLayer ? 1 : 0), + HatchElement.OutputHatch.withAdder(IngredientDistributor::addHatch) + .withCount(s -> s.hasHatchThisLayer ? 1 : 0)) + .allowOnly(ForgeDirection.DOWN) + // .shouldSkip((a,b)->a.hasBusThisLayer) + .casingIndex(CASING_INDEX).dot(1).buildAndChain(GregTechAPI.sBlockCasings4, 0)) + + .addElement('m', + buildHatchAdder(IngredientDistributor.class).atLeast(HatchElement.Maintenance, HatchElement.Energy) + .casingIndex(CASING_INDEX).dot(3).buildAndChain(buildHatchAdder(IngredientDistributor.class) + .atLeast(new IHatchElement() { + + @Override + public List> mteClasses() { + + return ImmutableList.of(CommunicationPortHatch.class); + } + + @Override + public IGTHatchAdder adder() { + + return (s, w, u) -> { + if (s == null) + return false; + if (s.port != null) + return false; + if (w.getMetaTileEntity() instanceof CommunicationPortHatch == false) + return false; + s.port = (CommunicationPortHatch) w.getMetaTileEntity(); + if (s.port == null) + return false; + s.port.updateTexture(CASING_INDEX); + return true; + + }; + } + + @Override + public String name() { + + return "commport"; + } + + @Override + public long count(IngredientDistributor t) { + + return port == null ? 0 : 1; + } + }) + + .hatchItemFilter(s -> ( + // have to return this or will this not be + // displayed in NEI 'availale hatches' list + is -> is.getItemDamage() == Registration.CommunicationPortHatchOffset + Config.metaTileEntityOffset)) + + .casingIndex(CASING_INDEX).dot(3).build(), + + ofBlock(GregTechAPI.sBlockCasings4, 12))) + + .addElement('◎', buildHatchAdder(IngredientDistributor.class) + + .atLeast( + + new IHatchElement() { + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public List> mteClasses() { + return (List) ImmutableList.of(IDualInputHatch.class); + } + + @Override + public IGTHatchAdder adder() { + return IngredientDistributor::addDual; + } + + @Override + public String name() { + return "dualadder"; + } + + @Override + public long count(IngredientDistributor t) { + + return t.mDualInputHatches.size(); + } + } + + , HatchElement.InputBus, HatchElement.InputHatch + + ).casingIndex(CASING_INDEX).dot(2).build() + + ).build(); + + public IngredientDistributor(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + Registration.items.add(new ItemStack(GregTechAPI.sBlockMachines, 1, aID)); + + } + + private void onCheapFrameFound() { + isLiteVersion = true; + return; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + + return new IngredientDistributor(mName); + } + + protected static final int CASING_INDEX = 49 + 11 - 12; + + @Override + public ITexture[] getTexture(IGregTechTileEntity baseMetaTileEntity, ForgeDirection side, ForgeDirection facing, + int colorIndex, boolean active, boolean redstoneLevel) { + if (side != facing) { + return new ITexture[] { BlockIcons.getCasingTextureForId(CASING_INDEX) }; + } + return active ? getTexturesActive(BlockIcons.getCasingTextureForId(CASING_INDEX)) + : getTexturesInactive(BlockIcons.getCasingTextureForId(CASING_INDEX)); + } + + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, + TextureFactory.builder().addIcon(OVERLAY_FRONT_VACUUM_FREEZER_ACTIVE).extFacing().build() + // TextureFactory.builder() + // .setFromBlock(MyMod.iohub, + // BlockIOHub.magicNO_provider_active_overlay).glow().build() + }; + } + + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, + TextureFactory.builder().addIcon(OVERLAY_FRONT_VACUUM_FREEZER).extFacing().build() + + }; + } + + @Override + public IStructureDefinition getStructureDefinition() { + + return STRUCTURE_DEFINITION; + } + + @Override + protected MultiblockTooltipBuilder createTooltip() { + final MultiblockTooltipBuilder tt = new MultiblockTooltipBuilder(); + Config.get(tt, "M_ID"); + return tt; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + + return true; + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + + if (mMachine) + return -1; + int b = survivialBuildPiece("first", stackSize, 1, 1, 0, elementBudget, env, false, true); + if (b > 0) + return b; + b = survivialBuildPiece("second", stackSize, 0, 1, 0, elementBudget, env, false, true); + if (b > 0) + return b; + b = survivialBuildPiece("third", stackSize, -1, 1, 0, elementBudget, env, false, true); + if (b > 0) + return b; + + int size = stackSize.stackSize + 1; + int index = -2; + + while (true) { + b = survivialBuildPiece("piece_survival", stackSize, index, 1, 0, elementBudget, env, false, true); + if (b > 0) + return b; + index--; + if (--size == 0) + break; + + } + ; + return survivialBuildPiece("last", stackSize, index, 1, 0, elementBudget, env, false, true); + + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece("first", stackSize, hintsOnly, 1, 1, 0); + buildPiece("second", stackSize, hintsOnly, 0, 1, 0); + buildPiece("third", stackSize, hintsOnly, -1, 1, 0); + int size = stackSize.stackSize + 1; + int index = -2; + while (buildPiece("piece", stackSize, hintsOnly, index, 1, 0)) { + + index--; + if (--size == 0) + break; + } + ; + buildPiece("last", stackSize, hintsOnly, index, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + isLiteVersion = false; + port = null; + if (checkPiece("first", 1, 1, 0) && checkPiece("second", 0, 1, 0) && checkPiece("third", -1, 1, 0)) { + } else { + return false; + } + int index = -2; + + // if(mDualInputHatches.size()!=1)return false; + hasHatchThisLayer = hasBusThisLayer = false; + while (checkPiece("piece", index, 1, 0)) { + hasHatchThisLayer = hasBusThisLayer = false; + index--; + } + ; + + if (port != null && allMEHatch == false) { + return false; + } + return checkPiece("last", index, 1, 0) && this.mEnergyHatches.size() > 0; + + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + + return 10000; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + + return false; + } + + int ready; + + long storedEU; + + /* + * protected void drawTexts(DynamicPositionedColumn screenElements, + * SlotWidget inventorySlot) { super.drawTexts(screenElements, + * inventorySlot); screenElements.widget( TextWidget.dynamicString(()-> + * StatCollector.translateToLocalFormatted("proghatches.ingdistr.eu", + * cost(),getMaxInputEu()) ).setDefaultColor(COLOR_TEXT_WHITE.get()) + * .setEnabled(widget -> { return + * (getBaseMetaTileEntity().isAllowedToWork()); })); } + */ + + boolean yield; + int count; + int cd; + int cdmax = 1; + + @Override + protected void runMachine(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.runMachine(aBaseMetaTileEntity, aTick); + if (!mMachine) + return; + + if (ready > 0 && aBaseMetaTileEntity.isAllowedToWork()) { + boolean trylock = false; + boolean porton = false; + if (port != null && !lockRecipe && isAllMEOutputEmpty() == true + && (!port.getBaseMetaTileEntity().getRedstone() || count > 0) && !isInputEmpty()) { + count++; + porton = true; + if (count > 100) { + count = 0; + trylock = true; + } + } else { + count = 0; + } + if (port != null) { + yield = (!porton && count == 0 && port.getBaseMetaTileEntity().getRedstone() && !lockRecipe); + + port.setRS(porton); + } + if (trylock) { + + cd = 0; + cdmax = 1; + } + if ((port != null && lockRecipe && isAllMEOutputEmpty() == false) || port == null || trylock) + if (++cd >= cdmax) { + cd = 0; + if (distribute()) { + ready--; + if (port != null) { + if (trylock) + lockRecipe = true; + + } + lastfail = null; + cd = 0; + cdmax = 1; + } else { + if (cdmax < 16) + cdmax *= 2; + } + } + + if (port != null) { + if (isAllMEOutputEmpty()) { + lockRecipe = false; + } + } + + } + } + /* + * @SuppressWarnings({ "unchecked", "rawtypes", "unused" }) private + * Optional getInput(){ + * if(mDualInputHatches.size()==1){ return + * (Optional)Optional.ofNullable(mDualInputHatches.get(0)).filter(s->s + * instanceof IRecipeProcessingAwareDualHatch) .map(s->new + * IRecipeProcessingAwareHatch(){ public void startRecipeProcessing() { + * ((IRecipeProcessingAwareDualHatch)s).startRecipeProcessing(); } public + * CheckRecipeResult endRecipeProcessing(MTEMultiBlockBase controller) { + * return + * ((IRecipeProcessingAwareDualHatch)s).endRecipeProcessing(controller); }}) + * ; } if(mInputBusses.size()==1){ return + * (Optional)Optional.ofNullable(mInputBusses.get(0)).filter(s->s instanceof + * IRecipeProcessingAwareHatch); } if(mInputHatches.size()==1){ return + * (Optional)Optional.ofNullable(mInputHatches.get(0)).filter(s->s + * instanceof IRecipeProcessingAwareHatch); } return Optional.empty(); } + */ + + public boolean isInputEmpty() { + startRecipeProcessing(); + + try { + if (mDualInputHatches.size() == 1) { + return !mDualInputHatches.get(0).getFirstNonEmptyInventory().isPresent(); + } + if (mInputBusses.size() == 1) { + MTEHatchInputBus bus = mInputBusses.get(0); + for (int i = 0; i < bus.getSizeInventory(); i++) { + if (bus.getStackInSlot(i) != null || bus.getStackInSlot(i).stackSize > 0) { + return false; + } + } + } + if (mInputHatches.size() == 1) { + ArrayList bus = getStoredFluids(); + for (int i = 0; i < bus.size(); i++) { + if (bus.get(i) != null || bus.get(i).amount > 0) { + return false; + } + } + } + return true; + } finally { + endRecipeProcessing(); + + } + } + + private boolean distribute() { + + startRecipeProcessing(); + try { + return doDistribute(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + fail = false; + endRecipeProcessing(); + if (fail) + return false; + } + return false; + } + + @SuppressWarnings("unchecked") + private boolean doDistribute() { + + Iterator possibleSource = null; + try { + if (mDualInputHatches.size() == 1) { + IDualInputHatch input = mDualInputHatches.get(0); + possibleSource = (Iterator) input.inventories(); + + } + if (possibleSource == null && mInputHatches.size() == 1) { + ArrayList fluid = getStoredFluids(); + fluid.removeIf(s -> s == null || s.amount <= 0); + if (fluid.size() > 0) { + possibleSource = ImmutableList.of(new INeoDualInputInventory() { + + @Override + public ItemStack[] getItemInputs() { + return new ItemStack[0]; + } + + FluidStack[] obj = null; + + @Override + public FluidStack[] getFluidInputs() { + if (obj != null) + return obj; + fluid.removeIf(s -> s == null || s.amount <= 0); + return obj = fluid.toArray(new FluidStack[fluid.size()]); + } + } + + ).iterator(); + + } + } + + if (possibleSource == null && mInputBusses.size() == 1) { + ArrayList items = getStoredInputs(); + items.removeIf(s -> s == null || s.stackSize <= 0); + if (items.size() > 0) { + possibleSource = ImmutableList.of(new INeoDualInputInventory() { + + @Override + public ItemStack[] getItemInputs() { + if (obj != null) + return obj; + items.removeIf(s -> s == null || s.stackSize <= 0); + return obj = items.toArray(new ItemStack[items.size()]); + } + + ItemStack[] obj = null; + + @Override + public FluidStack[] getFluidInputs() { + return new FluidStack[0]; + } + } + + ).iterator(); + + } + } + } finally { + // boolean + // fail=in.map(s->s.endRecipeProcessing(this)).filter(s->!s.wasSuccessful()).isPresent(); + + } + if (possibleSource == null) + return false; + Iterator itr = (Iterator) possibleSource; + if (blocking) { + if (allMEHatch) { + while (itr.hasNext()) { + if (moveToOutpusME(itr.next())) { + return true; + } + ; + + } + } + return false; + } + while (itr.hasNext()) { + if (moveToOutpus(itr.next(), true)) { + return true; + } + ; + + } + return false; + } + + boolean fail; + + public void setResultIfFailure(CheckRecipeResult result) { + if (result.wasSuccessful() == false) + fail = true; + super.setResultIfFailure(result); + } + + TransferCheckResult lastfail; + boolean blocking; + int blockingNotAvailableReason; + + private boolean moveToOutpusME(IDualInputInventory opt) { + ItemStack[] i = opt.getItemInputs(); + FluidStack[] f = opt.getFluidInputs(); + + if (i.length > mOutputBusses.size()) + return false; + if (f.length > mOutputHatches.size()) + return false; + + for (int index = 0; index < mOutputBusses.size(); ++index) { + if (!(mOutputBusses.get(index) instanceof MTEHatchOutputBusME)) { + return false; + } + TransferCheckResult result = checkMEBus(((MTEHatchOutputBusME) mOutputBusses.get(index)), + index < i.length ? i[index] : null, index); + if (!result.isSuccess) { + lastfail = result; + return false; + } + ; + } + + for (int index = 0; index < mOutputHatches.size(); ++index) { + if (!(mOutputHatches.get(index) instanceof MTEHatchOutputME)) { + return false; + } + TransferCheckResult result = checkMEHatch(((MTEHatchOutputME) mOutputHatches.get(index)), + index < f.length ? f[index] : null, index); + if (!result.isSuccess) { + lastfail = result; + return false; + } + ; + } + + for (int index = 0; index < i.length; ++index) { + try { + IAEItemStack notadded = ((MTEHatchOutputBusME) mOutputBusses.get(index)).getProxy().getStorage() + .getItemInventory().injectItems(AEApi.instance().storage().createItemStack(i[index]), + Actionable.MODULATE, getActionSourceFor(mOutputBusses.get(index))); + + i[index].stackSize = Optional.ofNullable(notadded).map(s -> s.getStackSize()).orElse(0l).intValue(); + } catch (GridAccessException e) { + } + + } + + for (int index = 0; index < f.length; ++index) { + try { + IAEFluidStack notadded = ((MTEHatchOutputME) mOutputHatches.get(index)).getProxy().getStorage() + .getFluidInventory().injectItems(AEApi.instance().storage().createFluidStack(f[index]), + Actionable.MODULATE, getActionSourceFor(mOutputHatches.get(index))); + + f[index].amount = Optional.ofNullable(notadded).map(s -> s.getStackSize()).orElse(0l).intValue(); + } catch (GridAccessException e) { + } + } + mInputBusses.forEach(s -> s.updateSlots()); + mInputHatches.forEach(s -> s.updateSlots()); + + return true; + } + + public static class TransferCheckResultSyncer extends FakeSyncWidget { + + public TransferCheckResultSyncer(Supplier getter, Consumer setter) { + super(getter, setter, TransferCheckResult::ser, TransferCheckResult::deser); + } + } + + static class TransferCheckResult { + + boolean isSuccess; + String reason = ""; + + public String format() { + if (isSuccess) + return "";// StatCollector.translateToLocalFormatted("proghatch.ingbuf.success"); + + for (int i = 0; i < args.length; i++) { + if (args[i] instanceof AEFluidStack) { + args[i] = ((AEFluidStack) args[i]).getFluidStack(); + } + if (args[i] instanceof FluidStack) { + args[i] = ((FluidStack) args[i]).getFluid().getName() + " " + ((FluidStack) args[i]).amount + "L"; + } + + if (args[i] instanceof AEItemStack) { + args[i] = ((AEItemStack) args[i]).getItemStack(); + } + if (args[i] instanceof ItemStack) { + args[i] = ((ItemStack) args[i]).getDisplayName() + "x" + ((ItemStack) args[i]).stackSize; + } + + } // only called on CLIENT, so it's safe to do like this + + return StatCollector.translateToLocalFormatted("proghatch.ingbuf.fail." + reason, args); + + } + + Object[] args = new Object[0]; + + static TransferCheckResult ofSuccess() { + return new TransferCheckResult() { + + { + isSuccess = true; + } + }; + } + + static TransferCheckResult ofFail(String key, Object... fmt) { + return new TransferCheckResult() { + + { + reason = key; + args = fmt; + } + }; + } + + static TransferCheckResult deser(PacketBuffer pb) { + try { + NBTTagCompound tag = pb.readNBTTagCompoundFromBuffer(); + if (tag.hasNoTags()) + return null; + TransferCheckResult ret = new TransferCheckResult(); + ret.isSuccess = tag.getBoolean("s"); + ret.reason = tag.getString("r"); + int len = tag.getInteger("l"); + Object[] arg = new Object[len]; + for (int i = 0; i < len; ++i) { + Object r = null; + int type = tag.getInteger("t" + i); + + if (type == 0) + r = tag.getString("o" + i); + if (type == 1) + r = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("o" + i)); + if (type == 2) + r = AEItemStack.loadItemStackFromNBT(tag.getCompoundTag("o" + i)); + if (type == 3) + r = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("o" + i)); + // if(type==4) + // r=AEFluidStack.loadFluidStackFromNBT(tag.getCompoundTag("o"+i)); + + arg[i] = r; + } + ret.args = arg; + return ret; + } catch (IOException e) { + + e.printStackTrace(); + return null; + } + + } + + static void ser(PacketBuffer pb, TransferCheckResult thiz) { + + NBTTagCompound tag = new NBTTagCompound(); + if (thiz == null) { + try { + pb.writeNBTTagCompoundToBuffer(tag); + } catch (IOException e) { + e.printStackTrace(); + } + return; + } + try { + tag.setBoolean("s", thiz.isSuccess); + tag.setString("r", thiz.reason); + tag.setInteger("l", thiz.args.length); + for (int i = 0; i < thiz.args.length; i++) { + Object o = thiz.args[i]; + if (o instanceof String) { + tag.setString("o" + i, o.toString()); + tag.setInteger("t" + i, 0); + } + if (o instanceof ItemStack) { + tag.setTag("o" + i, ((ItemStack) o).writeToNBT(new NBTTagCompound())); + tag.setInteger("t" + i, 1); + } + if (o instanceof AEItemStack) { + NBTTagCompound tmp = new NBTTagCompound(); + ((AEItemStack) o).writeToNBT(tmp); + tag.setTag("o" + i, tmp); + tag.setInteger("t" + i, 2); + } + + if (o instanceof AEFluidStack) { + /* + * NBTTagCompound tmp = new NBTTagCompound(); + * ((AEFluidStack) o).writeToNBT(tmp); tag.setTag("o"+i, + * tmp); tag.setInteger("t"+i, 4); + */ + o = ((AEFluidStack) o).getFluidStack(); + } + + if (o instanceof FluidStack) { + tag.setTag("o" + i, ((FluidStack) o).writeToNBT(new NBTTagCompound())); + tag.setInteger("t" + i, 3); + } + + if (o instanceof Number) { + + tag.setString("o" + i, o.toString()); + tag.setInteger("t" + i, 0); + } + + } + + pb.writeNBTTagCompoundToBuffer(tag); + } catch (IOException e) { + + e.printStackTrace(); + } + } + + } + + private ItemStack cp(ItemStack c) { + if (c != null) + return c.copy(); + return null; + } + + private IAEItemStack cp(IAEItemStack c) { + if (c != null) + return c.copy(); + return null; + } + + private boolean isAllMEOutputEmpty() { + + for (MTEHatchOutputBus o : mOutputBusses) { + if (o instanceof MTEHatchOutputBusME) { + + IItemList itemCache; + try { + itemCache = (IItemList) f.get(o); + if (itemCache.isEmpty() == false) { + return false; + } + itemCache = o.getProxy().getStorage().getItemInventory().getStorageList(); + if (itemCache.isEmpty() == false) { + return false; + } + + } catch (Exception e) { + e.printStackTrace(); + } + } else + return false; + } + + for (MTEHatchOutput o : mOutputHatches) { + if (o instanceof MTEHatchOutputME) { + + IItemList itemCache; + try { + itemCache = (IItemList) f2.get(o); + if (itemCache.isEmpty() == false) { + return false; + } + itemCache = o.getProxy().getStorage().getFluidInventory().getStorageList(); + if (itemCache.isEmpty() == false) { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + } else + return false; + } + return true; + } + + static Field f, f2; + static { + if (f == null) + try { + f = MTEHatchOutputBusME.class.getDeclaredField("itemCache"); + f.setAccessible(true); + } catch (Exception e) { + e.printStackTrace(); + } + if (f2 == null) + try { + f2 = MTEHatchOutputME.class.getDeclaredField("fluidCache"); + f2.setAccessible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static > T verifyForRealExistance(T tocheck, IMEMonitor tocheckfrom) { + + if (tocheck == null) + return tocheck; + + return tocheckfrom.extractItems(tocheck, Actionable.SIMULATE, fakeSource); + + } + + @SuppressWarnings({ "unchecked", "unused" }) + private TransferCheckResult checkMEBus(MTEHatchOutputBusME bus, ItemStack check, int index) { + + try { + IItemList itemCache = (IItemList) f.get(bus); + Iterator itr = itemCache.iterator(); + // if(check!=null) + while (itr.hasNext()) { + IAEItemStack next; + if ((next = itr.next()).isSameType(check) == false && next.getStackSize() > 0) { + if (check == null) + return TransferCheckResult.ofFail("cache.diff.bus.null", index, cp(next)); + return TransferCheckResult.ofFail("cache.diff.bus", index, cp(next), cp(check)); + } + } + IMEMonitor itemInventory = bus.getProxy().getStorage().getItemInventory(); + itr = itemInventory.getStorageList().iterator(); + // if(check!=null) + while (itr.hasNext()) { + IAEItemStack next = verifyForRealExistance(itr.next(), itemInventory); + if (next != null) + if ((next).isSameType(check) == false && next.getStackSize() > 0) { + if (check == null) + return TransferCheckResult.ofFail("net.diff.bus.null", index, cp(next)); + return TransferCheckResult.ofFail("net.diff.bus", index, cp(next), cp(check)); + } + } + if (check != null) { + + IAEItemStack notadded = bus.getProxy().getStorage().getItemInventory() + .injectItems(AEItemStack.create(check), Actionable.SIMULATE, getActionSourceFor(bus)); + + if (notadded != null && notadded.getStackSize() > 0) + return TransferCheckResult.ofFail( + "inject.failure." + (bus.getProxy().isPowered() && bus.getProxy().isActive()) + ".bus", + index, check.copy(), notadded.copy()); + } + } catch (Exception e) { + e.printStackTrace(); + return TransferCheckResult.ofFail("crash", e.getClass() + " " + e.getMessage()); + } + + return TransferCheckResult.ofSuccess(); + } + + @SuppressWarnings({ "unchecked", "unused" }) + private TransferCheckResult checkMEHatch(MTEHatchOutputME bus, FluidStack check, int index) { + + try { + IItemList itemCache = (IItemList) f2.get(bus); + Iterator itr = itemCache.iterator(); + // if(check!=null) + while (itr.hasNext()) { + IAEFluidStack next = itr.next(); + if (next != null) + if (!sameType(next, (check)) && next.getStackSize() > 0) { + if (check == null) + return TransferCheckResult.ofFail("cache.diff.hatch.null", index, cp(next)); + return TransferCheckResult.ofFail("cache.diff.hatch", index, cp(next), cp(check)); + } + } + IMEMonitor itemInventory = bus.getProxy().getStorage().getFluidInventory(); + itr = itemInventory.getStorageList().iterator(); + // if(check!=null) + while (itr.hasNext()) { + IAEFluidStack next = verifyForRealExistance(itr.next(), itemInventory); + if (next != null) + if (!sameType(next, (check)) && next.getStackSize() > 0) { + if (check == null) + return TransferCheckResult.ofFail("net.diff.hatch.null", index, cp(next)); + return TransferCheckResult.ofFail("net.diff.hatch", index, cp(next), cp(check)); + } + } + if (check != null) { + IAEFluidStack notadded = bus.getProxy().getStorage().getFluidInventory() + .injectItems(AEFluidStack.create(check), Actionable.SIMULATE, getActionSourceFor(bus)); + if (notadded != null && notadded.getStackSize() > 0) + return TransferCheckResult.ofFail( + "inject.failure." + (bus.getProxy().isPowered() && bus.getProxy().isActive()) + ".hatch", + index, check.copy(), notadded.copy()); + } + } catch (Exception e) { + e.printStackTrace(); + return TransferCheckResult.ofFail("crash", e.getClass() + " " + e.getMessage()); + } + + return TransferCheckResult.ofSuccess(); + } + + private IAEFluidStack cp(IAEFluidStack c) { + + if (c != null) + return c.copy(); + return null; + } + + private FluidStack cp(FluidStack c) { + + if (c != null) + return c.copy(); + return null; + } + + static BaseActionSource fakeSource = new BaseActionSource(); + + static Method[] cache; + + static BaseActionSource getActionSourceFor(Object o) { + if (cache == null) + try { + cache = new Method[2]; + cache[0] = MTEHatchOutputBusME.class.getDeclaredMethod("getRequest"); + cache[1] = MTEHatchOutputME.class.getDeclaredMethod("getRequest"); + cache[0].setAccessible(true); + cache[1].setAccessible(true); + } catch (NoSuchMethodException e) { + cache = new Method[0]; + ; + e.printStackTrace(); + } + if (cache.length == 0) + return fakeSource; + + try { + if (o instanceof MTEHatchOutputBusME) + return (BaseActionSource) cache[0].invoke(o); + if (o instanceof MTEHatchOutputME) + return (BaseActionSource) cache[1].invoke(o); + } catch (Exception e) { + e.printStackTrace(); + } + + throw new RuntimeException("err"); + } + + private static boolean sameType(IAEFluidStack a, FluidStack b) { + if (a == null) + return false; + if (b == null) + return false; + if (a.getFluid() != b.getFluid()) + return false; + if (a.getTagCompound() == null) { + if (b.tag == null) + return true; + else + return false; + } else { + if (b.tag == null) + return false; + } + return a.getTagCompound().getNBTTagCompoundCopy().equals(b.tag); + } + + private boolean moveToOutpus(IDualInputInventory opt, boolean checkSpace) { + ItemStack[] i = opt.getItemInputs(); + i = Arrays.stream(i).filter(s -> s.stackSize > 0).toArray(ItemStack[]::new); + FluidStack[] f = opt.getFluidInputs(); + boolean anyDiff = false; + if (i.length > mOutputBusses.size()) { + lastfail = TransferCheckResult.ofFail("insufficient.length.bus", i.length, mOutputBusses.size()); + return false; + } + if (f.length > mOutputHatches.size()) { + lastfail = TransferCheckResult.ofFail("insufficient.length.hatch", f.length, mOutputHatches.size()); + return false; + } + + if (checkSpace) { + for (int index = 0; index < i.length; ++index) { + if (mOutputBusses.get(index) instanceof MTEHatchOutputBusME) { + if (i[index] != null) { + MTEHatchOutputBusME bus = (MTEHatchOutputBusME) mOutputBusses.get(index); + try { + IAEItemStack notadded = null; + notadded = (bus).getProxy().getStorage().getItemInventory().injectItems( + AEItemStack.create(i[index]), Actionable.SIMULATE, getActionSourceFor(bus)); + + if (notadded != null && notadded.getStackSize() > 0) { + TransferCheckResult ret = TransferCheckResult.ofFail("inject.failure." + + (bus.getProxy().isPowered() && bus.getProxy().isActive()) + ".bus", index, + i[index].copy(), notadded.copy()); + if (!ret.isSuccess) { + lastfail = ret; + return false; + } + } + } catch (GridAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + continue; + } + MTEHatchOutputBus bus = mOutputBusses.get(index); + int acc = 0; + for (int x = 0; x < bus.getSizeInventory(); x++) { + if (bus.isValidSlot(x)) + acc += space(i[index], bus.getStackInSlot(x)); + } + if (acc < i[index].stackSize) { + + lastfail = TransferCheckResult.ofFail("insufficient.space.bus", index, i[index].copy(), acc); + return false; + } + + } + for (int index = 0; index < f.length; ++index) { + if (mOutputHatches.get(index) instanceof MTEHatchOutputME) { + if (f[index] != null) { + MTEHatchOutputME bus = (MTEHatchOutputME) mOutputHatches.get(index); + try { + IAEFluidStack notadded = null; + notadded = (bus).getProxy().getStorage().getFluidInventory().injectItems( + AEFluidStack.create(f[index]), Actionable.SIMULATE, getActionSourceFor(bus)); + + if (notadded != null && notadded.getStackSize() > 0) { + TransferCheckResult ret = TransferCheckResult.ofFail("inject.failure." + + (bus.getProxy().isPowered() && bus.getProxy().isActive()) + ".hatch", index, + i[index].copy(), notadded.copy()); + if (!ret.isSuccess) { + lastfail = ret; + return false; + } + } + } catch (GridAccessException e) { + e.printStackTrace(); + } + } + continue; + } + MTEHatchOutput hatch = mOutputHatches.get(index); + int acc = 0; + acc += space(f[index], hatch); + if (acc < f[index].amount) { + lastfail = TransferCheckResult.ofFail("insufficient.space.hatch", index, f[index].copy(), acc); + return false; + } + } + } + + for (int index = 0; index < i.length; ++index) { + if (mOutputBusses.get(index) instanceof MTEHatchOutputBusME) { + int before = i[index].stackSize; + + try { + IAEItemStack notadd = ((MTEHatchOutputBusME) mOutputBusses.get(index)).getProxy().getStorage() + .getItemInventory().injectItems(AEApi.instance().storage().createItemStack(i[index]), + Actionable.MODULATE, getActionSourceFor(mOutputBusses.get(index))); + if (notadd != null) + i[index].stackSize = (int) notadd.getStackSize(); + else + i[index].stackSize = 0; + } catch (Exception e) { + + e.printStackTrace(); + } + + // i[index].stackSize=((MTEHatchOutputBusME)mOutputBusses.get(index)).store(i[index]); + + if (i[index].stackSize != before) + anyDiff = true; + + continue; + } + MTEHatchOutputBus bus = mOutputBusses.get(index); + int diff = storeAll(bus, i[index].copy()); + if (diff > 0) + anyDiff = true; + i[index].stackSize -= diff; + } + + for (int index = 0; index < f.length; ++index) { + if (mOutputHatches.get(index) instanceof MTEHatchOutputME) { + int before = f[index].amount; + // f[index].amount-=((MTEHatchOutputME)mOutputHatches.get(index)).tryFillAE(f[index]); + try { + IAEFluidStack notadd = ((MTEHatchOutputME) mOutputHatches.get(index)).getProxy().getStorage() + .getFluidInventory().injectItems(AEApi.instance().storage().createFluidStack(f[index]), + Actionable.MODULATE, getActionSourceFor(mOutputHatches.get(index))); + if (notadd != null) + f[index].amount = (int) notadd.getStackSize(); + else + f[index].amount = 0; + } catch (Exception e) { + + e.printStackTrace(); + } + + if (f[index].amount != before) + anyDiff = true; + + continue; + } + MTEHatchOutput hatch = mOutputHatches.get(index); + int diff = hatch.fill(f[index], true); + if (diff > 0) + anyDiff = true; + f[index].amount -= diff; + + } + mInputBusses.forEach(s -> s.updateSlots()); + mInputHatches.forEach(s -> s.updateSlots()); + + return anyDiff; + } + + private static int storeAll(MTEHatchOutputBus bus, ItemStack aStack) { + bus.markDirty(); + int consumed = 0; + for (int i = 0, mInventoryLength = bus.mInventory.length; i < mInventoryLength && aStack.stackSize > 0; i++) { + ItemStack tSlot = bus.mInventory[i]; + if (GTUtility.isStackInvalid(tSlot)) { + int tRealStackLimit = Math.min(bus.getInventoryStackLimit(), aStack.getMaxStackSize()); + if (aStack.stackSize <= tRealStackLimit) { + bus.mInventory[i] = aStack; + consumed += aStack.stackSize; + return consumed; + } + bus.mInventory[i] = aStack.splitStack(tRealStackLimit); + consumed += tRealStackLimit; + } else { + int tRealStackLimit = Math.min(bus.getInventoryStackLimit(), tSlot.getMaxStackSize()); + if (tSlot.stackSize < tRealStackLimit && tSlot.isItemEqual(aStack) + && ItemStack.areItemStackTagsEqual(tSlot, aStack)) { + if (aStack.stackSize + tSlot.stackSize <= tRealStackLimit) { + bus.mInventory[i].stackSize += aStack.stackSize; + consumed += aStack.stackSize; + return consumed; + } else { + // more to serve + consumed += tRealStackLimit - tSlot.stackSize; + aStack.stackSize -= tRealStackLimit - tSlot.stackSize; + bus.mInventory[i].stackSize = tRealStackLimit; + + } + } + } + } + return consumed; + } + + private static int space(FluidStack in, IFluidStore store) { + return store.fill(in, false); + + } + + private static int space(ItemStack in, ItemStack store) { + if (store == null) { + return in.getMaxStackSize(); + } + if (in.getItem() == store.getItem() && in.getItemDamage() == store.getItemDamage() + && ItemStack.areItemStackTagsEqual(in, store)) { + + return in.getMaxStackSize() - store.stackSize; + } + + return 0; + + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + ready = aNBT.getInteger("ready"); + blocking = aNBT.getBoolean("blocking"); + emptyRun = aNBT.getBoolean("emptyRun"); + allMEHatch = aNBT.getBoolean("allMEHatch"); + count = aNBT.getInteger("count"); + cd = aNBT.getInteger("cd"); + cdmax = aNBT.getInteger("cdmax"); + lockRecipe = aNBT.getBoolean("lockRecipe"); + isLiteVersion = aNBT.getBoolean("isLiteVersion"); + super.loadNBTData(aNBT); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("ready", ready); + aNBT.setBoolean("blocking", blocking); + aNBT.setBoolean("emptyRun", emptyRun); + aNBT.setBoolean("allMEHatch", allMEHatch); + aNBT.setBoolean("isLiteVersion", isLiteVersion); + aNBT.setInteger("count", count); + aNBT.setInteger("cd", cd); + aNBT.setInteger("cdmax", cdmax); + aNBT.setBoolean("lockRecipe", lockRecipe); + super.saveNBTData(aNBT); + } + + boolean lockRecipe; + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + + if (mMachine && !aBaseMetaTileEntity.getWorld().isRemote) { + if (isLiteVersion) { + blocking = false; + blockingNotAvailableReason = 1; + } + if (blocking == false && port != null && aBaseMetaTileEntity.isAllowedToWork()) { + + LargeProgrammingCircuitProvider.shut(this, "proghatch.commport"); + } + if (!aBaseMetaTileEntity.getWorld().isRemote && mMachine) { + if (!allMEHatch) { + blocking = false; + blockingNotAvailableReason = 2; + } + if (mMaxProgresstime > 0 && mProgresstime + 1 >= mMaxProgresstime) { + if (ready <= 0 && !emptyRun) + ready++; + + } + } + + if (blocking) + blockingNotAvailableReason = 0; + } + + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + boolean emptyRun; + + @Override + public CheckRecipeResult checkProcessing() { + mEfficiency = 10000; + final long inputVoltage = getMaxInputVoltage(); + calculateOverclockedNessMultiInternal(120, 100, 1, inputVoltage, false); + + mEUt /= -1; + if (ready > 0) { + mEUt = 0; + emptyRun = true; + return SimpleCheckRecipeResult.ofSuccess("proghatches.ingredientdistr.ready"); + } + emptyRun = false; + return SimpleCheckRecipeResult.ofSuccess("proghatches.ingredientdistr.charging"); + } + + @Override + public void addUIWidgets(com.gtnewhorizons.modularui.api.screen.ModularWindow.Builder builder, + UIBuildContext buildContext) { + builder.widget(new TransferCheckResultSyncer(() -> this.lastfail, s -> this.lastfail = s)); + builder.widget( + new DrawableWidget().setDrawable(GTUITextures.PICTURE_SCREEN_BLACK).setPos(4, 4).setSize(190, 85)); + final SlotWidget inventorySlot = new SlotWidget(inventoryHandler, 1); + builder.widget(inventorySlot.setPos(173, 167).setBackground(GTUITextures.SLOT_DARK_GRAY)); + + final DynamicPositionedColumn screenElements = new DynamicPositionedColumn(); + drawTexts(screenElements, inventorySlot); + builder.widget(new Scrollable().setVerticalScroll().widget(screenElements).setPos(10, 7).setSize(182, 79)); + + builder.widget(createPowerSwitchButton(builder)).widget(createBlockingModeButton(builder)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> blocking, val -> { + blocking = val; + }).setSynced(true, true)).widget(new FakeSyncWidget.BooleanSyncer(() -> lockRecipe, val -> { + lockRecipe = val; + }).setSynced(true, false)).widget(new FakeSyncWidget.BooleanSyncer(() -> port != null, val -> { + clientport = val; + }).setSynced(true, false)) + + .widget(new FakeSyncWidget.IntegerSyncer(() -> count, val -> { + count = val; + }).setSynced(true, false)).widget(new FakeSyncWidget.IntegerSyncer(() -> cd, val -> { + cd = val; + }).setSynced(true, false)).widget(new FakeSyncWidget.IntegerSyncer(() -> cdmax, val -> { + cdmax = val; + }).setSynced(true, false)).widget(new FakeSyncWidget.BooleanSyncer(() -> yield, val -> { + yield = val; + }).setSynced(true, false)) + .widget(new FakeSyncWidget.IntegerSyncer(() -> blockingNotAvailableReason, val -> { + blockingNotAvailableReason = val; + }).setSynced(true, false)); + + } + + ButtonWidget createBlockingModeButton(IWidgetBuilder builder) { + + Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { + blocking = !blocking; + }).setPlayClickSoundResource(() -> blocking ? SoundResource.GUI_BUTTON_UP.resourceLocation + : SoundResource.GUI_BUTTON_DOWN.resourceLocation).setBackground(() -> { + if (blocking) { + return new IDrawable[] { GTUITextures.BUTTON_STANDARD_PRESSED, + GTUITextures.OVERLAY_BUTTON_POWER_SWITCH_ON }; + } else { + return new IDrawable[] { GTUITextures.BUTTON_STANDARD, + GTUITextures.OVERLAY_BUTTON_POWER_SWITCH_OFF }; + } + }) + + .addTooltip(StatCollector.translateToLocal("proghatches.ingredientdistr.blocking")) + + .setTooltipShowUpDelay(TOOLTIP_DELAY).setPos(getVoidingModeButtonPos()).setSize(16, 16); + + IntStream.range(0, Integer.valueOf(StatCollector.translateToLocal("proghatches.ingredientdistr.blocking.desc"))) + .forEach(s -> button + .addTooltip(LangManager.translateToLocal("proghatches.ingredientdistr.blocking.desc." + s))); + + return (ButtonWidget) button; + } + + public static boolean addHatch(IngredientDistributor thiz, IGregTechTileEntity aTileEntity, short s) { + if (thiz.hasHatchThisLayer) { + return false; + } + return thiz.addOutputHatchToMachineList(aTileEntity, s); + } + + public static boolean addBus(IngredientDistributor thiz, IGregTechTileEntity aTileEntity, short s) { + if (thiz.hasBusThisLayer) { + return false; + } + return thiz.addOutputBusToMachineList(aTileEntity, s); + } + + boolean clientport; + + protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inventorySlot) { + + super.drawTexts(screenElements, inventorySlot); + screenElements.setSpace(0); + screenElements.setPos(0, 0); + // make it look same on 2.7.2- + // 2.7.2- set it to a non zero value + screenElements.widget(new TextWidget().setStringSupplier(() -> lastfail == null ? "" : lastfail.format() + + ).setDefaultColor(COLOR_TEXT_WHITE.get()).setEnabled(widget -> { + return (getBaseMetaTileEntity().isAllowedToWork()) && lastfail != null; + })); + + screenElements.widget(new TextWidget().setStringSupplier(() -> { + if (yield) + return StatCollector.translateToLocal("proghatch.ingbuf.yield"); + if (count > 0) + return StatCollector.translateToLocal("proghatch.ingbuf.acquring"); + if (lockRecipe) + return StatCollector.translateToLocal("proghatch.ingbuf.locked"); + + return StatCollector.translateToLocal("proghatch.ingbuf.idle"); + } + + ).setDefaultColor(COLOR_TEXT_WHITE.get()).setEnabled(widget -> clientport)); + + screenElements.widget(TextWidget.dynamicString(() -> "lock:" + lockRecipe - ) - .setDefaultColor(COLOR_TEXT_RED.get()) - .setEnabled(widget -> blockingNotAvailableReason > 0)); + ).setDefaultColor(COLOR_TEXT_WHITE.get()).setEnabled(widget -> clientport)); - } + screenElements.widget(TextWidget.dynamicString(() -> "count:" + count + + ).setDefaultColor(COLOR_TEXT_WHITE.get()).setEnabled(widget -> clientport)); + + screenElements.widget(TextWidget.dynamicString(() -> cd + "/" + cdmax + + ).setDefaultColor(COLOR_TEXT_WHITE.get()).setEnabled(widget -> clientport)); + + screenElements.widget(new TextWidget().setStringSupplier(() -> StatCollector.translateToLocal( + + "proghatch.ingbuf.noblocking.reason." + blockingNotAvailableReason) + + ).setDefaultColor(COLOR_TEXT_RED.get()).setEnabled(widget -> blockingNotAvailableReason > 0)); + + } } diff --git a/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java b/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java index fd15aa4..8b8f174 100644 --- a/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java +++ b/src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java @@ -163,8 +163,8 @@ public List getMixins() { } if (ff) retLate.add("eucrafting." + "MixinInvTracker"); - if (ff) retLate.add("MixinFixPipeCoverBug"); - if (ff) retLate.add("MixinFixPipeCoverBug2"); + //if (ff) retLate.add("MixinFixPipeCoverBug"); + // if (ff) retLate.add("MixinFixPipeCoverBug2"); if (ff) retLate.add("MixinAEAdaptorSkipStackSizeCheck"); if (ff) retLate.add("MixinAwarenessForDualHatch"); @@ -204,7 +204,7 @@ public List getMixins() { retLate.add("part2.MixinCraftingV2"); retLate.add("part2.MixinDirectionCapture"); - + // retLate.add("part2.M2"); retLate.add("part2.MixinEIOInit"); retLate.add("part2.MixinEIOBundle"); retLate.add("part2.MixinContextNoCircuitCache"); diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/MixinAwarenessForDualHatch.java b/src/main/java/reobf/proghatches/main/mixin/mixins/MixinAwarenessForDualHatch.java index f433b29..7a07071 100644 --- a/src/main/java/reobf/proghatches/main/mixin/mixins/MixinAwarenessForDualHatch.java +++ b/src/main/java/reobf/proghatches/main/mixin/mixins/MixinAwarenessForDualHatch.java @@ -19,7 +19,7 @@ import gregtech.common.tileentities.machines.IDualInputHatch; import reobf.proghatches.gt.metatileentity.util.IRecipeProcessingAwareDualHatch; -@SuppressWarnings("unused") + @Pseudo @Mixin( @@ -60,7 +60,7 @@ public abstract class MixinAwarenessForDualHatch { } @Unique - public void setResultIfFailure0(CheckRecipeResult endRecipeProcessing) { + private void setResultIfFailure0(CheckRecipeResult endRecipeProcessing) { try { MH_setResultIfFailure.invoke((MTEMultiBlockBase) (Object) this, endRecipeProcessing); } catch (Throwable e) { @@ -71,7 +71,7 @@ public void setResultIfFailure0(CheckRecipeResult endRecipeProcessing) { } @Unique - public ArrayList mDualInputHatches0() { + private ArrayList mDualInputHatches0() { try { return (ArrayList) MH_mDualInputHatches.invoke((MTEMultiBlockBase) (Object) this); } catch (Throwable e) { @@ -80,7 +80,7 @@ public ArrayList mDualInputHatches0() { } } - @Inject(method = "startRecipeProcessing", at = { @At(value = "RETURN") }/* ,require=1 */) + @Inject(method = "startRecipeProcessing", at = { @At(value = "RETURN") } ,require=1 ) public void startRecipeProcessing(CallbackInfo c) { ArrayList collection = mDualInputHatches0(); Iterator it = collection.iterator(); @@ -99,7 +99,7 @@ public void startRecipeProcessing(CallbackInfo c) { } } - @Inject(method = "endRecipeProcessing", at = { @At(value = "RETURN") }/* ,require=1 */) + @Inject(method = "endRecipeProcessing", at = { @At(value = "RETURN") } ,require=1 ) public void endRecipeProcessing(CallbackInfo c) { /* * Consumer setResultIfFailure = result -> { if diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/MixinFixPipeCoverBug.java b/src/main/java/reobf/proghatches/main/mixin/mixins/MixinFixPipeCoverBug.java index eec8235..83b0d87 100644 --- a/src/main/java/reobf/proghatches/main/mixin/mixins/MixinFixPipeCoverBug.java +++ b/src/main/java/reobf/proghatches/main/mixin/mixins/MixinFixPipeCoverBug.java @@ -14,7 +14,7 @@ @Mixin(value = BaseMetaPipeEntity.class, remap = false, priority = 999) public class MixinFixPipeCoverBug { - +/* ForgeDirection realSide; @Inject(remap = false, method = "onRightclick", at = @At(value = "INVOKE", target = "onPlayerAttach"), require = 1) @@ -25,5 +25,5 @@ public void onRightclick0(EntityPlayer aPlayer, ForgeDirection side, float aX, f realSide = GTUtility.determineWrenchingSide(side, aX, aY, aZ); } - +*/ } diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/MixinFixPipeCoverBug2.java b/src/main/java/reobf/proghatches/main/mixin/mixins/MixinFixPipeCoverBug2.java index 636078f..06b7a58 100644 --- a/src/main/java/reobf/proghatches/main/mixin/mixins/MixinFixPipeCoverBug2.java +++ b/src/main/java/reobf/proghatches/main/mixin/mixins/MixinFixPipeCoverBug2.java @@ -10,7 +10,7 @@ @Mixin(value = BaseMetaPipeEntity.class, remap = false, priority = 1000) public class MixinFixPipeCoverBug2 { - +/* @ModifyArg( remap = false, method = "onRightclick", @@ -27,5 +27,5 @@ public ForgeDirection onRightclick(ForgeDirection sd) { } ForgeDirection realSide; - +*/ } diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/part2/MixinCraftingV2.java b/src/main/java/reobf/proghatches/main/mixin/mixins/part2/MixinCraftingV2.java index e0e961b..5ef1c3b 100644 --- a/src/main/java/reobf/proghatches/main/mixin/mixins/part2/MixinCraftingV2.java +++ b/src/main/java/reobf/proghatches/main/mixin/mixins/part2/MixinCraftingV2.java @@ -4,6 +4,7 @@ import net.minecraftforge.common.util.ForgeDirection; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import appeng.api.implementations.tiles.ICraftingMachine; @@ -14,14 +15,20 @@ import reobf.proghatches.gt.metatileentity.util.ICraftingV2; @Mixin(value = BaseMetaTileEntity.class, remap = false) -public abstract class MixinCraftingV2 extends CommonMetaTileEntity implements ICraftingMachine { - +public abstract class MixinCraftingV2 /*extends CommonMetaTileEntity */implements ICraftingMachine { + + + private IMetaTileEntity getMetaTileEntity0(){ + + BaseMetaTileEntity x=(BaseMetaTileEntity)(Object)this; + return x.getMetaTileEntity(); + }; @Override public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table, ForgeDirection ejectionDirection) { if (notV2) return false; IMetaTileEntity mte; - if ((mte = getMetaTileEntity()) instanceof ICraftingV2) { + if ((mte = getMetaTileEntity0()) instanceof ICraftingV2) { if (((ICraftingV2) mte).enableCM() == false) { return false; } @@ -43,7 +50,7 @@ public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCraf public boolean acceptsPlans() { if (notV2) return false; IMetaTileEntity mte; - if ((mte = getMetaTileEntity()) instanceof ICraftingV2) { + if ((mte = getMetaTileEntity0()) instanceof ICraftingV2) { if (((ICraftingV2) mte).enableCM() == false) { return false; } diff --git a/src/main/java/reobf/proghatches/main/mixin/mixins/part2/MixinOC.java b/src/main/java/reobf/proghatches/main/mixin/mixins/part2/MixinOC.java index 00bfeb6..9fe1e1e 100644 --- a/src/main/java/reobf/proghatches/main/mixin/mixins/part2/MixinOC.java +++ b/src/main/java/reobf/proghatches/main/mixin/mixins/part2/MixinOC.java @@ -3,6 +3,7 @@ import net.minecraftforge.common.util.ForgeDirection; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.metatileentity.BaseMetaTileEntity; @@ -13,11 +14,15 @@ import li.cil.oc.api.network.SidedEnvironment; @Mixin(value = BaseMetaTileEntity.class, remap = false) -public abstract class MixinOC extends CommonMetaTileEntity implements Environment, SidedEnvironment { - +public abstract class MixinOC /*extends CommonMetaTileEntity */implements Environment, SidedEnvironment { +private IMetaTileEntity getMetaTileEntity0(){ + + BaseMetaTileEntity x=(BaseMetaTileEntity)(Object)this; + return x.getMetaTileEntity(); + }; @Override public Node sidedNode(ForgeDirection side) { - IMetaTileEntity mte = getMetaTileEntity(); + IMetaTileEntity mte = getMetaTileEntity0(); if (mte instanceof SidedEnvironment) { return ((SidedEnvironment) mte).sidedNode(side); } @@ -26,7 +31,7 @@ public Node sidedNode(ForgeDirection side) { @Override public boolean canConnect(ForgeDirection side) { - IMetaTileEntity mte = getMetaTileEntity(); + IMetaTileEntity mte = getMetaTileEntity0(); if (mte instanceof SidedEnvironment) { return ((SidedEnvironment) mte).canConnect(side); } @@ -36,7 +41,7 @@ public boolean canConnect(ForgeDirection side) { @Override public Node node() { - IMetaTileEntity mte = getMetaTileEntity(); + IMetaTileEntity mte = getMetaTileEntity0(); if (mte instanceof Environment) { return ((Environment) mte).node(); } @@ -45,7 +50,7 @@ public Node node() { @Override public void onConnect(Node node) { - IMetaTileEntity mte = getMetaTileEntity(); + IMetaTileEntity mte = getMetaTileEntity0(); if (mte instanceof Environment) { ((Environment) mte).onConnect(node); } @@ -54,7 +59,7 @@ public void onConnect(Node node) { @Override public void onDisconnect(Node node) { - IMetaTileEntity mte = getMetaTileEntity(); + IMetaTileEntity mte = getMetaTileEntity0(); if (mte instanceof Environment) { ((Environment) mte).onDisconnect(node); } @@ -62,7 +67,7 @@ public void onDisconnect(Node node) { @Override public void onMessage(Message message) { - IMetaTileEntity mte = getMetaTileEntity(); + IMetaTileEntity mte = getMetaTileEntity0(); if (mte instanceof Environment) { ((Environment) mte).onMessage(message); } diff --git a/src/main/java/reobf/proghatches/main/registration/Registration.java b/src/main/java/reobf/proghatches/main/registration/Registration.java index 0aec062..62ccaf2 100644 --- a/src/main/java/reobf/proghatches/main/registration/Registration.java +++ b/src/main/java/reobf/proghatches/main/registration/Registration.java @@ -2,6 +2,8 @@ import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.function.Supplier; @@ -17,7 +19,9 @@ import gregtech.api.GregTechAPI; import gregtech.api.enums.Dyes; import gregtech.api.enums.GTValues; +import gregtech.api.interfaces.ITexture; import gregtech.api.render.TextureFactory; +import gregtech.api.util.CoverBehaviorBase; import gregtech.api.util.LightingHelper; import gregtech.common.render.GTCopiedBlockTextureRender; import reobf.proghatches.eucrafting.AECover; @@ -202,26 +206,26 @@ public void run() { 5, 4, 1); - - GregTechAPI.registerCover( + + registerCover( new ItemStack(MyMod.cover, 1, 100), TextureFactory.of( MACHINE_CASINGS[1][0], TextureFactory.of(gregtech.api.enums.Textures.BlockIcons.OVERLAY_SCREEN_GLOW)), new LevelControlCover()); - GregTechAPI.registerCover( + registerCover( new ItemStack(MyMod.cover, 1, 0), TextureFactory.of( MACHINE_CASINGS[1][0], TextureFactory.of(gregtech.api.enums.Textures.BlockIcons.OVERLAY_SCREEN_GLOW)), new ProgrammingCover()); - GregTechAPI.registerCover( + registerCover( new ItemStack(MyMod.cover, 1, 1), TextureFactory.of( MACHINE_CASINGS[1][0], TextureFactory.of(gregtech.api.enums.Textures.BlockIcons.OVERLAY_SCREEN_GLOW)), new WirelessControlCover()); - GregTechAPI.registerCover( + registerCover( new ItemStack(MyMod.cover, 1, 4), TextureFactory.of( MACHINE_CASINGS[1][0], @@ -229,7 +233,7 @@ public void run() { new LinkedBusSlaveCover()); // WIP /* - * GregTechAPI.registerCover( + * registerCover( * new ItemStack(MyMod.cover, 1, 15), * TextureFactory.of( * MACHINE_CASINGS[1][0], @@ -237,14 +241,14 @@ public void run() { * new RecipeOutputAwarenessCover()); */ /* - * GregTechAPI.registerCover( + * registerCover( * new ItemStack(MyMod.cover, 1, 2), * TextureFactory.of( * MACHINE_CASINGS[1][0], * TextureFactory.of(gregtech.api.enums.Textures.BlockIcons.OVERLAY_SCREEN_GLOW)), * new RecipeCheckResultCover()); */ - GregTechAPI.registerCover( + registerCover( new ItemStack(MyMod.cover, 1, 3), TextureFactory.of( MACHINE_CASINGS[1][0], @@ -254,14 +258,14 @@ public void run() { for (int i = 0; i < 15; i++) { ; - GregTechAPI.registerCover( + registerCover( new ItemStack(MyMod.smartarm, 1, i), TextureFactory .of(MACHINE_CASINGS[i][0], TextureFactory.of(gregtech.api.enums.Textures.BlockIcons.OVERLAY_ARM)), new SmartArmCover(i)); } - GregTechAPI.registerCover( + registerCover( new ItemStack(MyMod.cover, 1, 32), TextureFactory.of( AEApi.instance() @@ -269,29 +273,29 @@ public void run() { new AECover(InterfaceData.class)); - GregTechAPI.registerCover( + registerCover( new ItemStack(MyMod.cover, 1, 33), TextureFactory.of(ItemAndBlockHolder.INTERFACE), new AECover(InterfaceData.FluidInterfaceData_TileFluidInterface.class)); - GregTechAPI.registerCover( + registerCover( new ItemStack(MyMod.cover, 1, 34), TextureFactory.of( AEApi.instance() .blocks().blockInterface.block()), new AECover(InterfaceP2PNoFluidData.class)); - GregTechAPI.registerCover( + registerCover( new ItemStack(MyMod.cover, 1, 35), TextureFactory.of(ItemAndBlockHolder.INTERFACE), new AECover(InterfaceP2PData.class)); - GregTechAPI.registerCover( + registerCover( new ItemStack(MyMod.cover, 1, 36), new DeferredGetterTexture(() -> MyMod.block_euinterface, ForgeDirection.UP, 0, Dyes._NULL.mRGBa, false), new AECover(InterfaceP2PEUData.class)); - GregTechAPI.registerCover( + registerCover( new ItemStack(MyMod.cover, 1, 37), TextureFactory.of(MyMod.iohub, 0X7F) @@ -301,7 +305,7 @@ public void run() { new AECover(BridgingData.class)); for (int i = 0; i <= 4; i++) { - GregTechAPI.registerCover( + registerCover( new ItemStack(MyMod.cover, 1, 90 + i), TextureFactory.of( MACHINE_CASINGS[1][0], @@ -578,7 +582,31 @@ public boolean supportsFluids() { */ } - public class DeferredGetterTexture extends GTCopiedBlockTextureRender { + + + private Method registerCover; + private void registerCover(ItemStack itemStack, ITexture of, CoverBehaviorBase circuitHolderCover) { + + if(registerCover==null){ + try { + registerCover=GregTechAPI.class.getDeclaredMethod("registerCover", ItemStack.class,ITexture.class,CoverBehaviorBase.class); + } catch (NoSuchMethodException e) {} + } + + if(registerCover==null){ + try { + registerCover=Class.forName("gregtech.api.covers.CoverRegistry").getDeclaredMethod("registerCover", ItemStack.class,ITexture.class,CoverBehaviorBase.class); + } catch (Exception e) {} + } + if(registerCover==null)throw new AssertionError("ERROR"); + try { + registerCover.invoke(null,itemStack, of,circuitHolderCover); + } catch (Exception e) { + throw new AssertionError(e); + } + } + + public class DeferredGetterTexture extends GTCopiedBlockTextureRender { private IIcon getIcon(int ordinalSide) {