diff --git a/austri3Fix.md b/austri3Fix.md index 59118ecb..2e78db2d 100644 --- a/austri3Fix.md +++ b/austri3Fix.md @@ -3,3 +3,4 @@ - legacy blocks aren't colorable - BlockLegacyDisplays don't rotate their faces correctly on the top and bottom - pattern encoder can create pattern with no inputs +- shift-clicking in the pattern encoder is less than ideal diff --git a/src/main/java/appeng/me/cache/RequestGridCache.java b/src/main/java/appeng/me/cache/RequestGridCache.java index 9904cb72..50913d95 100644 --- a/src/main/java/appeng/me/cache/RequestGridCache.java +++ b/src/main/java/appeng/me/cache/RequestGridCache.java @@ -26,8 +26,8 @@ import appeng.api.storage.StorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; -public class RequestGridCache implements IRequestGrid, IMEInventoryHandler, ICellProvider { - +public class RequestGridCache + implements IRequestGrid, IMEInventoryHandler, ICellProvider { private IGrid grid; private IStorageGrid storageGrid; private Map requestable = new HashMap<>(); @@ -38,9 +38,7 @@ public class RequestGridCache implements IRequestGrid, IMEInventoryHandler getRequestableItems() { Set list = new HashSet<>(); - for(IAEItemStack stack : requestable.keySet()) { + for (IAEItemStack stack : requestable.keySet()) { list.add(stack.copy()); } return list; @@ -108,12 +102,14 @@ public class RequestGridCache implements IRequestGrid, IMEInventoryHandler providers; public long amount; @@ -212,7 +210,5 @@ public class RequestGridCache implements IRequestGrid, IMEInventoryHandler mb = new ArrayList<>(); public List assemblers = new ArrayList<>(); public long inst; - public Job[] jobs; public AssemblerCluster(WorldCoord _min, WorldCoord _max) { this.min = _min; this.max = _max; } - public void onOperation() { - for (int i = 0; i < this.jobs.length; i++) { - if (this.jobs[i] == null) - continue; - - ItemStack out = this.jobs[i].det.getOutput( - this.jobs[i].inv, this.assemblers.get(0).getWorldObj() - ); - - if (out != null) { - try { - IMEMonitor inv - = this.assemblers.get(0).getProxy().getStorage().getItemInventory( - ); - - inv.injectItems( - AEItemStack.create(out), - Actionable.MODULATE, - new MachineSource(this.assemblers.get(0)) - ); - - } catch (GridAccessException kek) {} - } - - this.jobs[i] = null; + public void initMaster() { + if (this.getMaster().jobs == null + || this.getMaster().jobs.length != this.accelerators) { + this.getMaster().jobs = new TileAssembler.Job[this.accelerators]; } + + for (int i = 1; i < this.assemblers.size(); i++) { + // slaveify old masters + this.assemblers.get(i).jobs = null; + } + } + + public void onOperation() { + this.getMaster().onOperation(); } public TileAssembler getAssembler(int i) { return this.assemblers.get(i); } - public boolean addCraft(Job job) { - for (int i = 0; i < this.jobs.length; i++) { - if (this.jobs[i] == null) { - this.jobs[i] = job; - return true; - } - } - - return false; - } - public boolean canCraft() { - for (Job j : this.jobs) - if (j == null) - return true; - - return false; + return this.getMaster().canCraft(); } public void destroy() { @@ -136,13 +99,7 @@ public class AssemblerCluster implements IAssemblerCluster { ); } - public static class Job { - public ICraftingPatternDetails det; - public InventoryCrafting inv; - - public Job(ICraftingPatternDetails det, InventoryCrafting inv) { - this.det = det; - this.inv = inv; - } + public TileAssembler getMaster() { + return this.getAssembler(0); } } diff --git a/src/main/java/appeng/tile/legacy/TileAssembler.java b/src/main/java/appeng/tile/legacy/TileAssembler.java index a199212a..549fa743 100644 --- a/src/main/java/appeng/tile/legacy/TileAssembler.java +++ b/src/main/java/appeng/tile/legacy/TileAssembler.java @@ -2,20 +2,29 @@ package appeng.tile.legacy; import java.util.ArrayList; +import appeng.api.config.Actionable; import appeng.api.implementations.ICraftingPatternItem; +import appeng.api.networking.GridFlags; import appeng.api.networking.IAssemblerCache; import appeng.api.networking.crafting.ICraftingPatternDetails; import appeng.api.networking.crafting.ICraftingProvider; import appeng.api.networking.crafting.ICraftingProviderHelper; import appeng.api.networking.events.MENetworkCraftingPatternChange; +import appeng.api.networking.security.MachineSource; +import appeng.api.storage.IMEMonitor; +import appeng.api.storage.data.IAEItemStack; import appeng.api.util.WorldCoord; import appeng.block.legacy.BlockAssemblerHeatVent; import appeng.block.legacy.BlockAssemblerWall; +import appeng.container.ContainerNull; +import appeng.items.misc.ItemEncodedPattern; import appeng.me.GridAccessException; import appeng.me.cache.AssemblerGridCache; import appeng.me.cluster.IAssemblerCluster; import appeng.me.cluster.IAssemblerMB; import appeng.me.cluster.implementations.AssemblerCluster; +import appeng.me.helpers.AENetworkProxy; +import appeng.me.helpers.AENetworkProxyMultiblock; import appeng.tile.TileEvent; import appeng.tile.events.TileEventType; import appeng.tile.grid.AENetworkTile; @@ -26,12 +35,14 @@ import appeng.util.InventoryAdaptor; import appeng.util.Platform; import appeng.util.inv.AdaptorIInventory; import appeng.util.inv.IInventoryDestination; +import appeng.util.item.AEItemStack; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -41,11 +52,20 @@ public class TileAssembler extends AENetworkTile implements IAssemblerMB, IAEAppEngInventory, IInventory, ICraftingProvider { AssemblerCluster ac = null; AppEngInternalInventory inv = new AppEngInternalInventory(this, 54); + public Job[] jobs; public TileAssembler() { super(); // TODO: WTF //super.updatesOnPower = false; + this.getProxy().setFlags(GridFlags.REQUIRE_CHANNEL, GridFlags.MULTIBLOCK); + } + + @Override + protected AENetworkProxy createProxy() { + return new AENetworkProxyMultiblock( + this, "proxy", this.getItemFromTile(this), true + ); } @Override @@ -128,6 +148,7 @@ public class TileAssembler extends AENetworkTile if (ac != null && lastMB != null) { lastMB.sendUpdate(true, null); + ac.initMaster(); try { IAssemblerCache cache = lastMB.getProxy().getGrid().getCache(IAssemblerCache.class); @@ -194,8 +215,6 @@ public class TileAssembler extends AENetworkTile } } - ac.jobs = new AssemblerCluster.Job[ac.accelerators]; - if (ac.assemblers.size() > 0) { return ac; } else { @@ -203,6 +222,14 @@ public class TileAssembler extends AENetworkTile } } + public boolean canCraft() { + for (Job j : this.jobs) + if (j == null) + return true; + + return false; + } + public static boolean verifyUnownedRegionInner( IBlockAccess w, int minx, @@ -489,12 +516,48 @@ public class TileAssembler extends AENetworkTile if (((ICraftingPatternItem) is.getItem()) .getPatternForItem(is, this.worldObj) .equals(patternDetails)) { - return this.ac.addCraft(new AssemblerCluster.Job(patternDetails, table)); + return this.ac.getMaster().addCraft(new Job(patternDetails, table)); } } return false; } + public void onOperation() { + for (int i = 0; i < this.jobs.length; i++) { + if (this.jobs[i] == null) + continue; + + ItemStack out = this.jobs[i].det.getOutput(this.jobs[i].inv, this.worldObj); + + if (out != null) { + try { + IMEMonitor inv + = this.getProxy().getStorage().getItemInventory(); + + inv.injectItems( + AEItemStack.create(out), + Actionable.MODULATE, + new MachineSource(this) + ); + + } catch (GridAccessException kek) {} + } + + this.jobs[i] = null; + } + } + + public boolean addCraft(Job job) { + for (int i = 0; i < this.jobs.length; i++) { + if (this.jobs[i] == null) { + this.jobs[i] = job; + return true; + } + } + + return false; + } + @Override public boolean isBusy() { if (this.ac == null) @@ -520,13 +583,102 @@ public class TileAssembler extends AENetworkTile } } + public boolean isMaster() { + return this.jobs != null; + } + @TileEvent(TileEventType.WORLD_NBT_WRITE) public void writeToNbtTileAssembler(NBTTagCompound nbt) { this.inv.writeToNBT(nbt, "inv"); + + if (this.isMaster()) { + NBTTagList jobs = new NBTTagList(); + for (Job j : this.jobs) { + if (j == null) + continue; + + jobs.appendTag(j.writeToNBT(new NBTTagCompound())); + } + + nbt.setTag("jobs", jobs); + nbt.setInteger("jobc", this.jobs.length); + } } @TileEvent(TileEventType.WORLD_NBT_READ) public void readFromNbtTileAssembler(NBTTagCompound nbt) { + System.out.println("ALEC: " + nbt); this.inv.readFromNBT(nbt, "inv"); + + if (nbt.hasKey("jobs")) { + NBTTagList jobs = nbt.getTagList("jobs", 10); + + this.jobs = new Job[nbt.getInteger("jobc")]; + + for (int i = 0; i < jobs.tagCount(); i++) { + this.jobs[i] = Job.readFromNBT(jobs.getCompoundTagAt(i), this.worldObj); + } + } + } + + public static class Job { + public ICraftingPatternDetails det; + public InventoryCrafting inv; + + public Job(ICraftingPatternDetails det, InventoryCrafting inv) { + this.det = det; + this.inv = inv; + } + + public NBTTagCompound writeToNBT(NBTTagCompound nbt) { + nbt.setTag("pattern", this.det.getPattern().writeToNBT(new NBTTagCompound())); + NBTTagList input = new NBTTagList(); + + for (int i = 0; i < this.inv.getSizeInventory(); i++) { + if (this.inv.getStackInSlot(i) == null) { + input.appendTag(new NBTTagCompound()); + } else { + input.appendTag( + this.inv.getStackInSlot(i).writeToNBT(new NBTTagCompound()) + ); + } + } + + nbt.setTag("input", input); + + return nbt; + } + + public static Job readFromNBT(NBTTagCompound nbt, World w) { + ItemStack patternStack + = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("pattern")); + ICraftingPatternDetails det = ((ItemEncodedPattern) patternStack.getItem()) + .getPatternForItem(patternStack, w); + + NBTTagList input = nbt.getTagList("input", 10); + InventoryCrafting inv = new InventoryCrafting(new ContainerNull(), 3, 3); + + for (int i = 0; i < input.tagCount(); i++) { + if (input.getCompoundTagAt(i).hasNoTags()) { + inv.setInventorySlotContents(i, null); + } else { + inv.setInventorySlotContents( + i, ItemStack.loadItemStackFromNBT(input.getCompoundTagAt(i)) + ); + } + } + + return new Job(det, inv); + } + } + + @Override + public void disconnect(boolean b) { + // TODO Auto-generated method stub + } + + @Override + public boolean isValid() { + return this.isComplete(); } } diff --git a/src/main/java/appeng/tile/legacy/TileAssemblerMB.java b/src/main/java/appeng/tile/legacy/TileAssemblerMB.java index 3d47cb9a..1ad69cbe 100644 --- a/src/main/java/appeng/tile/legacy/TileAssemblerMB.java +++ b/src/main/java/appeng/tile/legacy/TileAssemblerMB.java @@ -3,10 +3,13 @@ package appeng.tile.legacy; import java.util.List; import appeng.api.implementations.ICraftingPatternItem; +import appeng.api.networking.GridFlags; import appeng.api.networking.crafting.ICraftingPatternDetails; import appeng.me.cluster.IAssemblerCluster; import appeng.me.cluster.IAssemblerMB; import appeng.me.cluster.implementations.AssemblerCluster; +import appeng.me.helpers.AENetworkProxy; +import appeng.me.helpers.AENetworkProxyMultiblock; import appeng.tile.TileEvent; import appeng.tile.events.TileEventType; import appeng.tile.grid.AENetworkTile; @@ -29,6 +32,7 @@ public class TileAssemblerMB extends AENetworkTile implements IAssemblerMB, IInv // TODO: WTF //super.updatesOnPower = false; this.getProxy().setIdlePowerUsage(0.0); + this.getProxy().setFlags(GridFlags.REQUIRE_CHANNEL, GridFlags.MULTIBLOCK); } @Override @@ -36,6 +40,13 @@ public class TileAssemblerMB extends AENetworkTile implements IAssemblerMB, IInv return false; } + @Override + protected AENetworkProxy createProxy() { + return new AENetworkProxyMultiblock( + this, "proxy", this.getItemFromTile(this), true + ); + } + // TODO: WTF //protected void terminate() { // super.terminate(); @@ -402,4 +413,14 @@ public class TileAssemblerMB extends AENetworkTile implements IAssemblerMB, IInv @Override public void getDrops(World w, int x, int y, int z, List drops) {} + + @Override + public void disconnect(boolean b) { + // TODO Auto-generated method stub + } + + @Override + public boolean isValid() { + return this.isComplete(); + } }