diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java index d0179af..2655df2 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java @@ -1617,8 +1617,13 @@ public FluidStack getFluid() { @Override public int getFluidAmount() { +int ret=(int) Math.min(inner.getFluidAmount(),Integer.MAX_VALUE); - return (int) Math.min(inner.getFluidAmount(),Integer.MAX_VALUE); +if(ret>64){ + + System.out.println(ret); +} + return ret; } @Override diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java b/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java index 5afaf49..fb09f6a 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatch.java @@ -18,6 +18,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.StatCollector; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.event.ForgeEventFactory; @@ -67,6 +68,7 @@ import appeng.me.helpers.AENetworkProxy; import appeng.me.helpers.IGridProxyable; import appeng.util.Platform; +import appeng.util.item.AEItemStack; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.GTMod; @@ -89,1062 +91,1009 @@ import reobf.proghatches.main.Config; public class PatternDualInputHatch extends BufferedDualInputHatch implements ICraftingProvider, IGridProxyable, - ICustomNameObject, IInterfaceViewable, IPowerChannelState, IActionHost, IMultiplePatternPushable { + ICustomNameObject, IInterfaceViewable, IPowerChannelState, IActionHost, IMultiplePatternPushable { - - - - public PatternDualInputHatch(String mName, byte mTier, String[] mDescriptionArray, ITexture[][][] mTextures, - boolean mMultiFluid, int bufferNum) { - super(mName, mTier, mDescriptionArray, mTextures, mMultiFluid, bufferNum); + public PatternDualInputHatch(String mName, byte mTier, String[] mDescriptionArray, ITexture[][][] mTextures, + boolean mMultiFluid, int bufferNum) { + super(mName, mTier, mDescriptionArray, mTextures, mMultiFluid, bufferNum); - } + } - @Override - public int rows() { - return 4; - } + @Override + public int rows() { + return 4; + } - @Override - public int rowSize() { - return 9; - } + @Override + public int rowSize() { + return 9; + } - @Override - public IInventory getPatterns() { - return patternMapper; - } + @Override + public IInventory getPatterns() { + return patternMapper; + } - IInventory patternMapper = new IInventory() { + IInventory patternMapper = new IInventory() { - @Override - public int getSizeInventory() { + @Override + public int getSizeInventory() { - return pattern.length; - } + return pattern.length; + } - @Override - public ItemStack getStackInSlot(int slotIn) { + @Override + public ItemStack getStackInSlot(int slotIn) { - return pattern[slotIn]; - } + return pattern[slotIn]; + } - @Override - public ItemStack decrStackSize(int index, int count) { + @Override + public ItemStack decrStackSize(int index, int count) { - try { - if (pattern[index] != null) { - ItemStack itemstack; + try { + if (pattern[index] != null) { + ItemStack itemstack; - if (pattern[index].stackSize <= count) { - itemstack = pattern[index]; - pattern[index] = null; - this.markDirty(); - return itemstack; - } else { - itemstack = pattern[index].splitStack(count); + if (pattern[index].stackSize <= count) { + itemstack = pattern[index]; + pattern[index] = null; + this.markDirty(); + return itemstack; + } else { + itemstack = pattern[index].splitStack(count); - if (pattern[index].stackSize == 0) { - pattern[index] = null; - } + if (pattern[index].stackSize == 0) { + pattern[index] = null; + } - this.markDirty(); - return itemstack; - } - } else { - return null; - } - } finally { + this.markDirty(); + return itemstack; + } + } else { + return null; + } + } finally { - onPatternChange(); - } - } - - @Override - public ItemStack getStackInSlotOnClosing(int index) { - - return null; - } - - @Override - public void setInventorySlotContents(int index, ItemStack stack) { - pattern[index] = stack; - onPatternChange(); - } - - @Override - public String getInventoryName() { - - return ""; - } - - @Override - public boolean hasCustomInventoryName() { - - return false; - } + onPatternChange(); + } + } - // @Override - // public int stack + @Override + public ItemStack getStackInSlotOnClosing(int index) { - @Override - public void markDirty() { + return null; + } - } - - @Override - public boolean isUseableByPlayer(EntityPlayer player) { + @Override + public void setInventorySlotContents(int index, ItemStack stack) { + pattern[index] = stack; + onPatternChange(); + } - return true; - } + @Override + public String getInventoryName() { - @Override - public void openInventory() {} - - @Override - public void closeInventory() {} + return ""; + } - @Override - public boolean isItemValidForSlot(int index, ItemStack stack) { + @Override + public boolean hasCustomInventoryName() { - return true; - } + return false; + } - @Override - public int getInventoryStackLimit() { + // @Override + // public int stack - return 1; - } - }; + @Override + public void markDirty() { - @Override - public ITexture[] getTexturesActive(ITexture aBaseTexture) { + } - return new ITexture[] { aBaseTexture, - TextureFactory.of( - supportsFluids() ? BlockIcons.OVERLAY_ME_CRAFTING_INPUT_BUFFER - : BlockIcons.OVERLAY_ME_CRAFTING_INPUT_BUS) }; - - } - - @Override - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[] { aBaseTexture, - TextureFactory.of( - supportsFluids() ? BlockIcons.OVERLAY_ME_CRAFTING_INPUT_BUFFER - : BlockIcons.OVERLAY_ME_CRAFTING_INPUT_BUS) }; - - } - - public PatternDualInputHatch(int id, String name, String nameRegional, int tier, boolean mMultiFluid, int bufferNum, - boolean sf, String... optional) { - - super( - id, - name, - nameRegional, - tier, - mMultiFluid, - bufferNum, - (optional.length > 0 ? optional - : reobf.proghatches.main.Config.get( - "PDIH" + (sf ? "" : "B"), - ImmutableMap.of( - "bufferNum", - bufferNum, - "fluidSlots", - 16/* fluidSlots() */, /* - * "cap", - * format.format((int) (4000 * Math.pow(4, tier) - * / (mMultiFluid ? 4 : 1))), - */ - "mMultiFluid", - mMultiFluid, - "slots", - Math.min(16, (1 + tier) * (tier + 1))/* - * , "stacksize", - * (int) (64 * Math.pow(2, Math.max(tier - 3, 0))) - */)) - - )); - if (sf != supportsFluids()) { - - throw new AssertionError(); - } - } - - public int fluidSlots() { - return 16; - - } - - ItemStack[] pattern = new ItemStack[36]; - - ButtonWidget createRefundButton(IWidgetBuilder builder) { - - Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { - - PatternDualInputHatch.this.dirty = true; - try { - PatternDualInputHatch.this.refundAll(); - } catch (Exception e) { - - // e.printStackTrace(); - } - }) - .setPlayClickSound(true) - .setBackground(GTUITextures.BUTTON_STANDARD, GTUITextures.OVERLAY_BUTTON_EXPORT) - - .addTooltips(ImmutableList.of("Return all internally stored items back to AE")) - - .setPos(new Pos2d(getGUIWidth() - 18 - 3, 5 + 16 + 2)) - .setSize(16, 16); - return (ButtonWidget) button; - } - - MachineSource requestSource; - - private BaseActionSource getRequest() { - - if (requestSource == null) requestSource = new MachineSource((IActionHost) getBaseMetaTileEntity()); - return requestSource; - } - - private void refundAll() throws Exception { - markDirty(); - dirty = true; - BaseActionSource src = getRequest(); - IMEMonitor sg = getProxy().getStorage() - .getItemInventory(); - abstract class Inv { - - abstract ItemStack[] geti(); - - abstract FluidStack[] getf(); - } - Consumer consumer = inv -> { - try { - for (ItemStack itemStack : inv.geti()) { - if (itemStack == null || itemStack.stackSize == 0) continue; - IAEItemStack rest = Platform.poweredInsert( - getProxy().getEnergy(), - sg, - AEApi.instance() - .storage() - .createItemStack(itemStack), - src); - itemStack.stackSize = rest != null && rest.getStackSize() > 0 ? (int) rest.getStackSize() : 0; - } - IMEMonitor fsg = getProxy().getStorage() - .getFluidInventory(); - for (FluidStack fluidStack : inv.getf()) { - if (fluidStack == null || fluidStack.amount == 0) continue; - IAEFluidStack rest = Platform.poweredInsert( - getProxy().getEnergy(), - fsg, - AEApi.instance() - .storage() - .createFluidStack(fluidStack), - src); - fluidStack.amount=0; - } ; - } catch (Exception e) { - throw new RuntimeException(e); - } - }; - - inv0.stream() - .map(s -> new Inv() { - - @Override - ItemStack[] geti() { - return flat(s.mStoredItemInternal); - } - - @Override - FluidStack[] getf() { - return flat(s.mStoredFluidInternal); - } - }) - .forEach(consumer);; - consumer.accept(new Inv() { - - @Override - ItemStack[] geti() { - - return mInventory; - } - - @Override - FluidStack[] getf() { - - return Arrays.stream(mStoredFluid).map(s->s.getFluid()).toArray(FluidStack[]::new); - } - }); - - } - - @Override - public void addUIWidgets(Builder builder, UIBuildContext buildContext) { - buildContext.addSyncedWindow(88, this::createPatternWindow); - - builder.widget(createRefundButton(builder)); - builder.widget( - new ButtonWidget().setOnClick( - (clickData, widget) -> { - if (widget.getContext() - .isClient() == false) - widget.getContext() - .openSyncedWindow(88); - }) - .setPlayClickSound(true) - .setBackground(GTUITextures.BUTTON_STANDARD, GTUITextures.OVERLAY_BUTTON_PLUS_LARGE) - .addTooltips(ImmutableList.of(LangManager.translateToLocalFormatted("programmable_hatches.gt.pattern"))) - .setSize(16, 16) - // .setPos(10 + 16 * 9, 3 + 16 * 2) - .setPos(new Pos2d(getGUIWidth() - 18 - 3, 5 + 16 + 2 + 16 + 2))); - - super.addUIWidgets(builder, buildContext); - } - - protected ModularWindow createPatternWindow(final EntityPlayer player) { - final int WIDTH = 18 * 4 + 6; - final int HEIGHT = 18 * 9 + 6; - final int PARENT_WIDTH = getGUIWidth(); - final int PARENT_HEIGHT = getGUIHeight(); - - ModularWindow.Builder builder = ModularWindow.builder(WIDTH, HEIGHT); - builder.setBackground(GTUITextures.BACKGROUND_SINGLEBLOCK_DEFAULT); - builder.setGuiTint(getGUIColorization()); - builder.setDraggable(true); - builder.setPos( - (a, b) -> new Pos2d( - PARENT_WIDTH + b.getPos() - .getX(), - PARENT_HEIGHT * 0 + b.getPos() - .getY())); - MappingItemHandler shared_handler = new MappingItemHandler(pattern, 0, 36); - // use shared handler - // or shift clicking a pattern in pattern slot will just transfer it to another pattern slot - // instead of player inventory! - for (int i = 0; i < 36; i++) { - - BaseSlot bs; - - builder.widget(new SlotWidget(bs = new BaseSlot(shared_handler, i) - - ) { - - @Override - protected ItemStack getItemStackForRendering(Slot slotIn) { - ItemStack stack = slotIn.getStack(); - if (stack == null || !(stack.getItem() instanceof ItemEncodedPattern)) { - return stack; - } - ItemStack output = ((ItemEncodedPattern) stack.getItem()).getOutput(stack); - return output != null ? output : stack; - - } - }.setShiftClickPriority(-1) - .setFilter(itemStack -> itemStack.getItem() instanceof ICraftingPatternItem) - .setChangeListener(() -> { onPatternChange(); }) - .setPos((i % 4) * 18 + 3, (i / 4) * 18 + 3) - .setBackground(getGUITextureSet().getItemSlot(), GTUITextures.OVERLAY_SLOT_PATTERN_ME)); - - } - - return builder.build(); - } - - boolean needPatternSync; - - private void onPatternChange() { - if (!getBaseMetaTileEntity().isServerSide()) return; - // we do not refund 'cause it's impossible to trace the item - - needPatternSync = true; - } - - @Override - public void gridChanged() { - needPatternSync = true; - } - - @Override - public boolean canExtractItem(int aIndex, ItemStack aStack, int ordinalSide) { - - return false; - } - - @Override - public boolean canInsertItem(int aIndex, ItemStack aStack, int ordinalSide) { - - return false; - } - - @Override - public boolean canDrain(ForgeDirection side, Fluid aFluid) { - - return false; - } - - @Override - public boolean canFill(ForgeDirection side, Fluid aFluid) { - - return false; - } - - public class Inst extends PatternDualInputHatch { - - public Inst(String mName, byte mTier, String[] mDescriptionArray, ITexture[][][] mTextures, boolean mMultiFluid, - int bufferNum) { - super(mName, mTier, mDescriptionArray, mTextures, mMultiFluid, bufferNum); - } - - @Override - public boolean supportsFluids() { - return PatternDualInputHatch.this.supportsFluids(); - } - - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - - return new Inst(mName, mTier, mDescriptionArray, mTextures, mMultiFluid, bufferNum); - } - - @Override - public void initTierBasedField() { - if (supportsFluids()) super.initTierBasedField(); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - if (aNBT.hasKey("x") == false) return; - additionalConnection = aNBT.getBoolean("additionalConnection"); - NBTTagCompound tag = aNBT.getCompoundTag("patternSlots"); - if (tag != null) for (int i = 0; i < pattern.length; i++) { - pattern[i] = Optional.ofNullable(tag.getCompoundTag("i" + i)) - .map(ItemStack::loadItemStackFromNBT) - .orElse(null); - } - customName = aNBT.getString("customName"); - - getProxy().readFromNBT(aNBT); - - super.loadNBTData(aNBT); - updateValidGridProxySides(); - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setBoolean("additionalConnection", additionalConnection); - NBTTagCompound tag = new NBTTagCompound();// aNBT.getCompoundTag("patternSlots"); - - for (int i = 0; i < pattern.length; i++) { - final int ii = i; - Optional.ofNullable(pattern[i]) - .map(s -> s.writeToNBT(new NBTTagCompound())) - .ifPresent(s -> tag.setTag("i" + ii, s)); - } - aNBT.setTag("patternSlots", tag); - Optional.ofNullable(customName) - .ifPresent(s -> aNBT.setString("customName", s)); - getProxy().writeToNBT(aNBT); - - super.saveNBTData(aNBT); - } - - private void clearInv() { - - for (int i = 0; i < 16; i++) mInventory[i] = null; - for (int i = 0; i < this.fluidSlots(); i++) mStoredFluid[i].setFluid(null);; - - } - - private boolean postMEPatternChange() { - // don't post until it's active - if (!getProxy().isActive()) return false; - try { - getProxy().getGrid() - .postEvent(new MENetworkCraftingPatternChange(this, getProxy().getNode())); - } catch (GridAccessException ignored) { - return false; - } - return true; - } - - long lastSync; - - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - super.onPostTick(aBaseMetaTileEntity, aTimer); - - if (getBaseMetaTileEntity().isServerSide()) { - if (needPatternSync && aTimer > lastSync + 100) { - needPatternSync = !postMEPatternChange(); - lastSync = aTimer; - } - if (aTimer % 20 == 0) { - getBaseMetaTileEntity().setActive(isActive()); - } - } - } - - @Override - public int getInventoryStackLimit() { - - return Integer.MAX_VALUE; - } - - public boolean skipActiveCheck; - - @Override - public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) { - if (!isActive() && !skipActiveCheck) return false; - if (!isEmpty()) return false; - if (!supportsFluids()) { - for (int i = 0; i < table.getSizeInventory(); ++i) { - ItemStack itemStack = table.getStackInSlot(i); - if (itemStack == null) continue; - if (itemStack.getItem() instanceof ItemFluidPacket) return false; - } - } - - int items = 0; - int fluids = 0; - int size = table.getSizeInventory(); - for (int i = 0; i < size; i++) { - ItemStack itemStack = table.getStackInSlot(i); - if (itemStack == null) continue; - if (itemStack.getItem() instanceof ItemFluidPacket) { - fluids++; - if (fluids > this.fluidSlots()) { - clearInv(); - return false; - } - - mStoredFluid[fluids - 1].setFluidDirect(ItemFluidPacket.getFluidStack(itemStack)); - - } else { - items++; - if (items > 16) { - clearInv(); - return false; - } - mInventory[items - 1] = itemStack; - - } - } - markDirty(); - dirty = true; - // inv0.recordRecipeOrClassify(this.mStoredFluid, mInventory) - // classify(); - - /* - * for (DualInvBuffer inv0 : this.sortByEmpty()) { - * if (inv0.full() == false) - * if(inv0.recordRecipeOrClassify(this.mStoredFluid, mInventory)|| - * inv0.classify(this.mStoredFluid, mInventory,true))break; - * } - */ - - /* - * Integer check = detailmap.get(patternDetails); - * if(check==null){ - * currentID++; - * detailmap.put(patternDetails,currentID ); - * check=currentID; - * } - */ - - DualInvBuffer theBuffer = /* ((BufferedDualInputHatch) master). */classifyForce(); - if(theBuffer!=null){ - recordRecipe(theBuffer);theBuffer.onChange(); - } - justHadNewItems = true; - return true; - } - - private boolean isEmpty() { - for (ItemStack is : mInventory) { - if (is != null && is.stackSize > 0) return false; - } - for (FluidTank is : mStoredFluid) { - if (is.getFluidAmount() > 0) return false; - } - return true; - } - - @Override - public boolean isBusy() { - return !isEmpty(); - } - - @Override - public IGridNode getGridNode(ForgeDirection dir) { - return getProxy().getNode(); - } - - private AENetworkProxy gridProxy; - - @Override - public AENetworkProxy getProxy() { - if (gridProxy == null) { - gridProxy = new AENetworkProxy( - this, - "proxy", - new ItemStack( - GregTechAPI.sBlockMachines, - 1, - this.getBaseMetaTileEntity() - .getMetaTileID()), - true); - gridProxy.setFlags(GridFlags.REQUIRE_CHANNEL); - updateValidGridProxySides(); - if (getBaseMetaTileEntity().getWorld() != null) gridProxy.setOwner( - getBaseMetaTileEntity().getWorld() - .getPlayerEntityByName(getBaseMetaTileEntity().getOwnerName())); - } - - return this.gridProxy; - } - - @Override - public void securityBreak() { - // no op - } - - @Override - public String getName() { - - if (hasCustomName()) { - return getCustomName(); - } - StringBuilder name = new StringBuilder(); - if (getCrafterIcon() != null) { - name.append(getCrafterIcon().getDisplayName()); - } else { - name.append(getLocalName());// getinventoryname() - } - - /* - * if (mInventory[SLOT_CIRCUIT] != null) { - * name.append(" - "); - * name.append(mInventory[SLOT_CIRCUIT].getItemDamage()); - * } - */ - - for (ItemStack is : this.shared.getDisplayItems()) { - name.append(" - "); - - if (is.getItem() != GTUtility.getIntegratedCircuit(0) - .getItem()) { - name.append(is.getDisplayName()); - if (is.getItemDamage() > 0) { - name.append("@" + is.getItemDamage()); - } - } else { - name.append(is.getItemDamage()); - } - - // if(is.stackSize>0){name.append("*"+is.stackSize);} - } - - for (FluidStack is : this.shared.getDisplayFluid()) { - name.append(" - "); - name.append(is.getLocalizedName()); - // if(is.amount>0){name.append("*"+is.amount);} - } - - return name.toString(); - } - - @Override - public TileEntity getTileEntity() { - return (TileEntity) getBaseMetaTileEntity(); - } - - @Override - public boolean shouldDisplay() { - - return true; - } - - String customName; - private boolean additionalConnection; - - @Override - public String getCustomName() { - - return customName; - } - - @Override - public boolean hasCustomName() { - - return customName != null && (!customName.equals("")); - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side, - float aX, float aY, float aZ) { - final ItemStack is = aPlayer.inventory.getCurrentItem(); - if (is != null && is.getItem() instanceof ToolQuartzCuttingKnife) { - if (ForgeEventFactory.onItemUseStart(aPlayer, is, 1) <= 0) return false; - IGregTechTileEntity te = getBaseMetaTileEntity(); - aPlayer.openGui( - AppEng.instance(), - GuiBridge.GUI_RENAMER.ordinal() << 5 | (side.ordinal()), - te.getWorld(), - te.getXCoord(), - te.getYCoord(), - te.getZCoord()); - return true; - } - return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ); - } - - @Override - public void setCustomName(String name) { - customName = name; - - } - - @Override - public DimensionalCoord getLocation() { - - return new DimensionalCoord(getTileEntity()); - } - - @Override - public boolean isActive() { - return getProxy() != null && getProxy().isActive(); - } - - ItemStack[] patternItemCache = new ItemStack[36]; - ICraftingPatternDetails[] patternDetailCache = new ICraftingPatternDetails[36]; - - @Override - public void provideCrafting(ICraftingProviderHelper craftingTracker) { - if (!isActive()) return; - - for (int index = 0; index < pattern.length; index++) { - ItemStack slot = pattern[index]; - - if (slot == null) { - patternItemCache[index] = null; - patternDetailCache[index] = null; - continue; - } - - if (patternItemCache[index] == pattern[index]) {// just compare object id - craftingTracker.addCraftingOption(this, patternDetailCache[index]); - continue; - } - - ICraftingPatternDetails details = null; - try { - details = ((ICraftingPatternItem) slot.getItem()).getPatternForItem( - slot, - this.getBaseMetaTileEntity() - .getWorld()); - } catch (Exception e) {} - if (details == null) { - GTMod.GT_FML_LOGGER.warn( - "Found an invalid pattern at " + getBaseMetaTileEntity().getCoords() - + " in dim " - + getBaseMetaTileEntity().getWorld().provider.dimensionId); - continue; - } - patternItemCache[index] = pattern[index]; - patternDetailCache[index] = details; - craftingTracker.addCraftingOption(this, details); - } - - } - - @Override - public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { - super.onFirstTick(aBaseMetaTileEntity); - getProxy().onReady(); - } - - @Override - public AECableType getCableConnectionType(ForgeDirection forgeDirection) { - return isOutputFacing(forgeDirection) ? AECableType.SMART : AECableType.NONE; - } - - private void updateValidGridProxySides() { - if (additionalConnection) { - getProxy().setValidSides(EnumSet.complementOf(EnumSet.of(ForgeDirection.UNKNOWN))); - } else { - getProxy().setValidSides(EnumSet.of(getBaseMetaTileEntity().getFrontFacing())); - } - // getProxy().setValidSides(EnumSet.of(getBaseMetaTileEntity().getFrontFacing())); - - } - - @Override - public void onFacingChange() { - updateValidGridProxySides(); - } - - @Override - public boolean isPowered() { - return getProxy() != null && getProxy().isPowered(); - } - - @Override - public ItemStack getCrafterIcon() { - ItemStack is = this.getMachineCraftingIcon(); - return is == null ? new ItemStack(GregTechAPI.sBlockMachines, 1, getBaseMetaTileEntity().getMetaTileID()) : is; - } - - @Override - public void onBlockDestroyed() { - try { - refundAll(); - } catch (Exception e) { - e.printStackTrace(); - } - super.onBlockDestroyed(); - - IGregTechTileEntity te = this.getBaseMetaTileEntity(); - World aWorld = te.getWorld(); - int aX = te.getXCoord(); - short aY = te.getYCoord(); - int aZ = te.getZCoord(); - - for (int i = 0; i < pattern.length; i++) { - final ItemStack tItem = pattern[i]; - if ((tItem != null) && (tItem.stackSize > 0)) { - final EntityItem tItemEntity = new EntityItem( - aWorld, - aX + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, - aY + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, - aZ + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, - new ItemStack(tItem.getItem(), tItem.stackSize, tItem.getItemDamage())); - if (tItem.hasTagCompound()) { - tItemEntity.getEntityItem() - .setTagCompound( - (NBTTagCompound) tItem.getTagCompound() - .copy()); - } - tItemEntity.motionX = (XSTR_INSTANCE.nextGaussian() * 0.05D); - tItemEntity.motionY = (XSTR_INSTANCE.nextGaussian() * 0.25D); - tItemEntity.motionZ = (XSTR_INSTANCE.nextGaussian() * 0.05D); - aWorld.spawnEntityInWorld(tItemEntity); - tItem.stackSize = 0; - pattern[i] = null; - } - } - } - - public long fluidLimit() { - - return Long.MAX_VALUE; - } - - public long itemLimit() { - - return Long.MAX_VALUE; - } - - boolean createInsertion() { - return false; - } - - boolean showFluidLimit() { - - return false; - } - - @Override - public int getInventoryFluidLimit() { - return Integer.MAX_VALUE; - } - - @Override - public boolean onWireCutterRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer, - float aX, float aY, float aZ) { - additionalConnection = !additionalConnection; - updateValidGridProxySides(); - aPlayer.addChatComponentMessage( - new ChatComponentTranslation("GT5U.hatch.additionalConnection." + additionalConnection)); - return true; - } - - public Net getNetwork() { - - return new Net( - this.getGridNode(ForgeDirection.UP) - .getGrid(), - this); - } - - @Override - public IGridNode getActionableNode() { - - return this.getGridNode(ForgeDirection.UP); - } - - public Object getTile() { - return this.getBaseMetaTileEntity(); - } - - @Override - public boolean allowsPatternOptimization() { - // TODO Auto-generated method stub - return IInterfaceViewable.super.allowsPatternOptimization(); - } - - @Override - public int[] pushPatternMulti(ICraftingPatternDetails patternDetails, InventoryCrafting table, int maxTodo) { - if (Config.fastPatternDualInput == false) return AZERO; - if (maxTodo <= 0) return AZERO; - if (!isActive() && !skipActiveCheck) return AZERO; - if (!isEmpty()) return AZERO; - if (!supportsFluids()) { - for (int i = 0; i < table.getSizeInventory(); ++i) { - ItemStack itemStack = table.getStackInSlot(i); - if (itemStack == null) continue; - if (itemStack.getItem() instanceof ItemFluidPacket) return AZERO; - } - } - - int items = 0; - int fluids = 0; - int size = table.getSizeInventory(); - for (int i = 0; i < size; i++) { - ItemStack itemStack = table.getStackInSlot(i); - if (itemStack == null) continue; - if (itemStack.getItem() instanceof ItemFluidPacket) { - fluids++; - if (fluids > this.fluidSlots()) { - clearInv(); - return AZERO; - } - - mStoredFluid[fluids - 1].setFluidDirect(ItemFluidPacket.getFluidStack(itemStack)); - - } else { - items++; - if (items > 16) { - clearInv(); - return AZERO; - } - mInventory[items - 1] = itemStack; - - } - } - markDirty(); - dirty = true; - // classify(); - int suc = 0; - - // DualInvBuffer theBuffer=classifyForce(); - - /* - * Integer check = detailmap.get(patternDetails); - * if(check==null){ - * currentID++; - * detailmap.put(patternDetails,currentID ); - * check=currentID; - * } - */ - - DualInvBuffer theBuffer = /* ((BufferedDualInputHatch) master). */classifyForce(); - if(theBuffer!=null) - recordRecipe(theBuffer); - - // if(theBuffer!=null){ - suc++; - maxTodo--; - // } - /* - * for (DualInvBuffer inv0 : this.sortByEmpty()) { - * if (inv0.full() == false) - * if(inv0.recordRecipeOrClassify(this.mStoredFluid, mInventory)|| - * inv0.classify(this.mStoredFluid, mInventory, true) - * ){ - * theBuffer=inv0;suc++;maxTodo--; - * break;} - * } - */ - if (theBuffer != null) {// if succeeded, it's safe to simply add to stacksize to push more patterns - int todo = Math.min(theBuffer.space() - /* - * space() will return correct result here - * it assumes item/fluid type is correct - */ - , maxTodo); - - if (todo > 0) { - for (int ix = 0; ix < theBuffer.i; ix++) { - if (theBuffer.mStoredItemInternalSingle[ix] != null) { - if (theBuffer.mStoredItemInternal[ix] == null) { - theBuffer.mStoredItemInternal[ix] = ItemStackG.neo(theBuffer.mStoredItemInternalSingle[ix].copy()); - theBuffer.mStoredItemInternal[ix].stackSize(0);// circuit? - } - theBuffer.mStoredItemInternal[ix].stackSizeInc( theBuffer.mStoredItemInternalSingle[ix].stackSize - * todo); - } - } - - for (int ix = 0; ix < theBuffer.f; ix++) { - if (theBuffer.mStoredFluidInternalSingle[ix].getFluidAmount() > 0) { - if (theBuffer.mStoredFluidInternal[ix].getFluidAmount() <= 0) { - theBuffer.mStoredFluidInternal[ix].setFluid( - theBuffer.mStoredFluidInternalSingle[ix].getFluid() - .copy()); - theBuffer.mStoredFluidInternal[ix].getFluid().amount = 0; - } - theBuffer.mStoredFluidInternal[ix].getFluid().amount += theBuffer.mStoredFluidInternalSingle[ix] - .getFluidAmount() * todo; - } - } - suc += todo; - } - theBuffer.onChange(); - } - - saved += suc; - - justHadNewItems = true; - return new int[]{suc}; - } - - long saved; - - @SideOnly(Side.CLIENT) - @Override - public void getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, - IWailaConfigHandler config) { - - super.getWailaBody(itemStack, currenttip, accessor, config); - if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { - currenttip.add("Saved pushPattern calls since chunk load:" + - - accessor.getNBTData() - .getLong("saved")); - } - - } - - @Override - public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y, - int z) { - - super.getWailaNBTData(player, tile, tag, world, x, y, z); - tag.setLong("saved", saved); - } - - @Override - public boolean isInfBuffer() { - - return true; - } + @Override + public boolean isUseableByPlayer(EntityPlayer player) { + + return true; + } + + @Override + public void openInventory() { + } + + @Override + public void closeInventory() { + } + + @Override + public boolean isItemValidForSlot(int index, ItemStack stack) { + + return true; + } + + @Override + public int getInventoryStackLimit() { + + return 1; + } + }; + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + + return new ITexture[] { aBaseTexture, TextureFactory.of(supportsFluids() + ? BlockIcons.OVERLAY_ME_CRAFTING_INPUT_BUFFER : BlockIcons.OVERLAY_ME_CRAFTING_INPUT_BUS) }; + + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, TextureFactory.of(supportsFluids() + ? BlockIcons.OVERLAY_ME_CRAFTING_INPUT_BUFFER : BlockIcons.OVERLAY_ME_CRAFTING_INPUT_BUS) }; + + } + + public PatternDualInputHatch(int id, String name, String nameRegional, int tier, boolean mMultiFluid, int bufferNum, + boolean sf, String... optional) { + + super(id, name, nameRegional, tier, mMultiFluid, bufferNum, (optional.length > 0 ? optional + : reobf.proghatches.main.Config.get("PDIH" + (sf ? "" : "B"), ImmutableMap.of("bufferNum", bufferNum, + "fluidSlots", + 16/* fluidSlots() */, /* + * "cap", format.format((int) + * (4000 * Math.pow(4, tier) / + * (mMultiFluid ? 4 : 1))), + */ + "mMultiFluid", mMultiFluid, "slots", Math.min(16, (1 + tier) * (tier + + 1))/* + * , "stacksize", (int) (64 * + * Math.pow(2, Math.max(tier - 3, 0))) + */)) + + )); + if (sf != supportsFluids()) { + + throw new AssertionError(); + } + } + + public int fluidSlots() { + return 16; + + } + + ItemStack[] pattern = new ItemStack[36]; + + ButtonWidget createRefundButton(IWidgetBuilder builder) { + + Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { + + PatternDualInputHatch.this.dirty = true; + try { + PatternDualInputHatch.this.refundAll(); + } catch (Exception e) { + + // e.printStackTrace(); + } + }).setPlayClickSound(true).setBackground(GTUITextures.BUTTON_STANDARD, GTUITextures.OVERLAY_BUTTON_EXPORT) + + .addTooltips(ImmutableList.of("Return all internally stored items back to AE")) + + .setPos(new Pos2d(getGUIWidth() - 18 - 3, 5 + 16 + 2)).setSize(16, 16); + return (ButtonWidget) button; + } + + MachineSource requestSource; + + private BaseActionSource getRequest() { + + if (requestSource == null) + requestSource = new MachineSource((IActionHost) getBaseMetaTileEntity()); + return requestSource; + } + + private void refundAll() throws Exception { + markDirty(); + dirty = true; + BaseActionSource src = getRequest(); + IMEMonitor sg = getProxy().getStorage().getItemInventory(); + abstract class Inv { + + abstract ItemStack[] geti(); + + abstract FluidStack[] getf(); + } + Consumer consumer = inv -> { + try { + for (ItemStack itemStack : inv.geti()) { + if (itemStack == null || itemStack.stackSize == 0) + continue; + IAEItemStack rest = Platform.poweredInsert(getProxy().getEnergy(), sg, + AEApi.instance().storage().createItemStack(itemStack), src); + itemStack.stackSize = rest != null && rest.getStackSize() > 0 ? (int) rest.getStackSize() : 0; + } + IMEMonitor fsg = getProxy().getStorage().getFluidInventory(); + for (FluidStack fluidStack : inv.getf()) { + if (fluidStack == null || fluidStack.amount == 0) + continue; + IAEFluidStack rest = Platform.poweredInsert(getProxy().getEnergy(), fsg, + AEApi.instance().storage().createFluidStack(fluidStack), src); + fluidStack.amount = 0; + } + ; + } catch (Exception e) { + throw new RuntimeException(e); + } + }; + + inv0.stream().map(s -> new Inv() { + + @Override + ItemStack[] geti() { + return flat(s.mStoredItemInternal); + } + + @Override + FluidStack[] getf() { + return flat(s.mStoredFluidInternal); + } + }).forEach(consumer); + ; + consumer.accept(new Inv() { + + @Override + ItemStack[] geti() { + + return mInventory; + } + + @Override + FluidStack[] getf() { + + return Arrays.stream(mStoredFluid).map(s -> s.getFluid()).toArray(FluidStack[]::new); + } + }); + + } + + @Override + public void addUIWidgets(Builder builder, UIBuildContext buildContext) { + buildContext.addSyncedWindow(88, this::createPatternWindow); + + builder.widget(createRefundButton(builder)); + builder.widget(new ButtonWidget().setOnClick((clickData, widget) -> { + if (widget.getContext().isClient() == false) + widget.getContext().openSyncedWindow(88); + }).setPlayClickSound(true).setBackground(GTUITextures.BUTTON_STANDARD, GTUITextures.OVERLAY_BUTTON_PLUS_LARGE) + .addTooltips(ImmutableList.of(LangManager.translateToLocalFormatted("programmable_hatches.gt.pattern"))) + .setSize(16, 16) + // .setPos(10 + 16 * 9, 3 + 16 * 2) + .setPos(new Pos2d(getGUIWidth() - 18 - 3, 5 + 16 + 2 + 16 + 2))); + + super.addUIWidgets(builder, buildContext); + } + + protected ModularWindow createPatternWindow(final EntityPlayer player) { + final int WIDTH = 18 * 4 + 6; + final int HEIGHT = 18 * 9 + 6; + final int PARENT_WIDTH = getGUIWidth(); + final int PARENT_HEIGHT = getGUIHeight(); + + ModularWindow.Builder builder = ModularWindow.builder(WIDTH, HEIGHT); + builder.setBackground(GTUITextures.BACKGROUND_SINGLEBLOCK_DEFAULT); + builder.setGuiTint(getGUIColorization()); + builder.setDraggable(true); + builder.setPos((a, b) -> new Pos2d(PARENT_WIDTH + b.getPos().getX(), PARENT_HEIGHT * 0 + b.getPos().getY())); + MappingItemHandler shared_handler = new MappingItemHandler(pattern, 0, 36); + // use shared handler + // or shift clicking a pattern in pattern slot will just transfer it to + // another pattern slot + // instead of player inventory! + for (int i = 0; i < 36; i++) { + + BaseSlot bs; + + builder.widget(new SlotWidget(bs = new BaseSlot(shared_handler, i) + + ) { + + @Override + protected ItemStack getItemStackForRendering(Slot slotIn) { + ItemStack stack = slotIn.getStack(); + if (stack == null || !(stack.getItem() instanceof ItemEncodedPattern)) { + return stack; + } + ItemStack output = ((ItemEncodedPattern) stack.getItem()).getOutput(stack); + return output != null ? output : stack; + + } + }.setShiftClickPriority(-1).setFilter(itemStack -> itemStack.getItem() instanceof ICraftingPatternItem) + .setChangeListener(() -> { + onPatternChange(); + }).setPos((i % 4) * 18 + 3, (i / 4) * 18 + 3) + .setBackground(getGUITextureSet().getItemSlot(), GTUITextures.OVERLAY_SLOT_PATTERN_ME)); + + } + + return builder.build(); + } + + boolean needPatternSync; + + private void onPatternChange() { + if (!getBaseMetaTileEntity().isServerSide()) + return; + // we do not refund 'cause it's impossible to trace the item + + needPatternSync = true; + } + + @Override + public void gridChanged() { + needPatternSync = true; + } + + @Override + public boolean canExtractItem(int aIndex, ItemStack aStack, int ordinalSide) { + + return false; + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int ordinalSide) { + + return false; + } + + @Override + public boolean canDrain(ForgeDirection side, Fluid aFluid) { + + return false; + } + + @Override + public boolean canFill(ForgeDirection side, Fluid aFluid) { + + return false; + } + + public class Inst extends PatternDualInputHatch { + + public Inst(String mName, byte mTier, String[] mDescriptionArray, ITexture[][][] mTextures, boolean mMultiFluid, + int bufferNum) { + super(mName, mTier, mDescriptionArray, mTextures, mMultiFluid, bufferNum); + } + + @Override + public boolean supportsFluids() { + return PatternDualInputHatch.this.supportsFluids(); + } + + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + + return new Inst(mName, mTier, mDescriptionArray, mTextures, mMultiFluid, bufferNum); + } + + @Override + public void initTierBasedField() { + if (supportsFluids()) + super.initTierBasedField(); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + if (aNBT.hasKey("x") == false) + return; + additionalConnection = aNBT.getBoolean("additionalConnection"); + NBTTagCompound tag = aNBT.getCompoundTag("patternSlots"); + if (tag != null) + for (int i = 0; i < pattern.length; i++) { + pattern[i] = Optional.ofNullable(tag.getCompoundTag("i" + i)).map(ItemStack::loadItemStackFromNBT) + .orElse(null); + } + customName = aNBT.getString("customName"); + + getProxy().readFromNBT(aNBT); + saved = aNBT.getLong("saved"); + super.loadNBTData(aNBT); + updateValidGridProxySides(); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("additionalConnection", additionalConnection); + NBTTagCompound tag = new NBTTagCompound();// aNBT.getCompoundTag("patternSlots"); + + for (int i = 0; i < pattern.length; i++) { + final int ii = i; + Optional.ofNullable(pattern[i]).map(s -> s.writeToNBT(new NBTTagCompound())) + .ifPresent(s -> tag.setTag("i" + ii, s)); + } + aNBT.setTag("patternSlots", tag); + Optional.ofNullable(customName).ifPresent(s -> aNBT.setString("customName", s)); + getProxy().writeToNBT(aNBT); + aNBT.setLong("saved", saved); + super.saveNBTData(aNBT); + } + + private void clearInv() { + + for (int i = 0; i < 16; i++) + mInventory[i] = null; + for (int i = 0; i < this.fluidSlots(); i++) + mStoredFluid[i].setFluid(null); + ; + + } + + private boolean postMEPatternChange() { + // don't post until it's active + if (!getProxy().isActive()) + return false; + try { + getProxy().getGrid().postEvent(new MENetworkCraftingPatternChange(this, getProxy().getNode())); + } catch (GridAccessException ignored) { + return false; + } + return true; + } + + long lastSync; + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + super.onPostTick(aBaseMetaTileEntity, aTimer); + + if (getBaseMetaTileEntity().isServerSide()) { + if (needPatternSync && aTimer > lastSync + 100) { + needPatternSync = !postMEPatternChange(); + lastSync = aTimer; + } + if (aTimer % 20 == 0) { + getBaseMetaTileEntity().setActive(isActive()); + } + } + } + + @Override + public int getInventoryStackLimit() { + + return Integer.MAX_VALUE; + } + + public boolean skipActiveCheck; + + @Override + public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) { + if (!isActive() && !skipActiveCheck) + return false; + if (!isEmpty()) + return false; + if (!supportsFluids()) { + for (int i = 0; i < table.getSizeInventory(); ++i) { + ItemStack itemStack = table.getStackInSlot(i); + if (itemStack == null) + continue; + if (itemStack.getItem() instanceof ItemFluidPacket) + return false; + } + } + + int items = 0; + int fluids = 0; + int size = table.getSizeInventory(); + for (int i = 0; i < size; i++) { + ItemStack itemStack = table.getStackInSlot(i); + if (itemStack == null) + continue; + if (itemStack.getItem() instanceof ItemFluidPacket) { + fluids++; + if (fluids > this.fluidSlots()) { + clearInv(); + return false; + } + + mStoredFluid[fluids - 1].setFluidDirect(ItemFluidPacket.getFluidStack(itemStack)); + + } else { + items++; + if (items > 16) { + clearInv(); + return false; + } + mInventory[items - 1] = itemStack; + + } + } + markDirty(); + dirty = true; + // inv0.recordRecipeOrClassify(this.mStoredFluid, mInventory) + // classify(); + + /* + * for (DualInvBuffer inv0 : this.sortByEmpty()) { if (inv0.full() == + * false) if(inv0.recordRecipeOrClassify(this.mStoredFluid, + * mInventory)|| inv0.classify(this.mStoredFluid, + * mInventory,true))break; } + */ + + /* + * Integer check = detailmap.get(patternDetails); if(check==null){ + * currentID++; detailmap.put(patternDetails,currentID ); + * check=currentID; } + */ + + DualInvBuffer theBuffer = /* ((BufferedDualInputHatch) master). */classifyForce(); + if (theBuffer != null) { + recordRecipe(theBuffer); + theBuffer.onChange(); + } + justHadNewItems = true; + return true; + } + + private boolean isEmpty() { + for (ItemStack is : mInventory) { + if (is != null && is.stackSize > 0) + return false; + } + for (FluidTank is : mStoredFluid) { + if (is.getFluidAmount() > 0) + return false; + } + return true; + } + + @Override + public boolean isBusy() { + return !isEmpty(); + } + + @Override + public IGridNode getGridNode(ForgeDirection dir) { + return getProxy().getNode(); + } + + private AENetworkProxy gridProxy; + + @Override + public AENetworkProxy getProxy() { + if (gridProxy == null) { + gridProxy = new AENetworkProxy(this, "proxy", + new ItemStack(GregTechAPI.sBlockMachines, 1, this.getBaseMetaTileEntity().getMetaTileID()), true); + gridProxy.setFlags(GridFlags.REQUIRE_CHANNEL); + updateValidGridProxySides(); + if (getBaseMetaTileEntity().getWorld() != null) + gridProxy.setOwner(getBaseMetaTileEntity().getWorld() + .getPlayerEntityByName(getBaseMetaTileEntity().getOwnerName())); + } + + return this.gridProxy; + } + + @Override + public void securityBreak() { + // no op + } + + @Override + public String getName() { + + if (hasCustomName()) { + return getCustomName(); + } + StringBuilder name = new StringBuilder(); + if (getCrafterIcon() != null) { + name.append(getCrafterIcon().getDisplayName()); + } else { + name.append(getLocalName());// getinventoryname() + } + + /* + * if (mInventory[SLOT_CIRCUIT] != null) { name.append(" - "); + * name.append(mInventory[SLOT_CIRCUIT].getItemDamage()); } + */ + + for (ItemStack is : this.shared.getDisplayItems()) { + name.append(" - "); + + if (is.getItem() != GTUtility.getIntegratedCircuit(0).getItem()) { + name.append(is.getDisplayName()); + if (is.getItemDamage() > 0) { + name.append("@" + is.getItemDamage()); + } + } else { + name.append(is.getItemDamage()); + } + + // if(is.stackSize>0){name.append("*"+is.stackSize);} + } + + for (FluidStack is : this.shared.getDisplayFluid()) { + name.append(" - "); + name.append(is.getLocalizedName()); + // if(is.amount>0){name.append("*"+is.amount);} + } + + return name.toString(); + } + + @Override + public TileEntity getTileEntity() { + return (TileEntity) getBaseMetaTileEntity(); + } + + @Override + public boolean shouldDisplay() { + + return true; + } + + String customName; + private boolean additionalConnection; + + @Override + public String getCustomName() { + + return customName; + } + + @Override + public boolean hasCustomName() { + + return customName != null && (!customName.equals("")); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side, + float aX, float aY, float aZ) { + final ItemStack is = aPlayer.inventory.getCurrentItem(); + if (is != null && is.getItem() instanceof ToolQuartzCuttingKnife) { + if (ForgeEventFactory.onItemUseStart(aPlayer, is, 1) <= 0) + return false; + IGregTechTileEntity te = getBaseMetaTileEntity(); + aPlayer.openGui(AppEng.instance(), GuiBridge.GUI_RENAMER.ordinal() << 5 | (side.ordinal()), te.getWorld(), + te.getXCoord(), te.getYCoord(), te.getZCoord()); + return true; + } + return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ); + } + + @Override + public void setCustomName(String name) { + customName = name; + + } + + @Override + public DimensionalCoord getLocation() { + + return new DimensionalCoord(getTileEntity()); + } + + @Override + public boolean isActive() { + return getProxy() != null && getProxy().isActive(); + } + + ItemStack[] patternItemCache = new ItemStack[36]; + ICraftingPatternDetails[] patternDetailCache = new ICraftingPatternDetails[36]; + + @Override + public void provideCrafting(ICraftingProviderHelper craftingTracker) { + if (!isActive()) + return; + + for (int index = 0; index < pattern.length; index++) { + ItemStack slot = pattern[index]; + + if (slot == null) { + patternItemCache[index] = null; + patternDetailCache[index] = null; + continue; + } + + if (patternItemCache[index] == pattern[index]) {// just compare + // object id + craftingTracker.addCraftingOption(this, patternDetailCache[index]); + continue; + } + + ICraftingPatternDetails details = null; + try { + details = ((ICraftingPatternItem) slot.getItem()).getPatternForItem(slot, + this.getBaseMetaTileEntity().getWorld()); + } catch (Exception e) { + } + if (details == null) { + GTMod.GT_FML_LOGGER.warn("Found an invalid pattern at " + getBaseMetaTileEntity().getCoords() + + " in dim " + getBaseMetaTileEntity().getWorld().provider.dimensionId); + continue; + } + patternItemCache[index] = pattern[index]; + patternDetailCache[index] = details; + craftingTracker.addCraftingOption(this, details); + } + + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + getProxy().onReady(); + } + + @Override + public AECableType getCableConnectionType(ForgeDirection forgeDirection) { + return isOutputFacing(forgeDirection) ? AECableType.SMART : AECableType.NONE; + } + + private void updateValidGridProxySides() { + if (additionalConnection) { + getProxy().setValidSides(EnumSet.complementOf(EnumSet.of(ForgeDirection.UNKNOWN))); + } else { + getProxy().setValidSides(EnumSet.of(getBaseMetaTileEntity().getFrontFacing())); + } + // getProxy().setValidSides(EnumSet.of(getBaseMetaTileEntity().getFrontFacing())); + + } + + @Override + public void onFacingChange() { + updateValidGridProxySides(); + } + + @Override + public boolean isPowered() { + return getProxy() != null && getProxy().isPowered(); + } + + @Override + public ItemStack getCrafterIcon() { + ItemStack is = this.getMachineCraftingIcon(); + return is == null ? new ItemStack(GregTechAPI.sBlockMachines, 1, getBaseMetaTileEntity().getMetaTileID()) : is; + } + + @Override + public void onBlockDestroyed() { + try { + refundAll(); + } catch (Exception e) { + e.printStackTrace(); + } + super.onBlockDestroyed(); + + IGregTechTileEntity te = this.getBaseMetaTileEntity(); + World aWorld = te.getWorld(); + int aX = te.getXCoord(); + short aY = te.getYCoord(); + int aZ = te.getZCoord(); + + for (int i = 0; i < pattern.length; i++) { + final ItemStack tItem = pattern[i]; + if ((tItem != null) && (tItem.stackSize > 0)) { + final EntityItem tItemEntity = new EntityItem(aWorld, aX + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, + aY + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, aZ + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, + new ItemStack(tItem.getItem(), tItem.stackSize, tItem.getItemDamage())); + if (tItem.hasTagCompound()) { + tItemEntity.getEntityItem().setTagCompound((NBTTagCompound) tItem.getTagCompound().copy()); + } + tItemEntity.motionX = (XSTR_INSTANCE.nextGaussian() * 0.05D); + tItemEntity.motionY = (XSTR_INSTANCE.nextGaussian() * 0.25D); + tItemEntity.motionZ = (XSTR_INSTANCE.nextGaussian() * 0.05D); + aWorld.spawnEntityInWorld(tItemEntity); + tItem.stackSize = 0; + pattern[i] = null; + } + } + } + + public long fluidLimit() { + + return Long.MAX_VALUE; + } + + public long itemLimit() { + + return Long.MAX_VALUE; + } + + boolean createInsertion() { + return false; + } + + boolean showFluidLimit() { + + return false; + } + + @Override + public int getInventoryFluidLimit() { + return Integer.MAX_VALUE; + } + + @Override + public boolean onWireCutterRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer, + float aX, float aY, float aZ) { + additionalConnection = !additionalConnection; + updateValidGridProxySides(); + aPlayer.addChatComponentMessage( + new ChatComponentTranslation("GT5U.hatch.additionalConnection." + additionalConnection)); + return true; + } + + public Net getNetwork() { + + return new Net(this.getGridNode(ForgeDirection.UP).getGrid(), this); + } + + @Override + public IGridNode getActionableNode() { + + return this.getGridNode(ForgeDirection.UP); + } + + public Object getTile() { + return this.getBaseMetaTileEntity(); + } + + @Override + public boolean allowsPatternOptimization() { + // TODO Auto-generated method stub + return IInterfaceViewable.super.allowsPatternOptimization(); + } + + @Override + public int[] pushPatternMulti(ICraftingPatternDetails patternDetails, InventoryCrafting table, int maxTodo) { + if (Config.fastPatternDualInput == false) + return AZERO; + if (maxTodo <= 0) + return AZERO; + if (!isActive() && !skipActiveCheck) + return AZERO; + if (!isEmpty()) + return AZERO; + if (!supportsFluids()) { + for (int i = 0; i < table.getSizeInventory(); ++i) { + ItemStack itemStack = table.getStackInSlot(i); + if (itemStack == null) + continue; + if (itemStack.getItem() instanceof ItemFluidPacket) + return AZERO; + } + } + + int items = 0; + int fluids = 0; + int size = table.getSizeInventory(); + for (int i = 0; i < size; i++) { + ItemStack itemStack = table.getStackInSlot(i); + if (itemStack == null) + continue; + if (itemStack.getItem() instanceof ItemFluidPacket) { + fluids++; + if (fluids > this.fluidSlots()) { + clearInv(); + return AZERO; + } + + mStoredFluid[fluids - 1].setFluidDirect(ItemFluidPacket.getFluidStack(itemStack)); + + } else { + items++; + if (items > 16) { + clearInv(); + return AZERO; + } + mInventory[items - 1] = itemStack; + + } + } + markDirty(); + dirty = true; + // classify(); + int suc = 0; + + // DualInvBuffer theBuffer=classifyForce(); + + /* + * Integer check = detailmap.get(patternDetails); if(check==null){ + * currentID++; detailmap.put(patternDetails,currentID ); + * check=currentID; } + */ + + DualInvBuffer theBuffer = /* ((BufferedDualInputHatch) master). */classifyForce(); + if (theBuffer != null) + recordRecipe(theBuffer); + + // if(theBuffer!=null){ + suc++; + maxTodo--; + // } + /* + * for (DualInvBuffer inv0 : this.sortByEmpty()) { if (inv0.full() == + * false) if(inv0.recordRecipeOrClassify(this.mStoredFluid, + * mInventory)|| inv0.classify(this.mStoredFluid, mInventory, true) ){ + * theBuffer=inv0;suc++;maxTodo--; break;} } + */ + if (theBuffer != null) {// if succeeded, it's safe to simply add to + // stacksize to push more patterns + int todo = Math.min(theBuffer.space() + /* + * space() will return correct result here it assumes item/fluid + * type is correct + */ + , maxTodo); + + if (todo > 0) { + for (int ix = 0; ix < theBuffer.i; ix++) { + if (theBuffer.mStoredItemInternalSingle[ix] != null) { + if (theBuffer.mStoredItemInternal[ix] == null) { + theBuffer.mStoredItemInternal[ix] = ItemStackG + .neo(theBuffer.mStoredItemInternalSingle[ix].copy()); + theBuffer.mStoredItemInternal[ix].stackSize(0);// circuit? + } + theBuffer.mStoredItemInternal[ix] + .stackSizeInc(theBuffer.mStoredItemInternalSingle[ix].stackSize * todo); + } + } + + for (int ix = 0; ix < theBuffer.f; ix++) { + if (theBuffer.mStoredFluidInternalSingle[ix].getFluidAmount() > 0) { + if (theBuffer.mStoredFluidInternal[ix].getFluidAmount() <= 0) { + FluidStack zerof = theBuffer.mStoredFluidInternalSingle[ix].getFluid().copy(); + zerof.amount = 0; + theBuffer.mStoredFluidInternal[ix].setFluid(zerof); + + } + theBuffer.mStoredFluidInternal[ix].amountAcc ( theBuffer.mStoredFluidInternalSingle[ix] + .getFluidAmount() *1l* todo); + } + } + suc += todo; + } + theBuffer.onChange(); + } + + saved += suc; + + justHadNewItems = true; + return new int[] { suc }; + } + + long saved; + + @SideOnly(Side.CLIENT) + @Override + public void getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, + IWailaConfigHandler config) { + + super.getWailaBody(itemStack, currenttip, accessor, config); + if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { + + currenttip.add( + + StatCollector.translateToLocalFormatted("proghatch.saved.statistic", + accessor.getNBTData().getLong("saved"))); + } + + } + + @Override + public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y, + int z) { + + super.getWailaNBTData(player, tile, tag, world, x, y, z); + tag.setLong("saved", saved); + } + + @Override + public boolean isInfBuffer() { + + return true; + } } diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatchInventoryMappingSlave.java b/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatchInventoryMappingSlave.java index d13b97c..e24b268 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatchInventoryMappingSlave.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/PatternDualInputHatchInventoryMappingSlave.java @@ -97,7 +97,8 @@ public class PatternDualInputHatchInventoryMappingSlave 0) { if (theBuffer.mStoredFluidInternal[ix].getFluidAmount() <= 0) { - theBuffer.mStoredFluidInternal[ix].setFluid( - theBuffer.mStoredFluidInternalSingle[ix].getFluid() - .copy()); - theBuffer.mStoredFluidInternal[ix].getFluid().amount = 0; + FluidStack zerof = theBuffer.mStoredFluidInternalSingle[ix].getFluid().copy(); + zerof.amount = 0; + theBuffer.mStoredFluidInternal[ix].setFluid(zerof); + } - theBuffer.mStoredFluidInternal[ix] - .getFluid().amount += theBuffer.mStoredFluidInternalSingle[ix].getFluidAmount() - * todo; + theBuffer.mStoredFluidInternal[ix].amountAcc ( theBuffer.mStoredFluidInternalSingle[ix] + .getFluidAmount() *1l* todo); } } @@ -1174,7 +1174,11 @@ public int[] pushPatternMulti(ICraftingPatternDetails patternDetails, InventoryC if (master instanceof BufferedDualInputHatch) { ((BufferedDualInputHatch) master).justHadNewItems = true; } - + if (master instanceof PatternDualInputHatch) { + ((PatternDualInputHatch) master).saved+=suc; + } + + } return new int[]{suc}; diff --git a/src/main/java/reobf/proghatches/gt/metatileentity/bufferutil/FluidTankG.java b/src/main/java/reobf/proghatches/gt/metatileentity/bufferutil/FluidTankG.java index 97fea3b..7fb5751 100644 --- a/src/main/java/reobf/proghatches/gt/metatileentity/bufferutil/FluidTankG.java +++ b/src/main/java/reobf/proghatches/gt/metatileentity/bufferutil/FluidTankG.java @@ -22,7 +22,9 @@ public long getFluidAmount() { return arr.stream().mapToLong(s -> s.amount).sum(); } - +/** + * return value is readonly!!!! + * */ public FluidStack getFluid() { if (arr.size() > 0) { FluidStack f = arr.get(0).copy(); @@ -63,7 +65,7 @@ public NBTBase writeToNBT(NBTTagCompound nbtTagCompound) { } public void readFromNBT(NBTTagCompound compoundTag) { - + arr.clear(); FluidTank tk = new FluidTank(0); tk.readFromNBT(compoundTag); if (tk.getFluidAmount() > 0) @@ -201,6 +203,36 @@ public void fromAE(@Nonnull IAEFluidStack possible, int intmaxs) { + } + + public void amountAcc(long l) { + if (l==0) { + return; + } + long todo =l; + for (FluidStack is : arr) { + long cando = Math.min( + + Integer.MAX_VALUE + // 64 + + - is.amount, + todo); + todo -= cando; + is.amount += cando; + if (todo <= 0) + return ; + } + while(todo>0){ + int t=(int) Math.min(Integer.MAX_VALUE,todo); + todo-=t; + FluidStack i = arr.get(0).copy(); + i.amount = t; + arr.add(i); + } + + + } } diff --git a/src/main/resources/assets/proghatches/lang/en_US.lang b/src/main/resources/assets/proghatches/lang/en_US.lang index 74c75e0..48af284 100644 --- a/src/main/resources/assets/proghatches/lang/en_US.lang +++ b/src/main/resources/assets/proghatches/lang/en_US.lang @@ -769,4 +769,4 @@ hatch.dualinput.stocking.autopull.program=Auto consume Programming Circuit and s proghatch.stockingdual.exceedintmax=Actual pulled amount exceeds 2.1G, check tooltips for real amount! proghatch.stockingdual.intmax=Max pull amount (in int.max) proghatch.stockingdual.intmax.tooltips=Maximum amount allowed to pull in multiples of int.max(2.1G). Do not set to a large number especially when you has 9.2E item/fluid in storage. - +proghatch.saved.statistic=Saved pushPattern calls: %s diff --git a/src/main/resources/assets/proghatches/lang/zh_CN.lang b/src/main/resources/assets/proghatches/lang/zh_CN.lang index 315bec9..9a5d5ba 100644 --- a/src/main/resources/assets/proghatches/lang/zh_CN.lang +++ b/src/main/resources/assets/proghatches/lang/zh_CN.lang @@ -767,4 +767,4 @@ hatch.dualinput.stocking.autopull.program=自动消耗编程器电路设置虚 proghatch.stockingdual.exceedintmax=拉取数量超过2.1G, 查看tooltips获取真实数量! proghatch.stockingdual.intmax=最大拉取数量 (单位:int.max) proghatch.stockingdual.intmax.tooltips=最多能拉取int.max(2.1G)的几倍 不要设太大,尤其是当存储中有9.2E个物品时(比如无限水元件),否则可能会非常卡甚至损坏你的存档 - +proghatch.saved.statistic=优化掉的pushPattern调用次数: %s