diff --git a/dependencies.gradle b/dependencies.gradle index 7ad17d933..77ae25c63 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -2,7 +2,7 @@ dependencies { compile('com.github.GTNewHorizons:NotEnoughItems:2.2.17-GTNH:dev') - compile('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-92-GTNH:dev') + compile('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-108-GTNH:dev') compile('curse.maven:cofh-core-69162:2388751') compile('com.github.GTNewHorizons:ExtraCells2:2.5.20:dev') {transitive = false} compile("com.github.GTNewHorizons:WirelessCraftingTerminal:1.8.8.5:dev") diff --git a/src/main/java/com/glodblock/github/FluidCraft.java b/src/main/java/com/glodblock/github/FluidCraft.java index e79af60ad..c4e2788c5 100644 --- a/src/main/java/com/glodblock/github/FluidCraft.java +++ b/src/main/java/com/glodblock/github/FluidCraft.java @@ -75,6 +75,7 @@ public static void postInit(FMLPostInitializationEvent event) { Upgrades.REDSTONE.registerItem(new ItemStack(ItemAndBlockHolder.FLUID_IMPORT_BUS), 1 ); Upgrades.SPEED.registerItem(new ItemStack(ItemAndBlockHolder.FLUID_EXPORT_BUS), 4 ); Upgrades.SPEED.registerItem(new ItemStack(ItemAndBlockHolder.FLUID_IMPORT_BUS), 4 ); + Upgrades.CRAFTING.registerItem(new ItemStack(ItemAndBlockHolder.FLUID_EXPORT_BUS), 1 ); } proxy.postInit(event); diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidIO.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidIO.java index 4a6baab02..1284126cd 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidIO.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiFluidIO.java @@ -30,6 +30,7 @@ protected GuiText getName() public void update(int id, IAEFluidStack stack) { ((ContainerFluidIO)this.cvb).getBus().setFluidInSlot(id, stack); } + @Override public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY ) { diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidIO.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidIO.java index dd923e8fe..c8ce8afbb 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidIO.java +++ b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidIO.java @@ -1,7 +1,12 @@ package com.glodblock.github.client.gui.container; +import appeng.api.config.Settings; +import appeng.api.config.YesNo; +import appeng.api.util.IConfigManager; import appeng.tile.inventory.AppEngInternalAEInventory; +import com.glodblock.github.common.parts.PartFluidExportBus; import com.glodblock.github.common.parts.PartSharedFluidBus; +import com.glodblock.github.util.Ae2Reflect; import net.minecraft.entity.player.InventoryPlayer; public class ContainerFluidIO extends ContainerFluidConfigurable @@ -22,4 +27,12 @@ public PartSharedFluidBus getBus() { public AppEngInternalAEInventory getFakeFluidInv() { return (AppEngInternalAEInventory) this.bus.getInventoryByName("config"); } + + @Override + protected void loadSettingsFromHost(IConfigManager cm) { + super.loadSettingsFromHost(cm); + if (Ae2Reflect.getUpgradeableHost(this) instanceof PartFluidExportBus) { + this.setCraftingMode((YesNo)cm.getSetting(Settings.CRAFT_ONLY)); + } + } } diff --git a/src/main/java/com/glodblock/github/common/parts/PartFluidExportBus.java b/src/main/java/com/glodblock/github/common/parts/PartFluidExportBus.java index 953a00555..97e1c6db6 100644 --- a/src/main/java/com/glodblock/github/common/parts/PartFluidExportBus.java +++ b/src/main/java/com/glodblock/github/common/parts/PartFluidExportBus.java @@ -2,6 +2,10 @@ import appeng.api.config.*; import appeng.api.networking.IGridNode; +import appeng.api.networking.crafting.ICraftingGrid; +import appeng.api.networking.crafting.ICraftingLink; +import appeng.api.networking.crafting.ICraftingRequester; +import appeng.api.networking.energy.IEnergyGrid; import appeng.api.networking.security.BaseActionSource; import appeng.api.networking.security.MachineSource; import appeng.api.networking.ticking.TickRateModulation; @@ -10,11 +14,21 @@ import appeng.api.parts.IPartRenderHelper; import appeng.api.storage.IMEMonitor; import appeng.api.storage.data.IAEFluidStack; +import appeng.api.storage.data.IAEItemStack; import appeng.client.texture.CableBusTextures; +import appeng.core.AELog; +import appeng.helpers.MultiCraftingTracker; import appeng.me.GridAccessException; +import appeng.util.InventoryAdaptor; import appeng.util.item.AEFluidStack; +import appeng.util.item.AEItemStack; import com.glodblock.github.client.textures.FCPartsTexture; +import com.glodblock.github.common.item.ItemFluidDrop; import com.glodblock.github.common.item.ItemFluidPacket; +import com.glodblock.github.inventory.FluidConvertingInventoryAdaptor; +import com.glodblock.github.util.BlockPos; +import com.glodblock.github.util.Util; +import com.google.common.collect.ImmutableSet; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.RenderBlocks; @@ -23,9 +37,10 @@ import net.minecraft.util.IIcon; import net.minecraftforge.fluids.IFluidHandler; -public class PartFluidExportBus extends PartSharedFluidBus { +public class PartFluidExportBus extends PartSharedFluidBus implements ICraftingRequester { private final BaseActionSource source; + private final MultiCraftingTracker craftingTracker = new MultiCraftingTracker( this, 9 ); public PartFluidExportBus( ItemStack is ) { @@ -74,6 +89,8 @@ protected TickRateModulation doBusWork() { try { + final InventoryAdaptor destination = this.getHandler(te); + final ICraftingGrid cg = this.getProxy().getCrafting(); final IFluidHandler fh = (IFluidHandler) te; final IMEMonitor inv = this.getProxy().getStorage().getFluidInventory(); @@ -82,13 +99,20 @@ protected TickRateModulation doBusWork() IAEFluidStack fluid = AEFluidStack.create(ItemFluidPacket.getFluidStack(this.getInventoryByName("config").getStackInSlot(i))); if( fluid != null ) { + boolean isAllowed = true; + final IAEFluidStack toExtract = fluid.copy(); toExtract.setStackSize( this.calculateAmountToSend() ); + if( this.craftOnly() ) + { + isAllowed = this.craftingTracker.handleCrafting( i, toExtract.getStackSize(), ItemFluidDrop.newAeStack(toExtract), destination, this.getTile().getWorldObj(), this.getProxy().getGrid(), cg, this.source ); + } + final IAEFluidStack out = inv.extractItems( toExtract, Actionable.SIMULATE, this.source ); - if( out != null ) + if( out != null && isAllowed ) { int wasInserted = fh.fill( this.getSide().getOpposite(), out.getFluidStack(), true ); @@ -100,6 +124,10 @@ protected TickRateModulation doBusWork() return TickRateModulation.FASTER; } } + + if( this.isCraftingEnabled() ) { + this.craftingTracker.handleCrafting( i, toExtract.getStackSize(), ItemFluidDrop.newAeStack(toExtract), destination, this.getTile().getWorldObj(), this.getProxy().getGrid(), cg, this.source ); + } } } @@ -169,4 +197,64 @@ public RedstoneMode getRSMode() return (RedstoneMode) this.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED ); } + private boolean craftOnly() { + return this.getConfigManager().getSetting(Settings.CRAFT_ONLY) == YesNo.YES; + } + + private boolean isCraftingEnabled() + { + return this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0; + } + + @Override + public ImmutableSet getRequestedJobs() { + return this.craftingTracker.getRequestedJobs(); + } + + protected InventoryAdaptor getHandler(TileEntity target) { + return target != null ? FluidConvertingInventoryAdaptor.wrap(target, Util.from(this.getSide().getOpposite())) : null; + } + + @Override + public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode) { + final InventoryAdaptor d = this.getHandler(getConnectedTE()); + + try + { + if( d != null && this.getProxy().isActive() ) + { + final IEnergyGrid energy = this.getProxy().getEnergy(); + final double power = Math.ceil(items.getStackSize() / 1000D); + + if( energy.extractAEPower( power, mode, PowerMultiplier.CONFIG ) > power - 0.01 ) + { + ItemStack inputStack = items.getItemStack(); + + ItemStack remaining; + + if( mode == Actionable.SIMULATE ) + { + remaining = d.simulateAdd( inputStack ); + } + else + { + remaining = d.addItems( inputStack ); + } + + return AEItemStack.create( remaining ); + } + } + } + catch( final GridAccessException e ) + { + AELog.debug( e ); + } + + return items; + } + + @Override + public void jobStateChange(ICraftingLink link) { + this.craftingTracker.jobStateChange( link ); + } } diff --git a/src/main/java/com/glodblock/github/coremod/FCClassTransformer.java b/src/main/java/com/glodblock/github/coremod/FCClassTransformer.java index 80c52cae6..921a754e6 100644 --- a/src/main/java/com/glodblock/github/coremod/FCClassTransformer.java +++ b/src/main/java/com/glodblock/github/coremod/FCClassTransformer.java @@ -35,7 +35,7 @@ public byte[] transform(String name, String transformedName, byte[] code) { default: return code; } - System.out.println("[FCAE2] Transforming class: " + transformedName); + System.out.println("[AE2FC] Transforming class: " + transformedName); return tform.transformClass(code); } diff --git a/src/main/java/com/glodblock/github/coremod/hooker/CoreModHooks.java b/src/main/java/com/glodblock/github/coremod/hooker/CoreModHooks.java index 4edbd4b98..c3e9236df 100644 --- a/src/main/java/com/glodblock/github/coremod/hooker/CoreModHooks.java +++ b/src/main/java/com/glodblock/github/coremod/hooker/CoreModHooks.java @@ -74,7 +74,7 @@ public static InventoryAdaptor wrapInventory(@Nullable TileEntity tile, ForgeDir public static long getCraftingByteCost(IAEItemStack stack) { return stack.getItem() instanceof ItemFluidDrop - ? (long)Math.ceil(stack.getStackSize() / 1000D) : stack.getStackSize(); + ? (long) Math.ceil(stack.getStackSize() / 1000D) : stack.getStackSize(); } public static IAEItemStack[] flattenFluidPackets(IAEItemStack[] stacks) { diff --git a/src/main/java/com/glodblock/github/inventory/FluidConvertingInventoryAdaptor.java b/src/main/java/com/glodblock/github/inventory/FluidConvertingInventoryAdaptor.java index 3f3418706..385f3567e 100644 --- a/src/main/java/com/glodblock/github/inventory/FluidConvertingInventoryAdaptor.java +++ b/src/main/java/com/glodblock/github/inventory/FluidConvertingInventoryAdaptor.java @@ -9,7 +9,9 @@ import appeng.util.inv.ItemSlot; import cofh.api.transport.IItemDuct; import com.glodblock.github.common.Config; +import com.glodblock.github.common.item.ItemFluidDrop; import com.glodblock.github.common.item.ItemFluidPacket; +import com.glodblock.github.common.parts.PartFluidExportBus; import com.glodblock.github.common.parts.PartFluidInterface; import com.glodblock.github.common.tile.TileFluidInterface; import com.glodblock.github.util.Ae2Reflect; @@ -34,7 +36,8 @@ public static InventoryAdaptor wrap(TileEntity capProvider, EnumFacing face) { // sometimes i wish 1.7.10 has cap system. ForgeDirection f = Util.from(face); TileEntity inter = capProvider.getWorldObj().getTileEntity(capProvider.xCoord + f.offsetX, capProvider.yCoord + f.offsetY, capProvider.zCoord + f.offsetZ); - if (!Config.noFluidPacket && !(inter instanceof TileFluidInterface || (inter instanceof TileCableBus && ((TileCableBus) inter).getPart(f.getOpposite()) instanceof PartFluidInterface))) + if (!Config.noFluidPacket && !(inter instanceof TileFluidInterface || + (inter instanceof TileCableBus && (((TileCableBus) inter).getPart(f.getOpposite()) instanceof PartFluidInterface || ((TileCableBus) inter).getPart(f.getOpposite()) instanceof PartFluidExportBus)))) return InventoryAdaptor.getAdaptor(capProvider, f); InventoryAdaptor item = InventoryAdaptor.getAdaptor(capProvider, f); IFluidHandler fluid = capProvider instanceof IFluidHandler ? (IFluidHandler) capProvider : null; @@ -66,9 +69,15 @@ public FluidConvertingInventoryAdaptor(@Nullable InventoryAdaptor invItems, @Nul } public ItemStack addItems( ItemStack toBeAdded, InsertionMode insertionMode ) { - if (toBeAdded.getItem() instanceof ItemFluidPacket) { + if (toBeAdded.getItem() instanceof ItemFluidPacket || toBeAdded.getItem() instanceof ItemFluidDrop) { if (invFluids != null) { - FluidStack fluid = ItemFluidPacket.getFluidStack(toBeAdded); + FluidStack fluid; + if( toBeAdded.getItem() instanceof ItemFluidPacket ) { + fluid = ItemFluidPacket.getFluidStack(toBeAdded); + } else { + fluid = ItemFluidDrop.getFluidStack(toBeAdded); + } + if (fluid != null) { int filled = invFluids.fill(side, fluid, true); if (filled > 0) { @@ -97,10 +106,16 @@ public ItemStack simulateAdd(ItemStack toBeSimulated) { @Override public ItemStack simulateAdd(ItemStack toBeSimulated, InsertionMode insertionMode) { - if (toBeSimulated.getItem() instanceof ItemFluidPacket) { + if (toBeSimulated.getItem() instanceof ItemFluidPacket || toBeSimulated.getItem() instanceof ItemFluidDrop) { if (onmi) { boolean sus = false; - FluidStack fluid = ItemFluidPacket.getFluidStack(toBeSimulated); + FluidStack fluid; + if( toBeSimulated.getItem() instanceof ItemFluidPacket ) { + fluid = ItemFluidPacket.getFluidStack(toBeSimulated); + } else { + fluid = ItemFluidDrop.getFluidStack(toBeSimulated); + } + if (fluid != null) { for (ForgeDirection dir : ForgeDirection.values()) { TileEntity te = posInterface.getOffSet(dir).getTileEntity(); @@ -118,7 +133,13 @@ public ItemStack simulateAdd(ItemStack toBeSimulated, InsertionMode insertionMod return sus ? null : toBeSimulated; } if (invFluids != null) { - FluidStack fluid = ItemFluidPacket.getFluidStack(toBeSimulated); + FluidStack fluid; + if( toBeSimulated.getItem() instanceof ItemFluidPacket ) { + fluid = ItemFluidPacket.getFluidStack(toBeSimulated); + } else { + fluid = ItemFluidDrop.getFluidStack(toBeSimulated); + } + if (fluid != null) { int filled = invFluids.fill(side, fluid, false); if (filled > 0) { diff --git a/src/main/java/com/glodblock/github/util/Ae2Reflect.java b/src/main/java/com/glodblock/github/util/Ae2Reflect.java index 1ca3c2d56..bbf763b94 100644 --- a/src/main/java/com/glodblock/github/util/Ae2Reflect.java +++ b/src/main/java/com/glodblock/github/util/Ae2Reflect.java @@ -31,6 +31,7 @@ public class Ae2Reflect { private static final Field fCPU_size; private static final Field fCPU_inventory; private static final Field fCPU_machineSrc; + private static final Field fContainerUpgradeable_upgradeable; private static final Method mItemSlot_setExtractable; private static final Method mCPU_getGrid; private static final Method mCPU_postChange; @@ -47,6 +48,7 @@ public class Ae2Reflect { fCPU_size = Ae2Reflect.reflectField(CraftingCPURecord.class, "size"); fCPU_inventory = Ae2Reflect.reflectField(CraftingCPUCluster.class, "inventory"); fCPU_machineSrc = Ae2Reflect.reflectField(CraftingCPUCluster.class, "machineSrc"); + fContainerUpgradeable_upgradeable = Ae2Reflect.reflectField(ContainerUpgradeable.class, "upgradeable"); mItemSlot_setExtractable = reflectMethod(ItemSlot.class, "setExtractable", boolean.class); mCPU_getGrid = reflectMethod(CraftingCPUCluster.class, "getGrid"); mCPU_postChange = reflectMethod(CraftingCPUCluster.class, "postChange", IAEItemStack.class, BaseActionSource.class); @@ -150,6 +152,10 @@ public static MachineSource getCPUSource(CraftingCPUCluster cpu) { return Ae2Reflect.readField(cpu, fCPU_machineSrc); } + public static IUpgradeableHost getUpgradeableHost(ContainerUpgradeable owner) { + return Ae2Reflect.readField(owner, fContainerUpgradeable_upgradeable); + } + public static void postCPUChange(CraftingCPUCluster cpu, IAEItemStack stack, MachineSource src) { try { mCPU_postChange.invoke(cpu, stack, src);