diff --git a/src/main/java/mekanism/client/gui/GuiInductionMatrix.java b/src/main/java/mekanism/client/gui/GuiInductionMatrix.java index db4cccb34..f0297183f 100644 --- a/src/main/java/mekanism/client/gui/GuiInductionMatrix.java +++ b/src/main/java/mekanism/client/gui/GuiInductionMatrix.java @@ -24,8 +24,8 @@ public class GuiInductionMatrix extends GuiMekanismTile Arrays.asList(LangUtils.localize("gui.storing") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.getEnergy(), tileEntity.getMaxEnergy()), - LangUtils.localize("gui.input") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.structure.lastInput) + "/t", - LangUtils.localize("gui.output") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.structure.lastOutput) + "/t"), this, resource)); + LangUtils.localize("gui.input") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.structure.getLastInput()) + "/t", + LangUtils.localize("gui.output") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.structure.getLastOutput()) + "/t"), this, resource)); } @Override @@ -33,9 +33,9 @@ public class GuiInductionMatrix extends GuiMekanismTile= 7 && xAxis <= 39 && yAxis >= 14 && yAxis <= 72) { @@ -76,7 +76,6 @@ public class GuiInductionMatrix extends GuiMekanismTile { addGuiElement(new GuiRateBar(this, new IRateInfoHandler() { @Override public String getTooltip() { - return LangUtils.localize("gui.receiving") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.structure.lastInput) + "/t"; + return LangUtils.localize("gui.receiving") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.structure.getLastInput()) + "/t"; } @Override public double getLevel() { - return tileEntity.structure.lastInput / tileEntity.structure.transferCap; + return tileEntity.structure.getLastInput() / tileEntity.structure.getTransferCap(); } }, resource, 30, 13)); addGuiElement(new GuiRateBar(this, new IRateInfoHandler() { @Override public String getTooltip() { - return LangUtils.localize("gui.outputting") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.structure.lastOutput) + "/t"; + return LangUtils.localize("gui.outputting") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.structure.getLastOutput()) + "/t"; } @Override public double getLevel() { - return tileEntity.structure.lastOutput / tileEntity.structure.transferCap; + return tileEntity.structure.getLastOutput() / tileEntity.structure.getTransferCap(); } }, resource, 38, 13)); addGuiElement(new GuiEnergyInfo(() -> Arrays.asList( LangUtils.localize("gui.storing") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.getEnergy(), tileEntity.getMaxEnergy()), - LangUtils.localize("gui.input") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.structure.lastInput) + "/t", - LangUtils.localize("gui.output") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.structure.lastOutput) + "/t"), this, resource)); + LangUtils.localize("gui.input") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.structure.getLastInput()) + "/t", + LangUtils.localize("gui.output") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.structure.getLastOutput()) + "/t"), this, resource)); } @Override @@ -59,16 +59,16 @@ public class GuiMatrixStats extends GuiMekanismTile { String stats = LangUtils.localize("gui.matrixStats"); fontRenderer.drawString(stats, (xSize / 2) - (fontRenderer.getStringWidth(stats) / 2), 6, 0x404040); fontRenderer.drawString(LangUtils.localize("gui.input") + ":", 53, 26, 0x797979); - fontRenderer.drawString(MekanismUtils.getEnergyDisplay(tileEntity.structure.lastInput) + "/" + - MekanismUtils.getEnergyDisplay(tileEntity.structure.transferCap), 59, 35, 0x404040); + fontRenderer.drawString(MekanismUtils.getEnergyDisplay(tileEntity.structure.getLastInput()) + "/" + + MekanismUtils.getEnergyDisplay(tileEntity.structure.getTransferCap()), 59, 35, 0x404040); fontRenderer.drawString(LangUtils.localize("gui.output") + ":", 53, 46, 0x797979); - fontRenderer.drawString(MekanismUtils.getEnergyDisplay(tileEntity.structure.lastOutput) + "/" + - MekanismUtils.getEnergyDisplay(tileEntity.structure.transferCap), 59, 55, 0x404040); + fontRenderer.drawString(MekanismUtils.getEnergyDisplay(tileEntity.structure.getLastOutput()) + "/" + + MekanismUtils.getEnergyDisplay(tileEntity.structure.getTransferCap()), 59, 55, 0x404040); fontRenderer.drawString(LangUtils.localize("gui.dimensions") + ":", 8, 82, 0x797979); fontRenderer.drawString(tileEntity.structure.volWidth + " x " + tileEntity.structure.volHeight + " x " + tileEntity.structure.volLength, 14, 91, 0x404040); fontRenderer.drawString(LangUtils.localize("gui.constituents") + ":", 8, 102, 0x797979); - fontRenderer.drawString(tileEntity.clientCells + " " + LangUtils.localize("gui.cells"), 14, 111, 0x404040); - fontRenderer.drawString(tileEntity.clientProviders + " " + LangUtils.localize("gui.providers"), 14, 120, 0x404040); + fontRenderer.drawString(tileEntity.structure.getCellCount() + " " + LangUtils.localize("gui.cells"), 14, 111, 0x404040); + fontRenderer.drawString(tileEntity.structure.getProviderCount() + " " + LangUtils.localize("gui.providers"), 14, 120, 0x404040); super.drawGuiContainerForegroundLayer(mouseX, mouseY); } diff --git a/src/main/java/mekanism/common/block/BlockBasic.java b/src/main/java/mekanism/common/block/BlockBasic.java index d837a9bb7..0dd8f0baf 100644 --- a/src/main/java/mekanism/common/block/BlockBasic.java +++ b/src/main/java/mekanism/common/block/BlockBasic.java @@ -685,7 +685,6 @@ public abstract class BlockBasic extends BlockTileDrops { if (basicBlockType != null && basicBlockType.hasRedstoneOutput) { TileEntity tile = worldIn.getTileEntity(pos); if (tile instanceof IComparatorSupport) { - //TODO: Add support for induction port (will be done in induction cleanup PR) return ((IComparatorSupport) tile).getRedstoneLevel(); } } diff --git a/src/main/java/mekanism/common/block/states/BlockStateBasic.java b/src/main/java/mekanism/common/block/states/BlockStateBasic.java index 76e7e5711..4d8f03ab9 100644 --- a/src/main/java/mekanism/common/block/states/BlockStateBasic.java +++ b/src/main/java/mekanism/common/block/states/BlockStateBasic.java @@ -96,7 +96,7 @@ public class BlockStateBasic extends ExtendedBlockState { THERMAL_EVAPORATION_VALVE(BasicBlock.BASIC_BLOCK_1, 15, "ThermalEvaporationValve", TileEntityThermalEvaporationValve::new, true, BlockStateUtils.NO_ROTATION, false, false, false, true), THERMAL_EVAPORATION_BLOCK(BasicBlock.BASIC_BLOCK_2, 0, "ThermalEvaporationBlock", TileEntityThermalEvaporationBlock::new, true, BlockStateUtils.NO_ROTATION, false, false, false), INDUCTION_CASING(BasicBlock.BASIC_BLOCK_2, 1, "InductionCasing", TileEntityInductionCasing::new, true, BlockStateUtils.NO_ROTATION, false, false, false), - INDUCTION_PORT(BasicBlock.BASIC_BLOCK_2, 2, "InductionPort", TileEntityInductionPort::new, true, BlockStateUtils.NO_ROTATION, true, false, false), + INDUCTION_PORT(BasicBlock.BASIC_BLOCK_2, 2, "InductionPort", TileEntityInductionPort::new, true, BlockStateUtils.NO_ROTATION, true, false, false, true), INDUCTION_CELL(BasicBlock.BASIC_BLOCK_2, 3, "InductionCell", TileEntityInductionCell::new, true, BlockStateUtils.NO_ROTATION, false, true, false), INDUCTION_PROVIDER(BasicBlock.BASIC_BLOCK_2, 4, "InductionProvider", TileEntityInductionProvider::new, true, BlockStateUtils.NO_ROTATION, false, true, false), SUPERHEATING_ELEMENT(BasicBlock.BASIC_BLOCK_2, 5, "SuperheatingElement", TileEntitySuperheatingElement::new, true, BlockStateUtils.NO_ROTATION, false, false, false), diff --git a/src/main/java/mekanism/common/content/boiler/BoilerUpdateProtocol.java b/src/main/java/mekanism/common/content/boiler/BoilerUpdateProtocol.java index 89b528d49..469a6d484 100644 --- a/src/main/java/mekanism/common/content/boiler/BoilerUpdateProtocol.java +++ b/src/main/java/mekanism/common/content/boiler/BoilerUpdateProtocol.java @@ -43,107 +43,102 @@ public class BoilerUpdateProtocol extends UpdateProtocol @Override protected boolean canForm(SynchronizedBoilerData structure) { - if (structure.volHeight >= 3) { - Set dispersers = new HashSet<>(); - Set elements = new HashSet<>(); - for (Coord4D coord : innerNodes) { - TileEntity tile = coord.getTileEntity(pointer.getWorld()); - if (tile instanceof TileEntityPressureDisperser) { - dispersers.add(coord); - } else if (tile instanceof TileEntitySuperheatingElement) { - structure.internalLocations.add(coord); - elements.add(coord); - } + if (structure.volHeight < 3) { + return false; + } + Set dispersers = new HashSet<>(); + Set elements = new HashSet<>(); + for (Coord4D coord : innerNodes) { + TileEntity tile = coord.getTileEntity(pointer.getWorld()); + if (tile instanceof TileEntityPressureDisperser) { + dispersers.add(coord); + } else if (tile instanceof TileEntitySuperheatingElement) { + structure.internalLocations.add(coord); + elements.add(coord); } - - int prevDispersers = dispersers.size(); - //Ensure at least one disperser exists - if (dispersers.size() == 0) { - return false; - } - //Find a single disperser contained within this multiblock - final Coord4D initDisperser = dispersers.iterator().next(); - - //Ensure that a full horizontal plane of dispersers exist, surrounding the found disperser - Coord4D pos = new Coord4D(structure.renderLocation.x, initDisperser.y, structure.renderLocation.z, pointer.getWorld().provider.getDimension()); - for (int x = 1; x < structure.volLength - 1; x++) { - for (int z = 1; z < structure.volWidth - 1; z++) { - Coord4D coord4D = pos.translate(x, 0, z); - TileEntity tile = coord4D.getTileEntity(pointer.getWorld()); - if (!(tile instanceof TileEntityPressureDisperser)) { - return false; - } - dispersers.remove(coord4D); - } - } - - //If there are more dispersers than those on the plane found, the structure is invalid - if (dispersers.size() > 0) { - return false; - } - - if (elements.size() > 0) { - structure.superheatingElements = new NodeCounter(new NodeChecker() { - @Override - public boolean isValid(Coord4D coord) { - return coord.getTileEntity(pointer.getWorld()) instanceof TileEntitySuperheatingElement; - } - }).calculate(elements.iterator().next()); - } - - if (elements.size() > structure.superheatingElements) { - return false; - } - - Coord4D initAir = null; - int totalAir = 0; - - //Find the first available block in the structure for water storage (including casings) - for (int x = structure.renderLocation.x; x < structure.renderLocation.x + structure.volLength; x++) { - for (int y = structure.renderLocation.y; y < initDisperser.y; y++) { - for (int z = structure.renderLocation.z; z < structure.renderLocation.z + structure.volWidth; z++) { - if (pointer.getWorld().isAirBlock(new BlockPos(x, y, z)) || isViableNode(x, y, z)) { - initAir = new Coord4D(x, y, z, pointer.getWorld().provider.getDimension()); - totalAir++; - } - } - } - } - - //Some air must exist for the structure to be valid - if (initAir == null) { - return false; - } - - //Gradle build requires these fields to be final - final Coord4D renderLocation = structure.renderLocation; - final int volLength = structure.volLength; - final int volWidth = structure.volWidth; - - structure.waterVolume = new NodeCounter(new NodeChecker() { - @Override - public final boolean isValid(Coord4D coord) { - return coord.y >= renderLocation.y - 1 && coord.y < initDisperser.y && - coord.x >= renderLocation.x && coord.x < renderLocation.x + volLength && - coord.z >= renderLocation.z && coord.z < renderLocation.z + volWidth && - (coord.isAirBlock(pointer.getWorld()) || isViableNode(coord.getPos())); - } - }).calculate(initAir); - - //Make sure all air blocks are connected - if (totalAir > structure.waterVolume) { - return false; - } - - int steamHeight = structure.renderLocation.y + structure.volHeight - 2 - initDisperser.y; - structure.steamVolume = structure.volWidth * structure.volLength * steamHeight; - - structure.upperRenderLocation = new Coord4D(structure.renderLocation.x, initDisperser.y + 1, structure.renderLocation.z, pointer.getWorld().provider.getDimension()); - - return true; + } + //Ensure at least one disperser exists + if (dispersers.isEmpty()) { + return false; } - return false; + //Find a single disperser contained within this multiblock + final Coord4D initDisperser = dispersers.iterator().next(); + + //Ensure that a full horizontal plane of dispersers exist, surrounding the found disperser + Coord4D pos = new Coord4D(structure.renderLocation.x, initDisperser.y, structure.renderLocation.z, pointer.getWorld().provider.getDimension()); + for (int x = 1; x < structure.volLength - 1; x++) { + for (int z = 1; z < structure.volWidth - 1; z++) { + Coord4D coord4D = pos.translate(x, 0, z); + TileEntity tile = coord4D.getTileEntity(pointer.getWorld()); + if (!(tile instanceof TileEntityPressureDisperser)) { + return false; + } + dispersers.remove(coord4D); + } + } + + //If there are more dispersers than those on the plane found, the structure is invalid + if (!dispersers.isEmpty()) { + return false; + } + + if (elements.size() > 0) { + structure.superheatingElements = new NodeCounter(new NodeChecker() { + @Override + public boolean isValid(Coord4D coord) { + return coord.getTileEntity(pointer.getWorld()) instanceof TileEntitySuperheatingElement; + } + }).calculate(elements.iterator().next()); + } + + if (elements.size() > structure.superheatingElements) { + return false; + } + + Coord4D initAir = null; + int totalAir = 0; + + //Find the first available block in the structure for water storage (including casings) + for (int x = structure.renderLocation.x; x < structure.renderLocation.x + structure.volLength; x++) { + for (int y = structure.renderLocation.y; y < initDisperser.y; y++) { + for (int z = structure.renderLocation.z; z < structure.renderLocation.z + structure.volWidth; z++) { + if (pointer.getWorld().isAirBlock(new BlockPos(x, y, z)) || isViableNode(x, y, z)) { + initAir = new Coord4D(x, y, z, pointer.getWorld().provider.getDimension()); + totalAir++; + } + } + } + } + + //Some air must exist for the structure to be valid + if (initAir == null) { + return false; + } + + //Gradle build requires these fields to be final + final Coord4D renderLocation = structure.renderLocation; + final int volLength = structure.volLength; + final int volWidth = structure.volWidth; + structure.waterVolume = new NodeCounter(new NodeChecker() { + @Override + public final boolean isValid(Coord4D coord) { + return coord.y >= renderLocation.y - 1 && coord.y < initDisperser.y && + coord.x >= renderLocation.x && coord.x < renderLocation.x + volLength && + coord.z >= renderLocation.z && coord.z < renderLocation.z + volWidth && + (coord.isAirBlock(pointer.getWorld()) || isViableNode(coord.getPos())); + } + }).calculate(initAir); + + //Make sure all air blocks are connected + if (totalAir > structure.waterVolume) { + return false; + } + + int steamHeight = (structure.renderLocation.y + structure.volHeight - 2) - initDisperser.y; + structure.steamVolume = structure.volWidth * structure.volLength * steamHeight; + structure.upperRenderLocation = new Coord4D(structure.renderLocation.x, initDisperser.y + 1, structure.renderLocation.z, pointer.getWorld().provider.getDimension()); + return true; } @Override @@ -162,31 +157,28 @@ public class BoilerUpdateProtocol extends UpdateProtocol } @Override - protected void mergeCaches(List rejectedItems, MultiblockCache cache, - MultiblockCache merge) { - if (((BoilerCache) cache).water == null) { - ((BoilerCache) cache).water = ((BoilerCache) merge).water; - } else if (((BoilerCache) merge).water != null && ((BoilerCache) cache).water.isFluidEqual(((BoilerCache) merge).water)) { - ((BoilerCache) cache).water.amount += ((BoilerCache) merge).water.amount; + protected void mergeCaches(List rejectedItems, MultiblockCache cache, MultiblockCache merge) { + BoilerCache boilerCache = (BoilerCache) cache; + BoilerCache mergeCache = (BoilerCache) merge; + if (boilerCache.water == null) { + boilerCache.water = mergeCache.water; + } else if (mergeCache.water != null && boilerCache.water.isFluidEqual(mergeCache.water)) { + boilerCache.water.amount += mergeCache.water.amount; } - - if (((BoilerCache) cache).steam == null) { - ((BoilerCache) cache).steam = ((BoilerCache) merge).steam; - } else if (((BoilerCache) merge).steam != null && ((BoilerCache) cache).steam.isFluidEqual(((BoilerCache) merge).steam)) { - ((BoilerCache) cache).steam.amount += ((BoilerCache) merge).steam.amount; + if (boilerCache.steam == null) { + boilerCache.steam = mergeCache.steam; + } else if (mergeCache.steam != null && boilerCache.steam.isFluidEqual(mergeCache.steam)) { + boilerCache.steam.amount += mergeCache.steam.amount; } - - ((BoilerCache) cache).temperature = Math.max(((BoilerCache) cache).temperature, ((BoilerCache) merge).temperature); + boilerCache.temperature = Math.max(boilerCache.temperature, mergeCache.temperature); } @Override protected void onFormed() { super.onFormed(); - if (structureFound.waterStored != null) { structureFound.waterStored.amount = Math.min(structureFound.waterStored.amount, structureFound.waterVolume * WATER_PER_TANK); } - if (structureFound.steamStored != null) { structureFound.steamStored.amount = Math.min(structureFound.steamStored.amount, structureFound.steamVolume * STEAM_PER_TANK); } diff --git a/src/main/java/mekanism/common/content/matrix/MatrixCache.java b/src/main/java/mekanism/common/content/matrix/MatrixCache.java index cfbdd0f0b..b35e9b246 100644 --- a/src/main/java/mekanism/common/content/matrix/MatrixCache.java +++ b/src/main/java/mekanism/common/content/matrix/MatrixCache.java @@ -13,12 +13,12 @@ public class MatrixCache extends MultiblockCache { @Override public void apply(SynchronizedMatrixData data) { - data.inventory = inventory; + data.setInventory(inventory); } @Override public void sync(SynchronizedMatrixData data) { - inventory = data.inventory; + inventory = data.getInventory(); } @Override diff --git a/src/main/java/mekanism/common/content/matrix/MatrixUpdateProtocol.java b/src/main/java/mekanism/common/content/matrix/MatrixUpdateProtocol.java index 83e5ae7bf..1b32dcaa6 100644 --- a/src/main/java/mekanism/common/content/matrix/MatrixUpdateProtocol.java +++ b/src/main/java/mekanism/common/content/matrix/MatrixUpdateProtocol.java @@ -30,11 +30,11 @@ public class MatrixUpdateProtocol extends UpdateProtocol @Override public boolean isValidInnerNode(int x, int y, int z) { - TileEntity tile = new Coord4D(x, y, z, pointer.getWorld().provider.getDimension()).getTileEntity(pointer.getWorld()); - if (tile instanceof TileEntityInductionCell || tile instanceof TileEntityInductionProvider) { + if (super.isValidInnerNode(x, y, z)) { return true; } - return isAir(x, y, z); + TileEntity tile = new Coord4D(x, y, z, pointer.getWorld().provider.getDimension()).getTileEntity(pointer.getWorld()); + return tile instanceof TileEntityInductionCell || tile instanceof TileEntityInductionProvider; } @Override @@ -53,13 +53,21 @@ public class MatrixUpdateProtocol extends UpdateProtocol } @Override - protected void mergeCaches(List rejectedItems, MultiblockCache cache, - MultiblockCache merge) { - List rejects = StackUtils.getMergeRejects(((MatrixCache) cache).inventory, ((MatrixCache) merge).inventory); + protected void mergeCaches(List rejectedItems, MultiblockCache cache, MultiblockCache merge) { + MatrixCache matrixCache = (MatrixCache) cache; + MatrixCache mergeCache = (MatrixCache) merge; + List rejects = StackUtils.getMergeRejects(matrixCache.inventory, mergeCache.inventory); if (!rejects.isEmpty()) { rejectedItems.addAll(rejects); } - StackUtils.merge(((MatrixCache) cache).inventory, ((MatrixCache) merge).inventory); + StackUtils.merge(matrixCache.inventory, mergeCache.inventory); + } + + @Override + protected void onStructureDestroyed(SynchronizedMatrixData structure) { + //Save all energy changes before destroying the structure + structure.tick(pointer.getWorld()); + super.onStructureDestroyed(structure); } @Override @@ -67,11 +75,9 @@ public class MatrixUpdateProtocol extends UpdateProtocol for (Coord4D coord : innerNodes) { TileEntity tile = coord.getTileEntity(pointer.getWorld()); if (tile instanceof TileEntityInductionCell) { - structure.cells.add(coord); - structure.storageCap += ((TileEntityInductionCell) tile).tier.getMaxEnergy(); + structure.addCell(coord, (TileEntityInductionCell) tile); } else if (tile instanceof TileEntityInductionProvider) { - structure.providers.add(coord); - structure.transferCap += ((TileEntityInductionProvider) tile).tier.getOutput(); + structure.addProvider(coord, (TileEntityInductionProvider) tile); } } return true; diff --git a/src/main/java/mekanism/common/content/matrix/SynchronizedMatrixData.java b/src/main/java/mekanism/common/content/matrix/SynchronizedMatrixData.java index 8f47ede0e..bc521803f 100644 --- a/src/main/java/mekanism/common/content/matrix/SynchronizedMatrixData.java +++ b/src/main/java/mekanism/common/content/matrix/SynchronizedMatrixData.java @@ -1,65 +1,270 @@ package mekanism.common.content.matrix; +import io.netty.buffer.ByteBuf; import java.util.HashSet; import java.util.Set; import mekanism.api.Coord4D; +import mekanism.api.TileNetworkList; import mekanism.common.multiblock.SynchronizedData; import mekanism.common.tile.TileEntityInductionCell; +import mekanism.common.tile.TileEntityInductionProvider; +import mekanism.common.util.MekanismUtils; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.NonNullList; import net.minecraft.world.World; +//TODO: Do something better for purposes of double precision such as BigInt public class SynchronizedMatrixData extends SynchronizedData { - public NonNullList inventory = NonNullList.withSize(2, ItemStack.EMPTY); + private NonNullList inventory = NonNullList.withSize(2, ItemStack.EMPTY); + private Set providers = new HashSet<>(); + private Set cells = new HashSet<>(); + private double queuedOutput; + private double queuedInput; + private double lastOutput; + private double lastInput; - public Set cells = new HashSet<>(); + private double cachedTotal; + private double transferCap; + private double storageCap; - public Set providers = new HashSet<>(); - - public double remainingInput; - public double lastInput; - - public double remainingOutput; - public double lastOutput; - - public double clientEnergy; - public double storageCap; - public double transferCap; + private int clientProviders; + private int clientCells; @Override public NonNullList getInventory() { return inventory; } - public double getEnergy(World world) { - double ret = 0; - - for (Coord4D coord : cells) { - TileEntity tile = coord.getTileEntity(world); - - if (tile instanceof TileEntityInductionCell) { - ret += ((TileEntityInductionCell) tile).getEnergy(); - } - } - - return ret; + public void setInventory(NonNullList inventory) { + this.inventory = inventory; } - public void setEnergy(World world, double energy) { + public void addCell(Coord4D coord, TileEntityInductionCell cell) { + //As we already have the two different variables just pass them instead of accessing world to get tile again + cells.add(coord); + storageCap += cell.tier.getMaxEnergy(); + cachedTotal += cell.getEnergy(); + } + + public void addProvider(Coord4D coord, TileEntityInductionProvider provider) { + providers.add(coord); + transferCap += provider.tier.getOutput(); + } + + public double getEnergyPostQueue() { + return cachedTotal + queuedInput - queuedOutput; + } + + public void tick(World world) { + //See comment in getEnergyPostQueue for explanation of how lastChange is calculated. + double lastChange = queuedInput - queuedOutput; + if (lastChange < 0) { + //We are removing energy + removeEnergy(world, -lastChange); + } else if (lastChange > 0) { + //we are adding energy + addEnergy(world, lastChange); + } + cachedTotal += lastChange; + + lastInput = queuedInput; + queuedInput = 0; + lastOutput = queuedOutput; + queuedOutput = 0; + } + + public double queueEnergyAddition(double energy, boolean simulate) { + if (energy < 0) { + //Ensure that the correct queue type gets called + return queueEnergyRemoval(-energy, simulate); + } + double remainingInput = getRemainingInput(); + if (energy > remainingInput) { + energy = remainingInput; + } + //Check to see if we are trying to add more energy than we have room for, + // as we want to be as accurate as possible with the values we return + // It is possible that the energy we have space for is a lot less than the amount we + // can input at once such as if the matrix is almost full. + double availableEnergy = storageCap - getEnergyPostQueue(); + if (energy > availableEnergy) { + //Only allow addition of + energy = availableEnergy; + } + if (!simulate) { + //Increase how much we are inputting + queuedInput += energy; + } + return energy; + } + + public double queueEnergyRemoval(double energy, boolean simulate) { + if (energy < 0) { + //Ensure that the correct queue type gets called + return queueEnergyAddition(-energy, simulate); + } + double remainingOutput = getRemainingOutput(); + if (energy > remainingOutput) { + //If it is more than we can output lower it further + energy = remainingOutput; + } + //Check to see if we are trying to remove more energy than we have to remove, + // as we want to be as accurate as possible with the values we return + // It is possible that the energy we have stored is a lot less than the amount we + // can output at once such as if the matrix is almost empty. + double availableEnergy = getEnergyPostQueue(); + if (energy > availableEnergy) { + //If it is more than we have lower it further + energy = availableEnergy; + } + if (!simulate) { + //Increase how much we are outputting by the amount we accepted + queuedOutput += energy; + } + return energy; + } + + public void queueSetEnergy(double energy) { + if (energy > storageCap) { + energy = storageCap; + } + //TODO: Potentially should allow setting it directly to something bypassing rate limit + // API wise that makes sense, however this is only *really* used by IC2's setStored + double difference = energy - getEnergyPostQueue(); + if (difference != 0) { + //We call addition as values greater than zero are for addition + // The queue methods also ensure that it is using the correct method + // as IC2 changes energy by passing negative values for removal. + // This also adds extra safety in case a mod ends up using the wrong + // method for adding/removing energy. So when it is negative + // queueEnergyAddition will pass it to queueEnergyRemoval + queueEnergyAddition(difference, false); + } + } + + private void addEnergy(World world, double energy) { for (Coord4D coord : cells) { TileEntity tile = coord.getTileEntity(world); - if (tile instanceof TileEntityInductionCell) { TileEntityInductionCell cell = (TileEntityInductionCell) tile; - - cell.setEnergy(0); - - double toAdd = Math.min(cell.getMaxEnergy(), energy); - cell.setEnergy(toAdd); - energy -= toAdd; + double cellEnergy = cell.getEnergy(); + double cellMax = cell.getMaxEnergy(); + if (cellEnergy >= cellMax) { + //Is full + //Should this just be == + continue; + } + double cellSpace = cellMax - cellEnergy; + if (cellSpace >= energy) { + //All fits + cell.setEnergy(cellEnergy + energy); + //This cells data changed, so mark it for saving + MekanismUtils.saveChunk(cell); + break; + } else { + //We have left over so + cell.setEnergy(cellMax); + energy -= cellSpace; + //This cells data changed, so mark it for saving + MekanismUtils.saveChunk(cell); + } } } } -} + + private void removeEnergy(World world, double energy) { + for (Coord4D coord : cells) { + TileEntity tile = coord.getTileEntity(world); + if (tile instanceof TileEntityInductionCell) { + TileEntityInductionCell cell = (TileEntityInductionCell) tile; + double cellEnergy = cell.getEnergy(); + if (cellEnergy == 0) { + //It is already empty + continue; + } + if (cellEnergy >= energy) { + //Can supply it all + cell.setEnergy(cellEnergy - energy); + //This cells data changed, so mark it for saving + MekanismUtils.saveChunk(cell); + break; + } else { + //We need to keep removing from other ones + cell.setEnergy(0); + energy -= cellEnergy; + //This cells data changed, so mark it for saving + MekanismUtils.saveChunk(cell); + } + } + } + } + + public TileNetworkList addStructureData(TileNetworkList data) { + data.add(cachedTotal); + data.add(storageCap); + data.add(transferCap); + data.add(lastInput); + data.add(lastOutput); + + data.add(volWidth); + data.add(volHeight); + data.add(volLength); + + data.add(cells.size()); + data.add(providers.size()); + return data; + } + + public void readStructureData(ByteBuf dataStream) { + cachedTotal = dataStream.readDouble(); + storageCap = dataStream.readDouble(); + transferCap = dataStream.readDouble(); + lastInput = dataStream.readDouble(); + lastOutput = dataStream.readDouble(); + + volWidth = dataStream.readInt(); + volHeight = dataStream.readInt(); + volLength = dataStream.readInt(); + + clientCells = dataStream.readInt(); + clientProviders = dataStream.readInt(); + } + + public double getStorageCap() { + return storageCap; + } + + public double getTransferCap() { + return transferCap; + } + + public double getEnergy() { + return cachedTotal; + } + + public double getLastInput() { + return lastInput; + } + + public double getLastOutput() { + return lastOutput; + } + + public double getRemainingInput() { + return transferCap - queuedInput; + } + + public double getRemainingOutput() { + return transferCap - queuedOutput; + } + + public int getCellCount() { + return cells.isEmpty() ? clientCells : cells.size(); + } + + public int getProviderCount() { + return providers.isEmpty() ? clientProviders : providers.size(); + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/content/tank/TankUpdateProtocol.java b/src/main/java/mekanism/common/content/tank/TankUpdateProtocol.java index 4795c82c5..eb76ef24b 100644 --- a/src/main/java/mekanism/common/content/tank/TankUpdateProtocol.java +++ b/src/main/java/mekanism/common/content/tank/TankUpdateProtocol.java @@ -47,20 +47,20 @@ public class TankUpdateProtocol extends UpdateProtocol { } @Override - protected void mergeCaches(List rejectedItems, MultiblockCache cache, - MultiblockCache merge) { - if (((TankCache) cache).fluid == null) { - ((TankCache) cache).fluid = ((TankCache) merge).fluid; - } else if (((TankCache) merge).fluid != null && ((TankCache) cache).fluid.isFluidEqual(((TankCache) merge).fluid)) { - ((TankCache) cache).fluid.amount += ((TankCache) merge).fluid.amount; + protected void mergeCaches(List rejectedItems, MultiblockCache cache, MultiblockCache merge) { + TankCache tankCache = (TankCache) cache; + TankCache mergeCache = (TankCache) merge; + if (tankCache.fluid == null) { + tankCache.fluid = mergeCache.fluid; + } else if (mergeCache.fluid != null && tankCache.fluid.isFluidEqual(mergeCache.fluid)) { + tankCache.fluid.amount += mergeCache.fluid.amount; } - - ((TankCache) cache).editMode = ((TankCache) merge).editMode; - List rejects = StackUtils.getMergeRejects(((TankCache) cache).inventory, ((TankCache) merge).inventory); + tankCache.editMode = mergeCache.editMode; + List rejects = StackUtils.getMergeRejects(tankCache.inventory, mergeCache.inventory); if (!rejects.isEmpty()) { rejectedItems.addAll(rejects); } - StackUtils.merge(((TankCache) cache).inventory, ((TankCache) merge).inventory); + StackUtils.merge(tankCache.inventory, mergeCache.inventory); } @Override diff --git a/src/main/java/mekanism/common/multiblock/MultiblockManager.java b/src/main/java/mekanism/common/multiblock/MultiblockManager.java index d58aa7bdd..4315293b4 100644 --- a/src/main/java/mekanism/common/multiblock/MultiblockManager.java +++ b/src/main/java/mekanism/common/multiblock/MultiblockManager.java @@ -39,10 +39,10 @@ public class MultiblockManager> { } public static boolean areEqual(TileEntity tile1, TileEntity tile2) { - if (!(tile1 instanceof TileEntityMultiblock) || !(tile2 instanceof TileEntityMultiblock)) { - return false; + if (tile1 instanceof TileEntityMultiblock && tile2 instanceof TileEntityMultiblock) { + return ((TileEntityMultiblock) tile1).getManager() == ((TileEntityMultiblock) tile2).getManager(); } - return ((TileEntityMultiblock) tile1).getManager() == ((TileEntityMultiblock) tile2).getManager(); + return false; } public static void reset() { @@ -89,9 +89,8 @@ public class MultiblockManager> { for (Coord4D obj : entry.getValue().locations) { if (obj.dimensionId == world.provider.getDimension() && obj.exists(world)) { TileEntity tileEntity = obj.getTileEntity(world); - if (!(tileEntity instanceof TileEntityMultiblock) || ((TileEntityMultiblock) tileEntity).getManager() != this || - (getStructureId((TileEntityMultiblock) tileEntity) != null && !Objects.equals(getStructureId((TileEntityMultiblock) tileEntity), inventoryID))) { + (getStructureId(((TileEntityMultiblock) tileEntity)) != null && !Objects.equals(getStructureId(((TileEntityMultiblock) tileEntity)), inventoryID))) { if (!tilesToKill.containsKey(inventoryID)) { tilesToKill.put(inventoryID, new HashSet<>()); } @@ -117,8 +116,8 @@ public class MultiblockManager> { if (!inventories.containsKey(tile.cachedID)) { tile.cachedData.locations.add(Coord4D.get(tile)); inventories.put(tile.cachedID, tile.cachedData); - return; + } else { + inventories.get(tile.cachedID).locations.add(Coord4D.get(tile)); } - inventories.get(tile.cachedID).locations.add(Coord4D.get(tile)); } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/multiblock/UpdateProtocol.java b/src/main/java/mekanism/common/multiblock/UpdateProtocol.java index 8dc5ffebe..b9e3455d7 100644 --- a/src/main/java/mekanism/common/multiblock/UpdateProtocol.java +++ b/src/main/java/mekanism/common/multiblock/UpdateProtocol.java @@ -44,134 +44,89 @@ public abstract class UpdateProtocol> { */ public void loopThrough(Coord4D coord, Deque queue) { int origX = coord.x, origY = coord.y, origZ = coord.z; - - boolean isCorner = true; - boolean isHollow = true; - boolean rightBlocks = true; - boolean rightFrame = true; - - Set locations = new HashSet<>(); - - int xmin = 0, xmax = 0, ymin = 0, ymax = 0, zmin = 0, zmax = 0; - - int x = 0, y = 0, z = 0; - - if ((isViableNode(origX + 1, origY, origZ) && isViableNode(origX - 1, origY, origZ)) || - (isViableNode(origX, origY + 1, origZ) && isViableNode(origX, origY - 1, origZ)) || - (isViableNode(origX, origY, origZ + 1) && isViableNode(origX, origY, origZ - 1))) { - isCorner = false; - } - - if (isCorner) { + if (isCorner(origX, origY, origZ)) { + int xmin = 0, xmax = 0, ymin = 0, ymax = 0, zmin = 0, zmax = 0; if (isViableNode(origX + 1, origY, origZ)) { - while (isViableNode(origX + x + 1, origY, origZ)) { - x++; - } - - xmax = x; + xmax = findViableNode(coord, 1, 0, 0); } else { - while (isViableNode(origX + x - 1, origY, origZ)) { - x--; - } - - xmin = x; + xmin = findViableNode(coord, -1, 0, 0); } - if (isViableNode(origX, origY + 1, origZ)) { - ymin = 0; - - while (isViableNode(origX, origY + y + 1, origZ)) { - y++; - } - - ymax = y; + ymax = findViableNode(coord, 0, 1, 0); } else { - ymax = 0; - - while (isViableNode(origX, origY + y - 1, origZ)) { - y--; - } - - ymin = y; + ymin = findViableNode(coord, 0, -1, 0); } - if (isViableNode(origX, origY, origZ + 1)) { - zmin = 0; - - while (isViableNode(origX, origY, origZ + z + 1)) { - z++; - } - - zmax = z; + zmax = findViableNode(coord, 0, 0, 1); } else { - zmax = 0; - - while (isViableNode(origX, origY, origZ + z - 1)) { - z--; - } - - zmin = z; + zmin = findViableNode(coord, 0, 0, -1); } - for (x = xmin; x <= xmax; x++) { - for (y = ymin; y <= ymax; y++) { - for (z = zmin; z <= zmax; z++) { + Set locations = new HashSet<>(); + boolean isValid = true; + + int minX = origX + xmin; + int maxX = origX + xmax; + int minY = origY + ymin; + int maxY = origY + ymax; + int minZ = origZ + zmin; + int maxZ = origZ + zmax; + for (int x = xmin; x <= xmax; x++) { + int xPos = origX + x; + for (int y = ymin; y <= ymax; y++) { + int yPos = origY + y; + for (int z = zmin; z <= zmax; z++) { + int zPos = origZ + z; if (x == xmin || x == xmax || y == ymin || y == ymax || z == zmin || z == zmax) { - if (!isViableNode(origX + x, origY + y, origZ + z)) { - rightBlocks = false; - break; - } else if (isFrame(coord.translate(x, y, z), origX + xmin, origX + xmax, origY + ymin, - origY + ymax, origZ + zmin, origZ + zmax) && !isValidFrame(origX + x, origY + y, - origZ + z)) { - rightFrame = false; + if (!isViableNode(xPos, yPos, zPos) || + isFrame(coord.translate(x, y, z), minX, maxX, minY, maxY, minZ, maxZ) + && !isValidFrame(xPos, yPos, zPos)) { + //If it is not a valid node or if it is supposed to be a frame but is invalid + // then we are not valid over all + isValid = false; break; } else { locations.add(coord.translate(x, y, z)); } - } else { - if (!isValidInnerNode(origX + x, origY + y, origZ + z)) { - isHollow = false; - break; - } else { - if (!isAir(origX + x, origY + y, origZ + z)) { - innerNodes.add(new Coord4D(origX + x, origY + y, origZ + z, - pointer.getWorld().provider.getDimension())); - } - } + } else if (!isValidInnerNode(xPos, yPos, zPos)) { + isValid = false; + break; + } else if (!isAir(xPos, yPos, zPos)) { + innerNodes.add(new Coord4D(xPos, yPos, zPos, pointer.getWorld().provider.getDimension())); } } - - if (!isHollow || !rightBlocks || !rightFrame) { + if (!isValid) { break; } } - - if (!isHollow || !rightBlocks || !rightFrame) { + if (!isValid) { break; } } - } - if (Math.abs(xmax - xmin) + 1 <= 18 && Math.abs(ymax - ymin) + 1 <= 18 && Math.abs(zmax - zmin) + 1 <= 18) { - if (rightBlocks && rightFrame && isHollow && isCorner) { - T structure = getNewStructure(); - structure.locations = locations; - structure.volLength = Math.abs(xmax - xmin) + 1; - structure.volHeight = Math.abs(ymax - ymin) + 1; - structure.volWidth = Math.abs(zmax - zmin) + 1; - structure.volume = structure.volLength * structure.volHeight * structure.volWidth; - structure.renderLocation = coord.translate(0, 1, 0); - structure.minLocation = coord.translate(xmin, ymin, zmin); - structure.maxLocation = coord.translate(xmax, ymax, zmax); + if (isValid) { + //Check the boolean values before performing other calculations + int length = Math.abs(xmax - xmin) + 1; + int height = Math.abs(ymax - ymin) + 1; + int width = Math.abs(zmax - zmin) + 1; + if (length <= 18 && height <= 18 && width <= 18) { + T structure = getNewStructure(); + structure.locations = locations; + structure.volLength = length; + structure.volHeight = height; + structure.volWidth = width; + structure.volume = structure.volLength * structure.volHeight * structure.volWidth; + structure.renderLocation = coord.translate(0, 1, 0); + structure.minLocation = coord.translate(xmin, ymin, zmin); + structure.maxLocation = coord.translate(xmax, ymax, zmax); - if (structure.volLength >= 3 && structure.volHeight >= 3 && structure.volWidth >= 3) { - onStructureCreated(structure, origX, origY, origZ, xmin, xmax, ymin, ymax, zmin, zmax); - - if (structure.locations.contains(Coord4D.get(pointer)) && isCorrectCorner(coord, origX + xmin, - origY + ymin, origZ + zmin)) { - if (canForm(structure)) { - structureFound = structure; - return; + if (structure.volLength >= 3 && structure.volHeight >= 3 && structure.volWidth >= 3) { + onStructureCreated(structure, origX, origY, origZ, xmin, xmax, ymin, ymax, zmin, zmax); + if (structure.locations.contains(Coord4D.get(pointer)) && isCorrectCorner(coord, minX, minY, minZ)) { + if (canForm(structure)) { + structureFound = structure; + return; + } } } } @@ -187,7 +142,6 @@ public abstract class UpdateProtocol> { for (EnumFacing side : EnumFacing.VALUES) { Coord4D sideCoord = coord.offset(side); - if (isViableNode(sideCoord.getPos())) { if (!iteratedNodes.contains(sideCoord)) { queue.addLast(sideCoord); @@ -214,7 +168,6 @@ public abstract class UpdateProtocol> { } else if (obj.z == zmax) { return EnumFacing.SOUTH; } - return null; } @@ -233,6 +186,37 @@ public abstract class UpdateProtocol> { return isAir(x, y, z); } + /** + * Helper method for reducing duplicate code in loopThrough. + * + * @param orig Starting position + * @param xShift Direction x is being changed, 1 is increasing, 0 means not changing, -1 means decreasing. Only one of xShift, yShift, and zShift should not be 0 + * during any call. A value of 1 also implies that it is a viable node so we start checking at 1 instead of 0. + * @param yShift Direction y is being changed, 1 is increasing, 0 means not changing, -1 means decreasing. Only one of xShift, yShift, and zShift should not be 0 + * during any call. A value of 1 also implies that it is a viable node so we start checking at 1 instead of 0. + * @param zShift Direction z is being changed, 1 is increasing, 0 means not changing, -1 means decreasing. Only one of xShift, yShift, and zShift should not be 0 + * during any call. A value of 1 also implies that it is a viable node so we start checking at 1 instead of 0. + * + * @return x, y, or z depending on which one is not zero. + */ + private int findViableNode(Coord4D orig, int xShift, int yShift, int zShift) { + int x = xShift == 1 ? 1 : 0; + int y = yShift == 1 ? 1 : 0; + int z = zShift == 1 ? 1 : 0; + while (isViableNode(orig.x + x + xShift, orig.y + y + yShift, orig.z + z + zShift)) { + x += xShift; + y += yShift; + z += zShift; + } + return x != 0 ? x : y != 0 ? y : z; + } + + private boolean isCorner(int x, int y, int z) { + return (!isViableNode(x + 1, y, z) || !isViableNode(x - 1, y, z)) && + (!isViableNode(x, y + 1, z) || !isViableNode(x, y - 1, z)) && + (!isViableNode(x, y, z + 1) || !isViableNode(x, y, z - 1)); + } + /** * @param x - x coordinate * @param y - y coordinate @@ -241,15 +225,10 @@ public abstract class UpdateProtocol> { * @return Whether or not the block at the specified location is a viable node for a multiblock structure. */ public boolean isViableNode(int x, int y, int z) { - TileEntity tile = new Coord4D(x, y, z, pointer.getWorld().provider.getDimension()) - .getTileEntity(pointer.getWorld()); - - if (tile instanceof IStructuralMultiblock) { - if (((IStructuralMultiblock) tile).canInterface(pointer)) { - return true; - } + TileEntity tile = new Coord4D(x, y, z, pointer.getWorld().provider.getDimension()).getTileEntity(pointer.getWorld()); + if (tile instanceof IStructuralMultiblock && ((IStructuralMultiblock) tile).canInterface(pointer)) { + return true; } - return MultiblockManager.areEqual(tile, pointer); } @@ -260,20 +239,7 @@ public abstract class UpdateProtocol> { * @return Whether or not the block at the specified location is a viable node for a multiblock structure. */ public boolean isViableNode(BlockPos pos) { - TileEntity tile = new Coord4D(pos, pointer.getWorld()).getTileEntity(pointer.getWorld()); - - if (tile == null || !tile.hasWorld() || tile.isInvalid()) { - return false; - } - - if (tile instanceof IStructuralMultiblock) { - if (((IStructuralMultiblock) tile).canInterface(pointer)) { - return true; - } - } - - return MultiblockManager.areEqual(tile, pointer); - + return isViableNode(pos.getX(), pos.getY(), pos.getZ()); } /** @@ -286,7 +252,6 @@ public abstract class UpdateProtocol> { */ private boolean isCorrectCorner(Coord4D obj, int xmin, int ymin, int zmin) { return obj.x == xmin && obj.y == ymin && obj.z == zmin; - } /** @@ -301,43 +266,10 @@ public abstract class UpdateProtocol> { * @return Whether or not the block at the specified location is considered a frame on the multiblock structure. */ private boolean isFrame(Coord4D obj, int xmin, int xmax, int ymin, int ymax, int zmin, int zmax) { - if (obj.x == xmin && obj.y == ymin) { - return true; - } - if (obj.x == xmax && obj.y == ymin) { - return true; - } - if (obj.x == xmin && obj.y == ymax) { - return true; - } - if (obj.x == xmax && obj.y == ymax) { - return true; - } - - if (obj.x == xmin && obj.z == zmin) { - return true; - } - if (obj.x == xmax && obj.z == zmin) { - return true; - } - if (obj.x == xmin && obj.z == zmax) { - return true; - } - if (obj.x == xmax && obj.z == zmax) { - return true; - } - - if (obj.y == ymin && obj.z == zmin) { - return true; - } - if (obj.y == ymax && obj.z == zmin) { - return true; - } - if (obj.y == ymin && obj.z == zmax) { - return true; - } - return obj.y == ymax && obj.z == zmax; - + boolean xMatches = obj.x == xmin || obj.x == xmax; + boolean yMatches = obj.y == ymin || obj.y == ymax; + boolean zMatches = obj.z == zmin || obj.z == zmax; + return xMatches && yMatches || xMatches && zMatches || yMatches && zMatches; } /** @@ -355,36 +287,28 @@ public abstract class UpdateProtocol> { protected abstract MultiblockManager getManager(); - protected abstract void mergeCaches(List rejectedItems, MultiblockCache cache, - MultiblockCache merge); + protected abstract void mergeCaches(List rejectedItems, MultiblockCache cache, MultiblockCache merge); protected void onFormed() { for (Coord4D coord : structureFound.internalLocations) { TileEntity tile = coord.getTileEntity(pointer.getWorld()); - if (tile instanceof TileEntityInternalMultiblock) { ((TileEntityInternalMultiblock) tile).setMultiblock(structureFound.inventoryID); } } } - protected void onStructureCreated(T structure, int origX, int origY, int origZ, int xmin, int xmax, int ymin, - int ymax, int zmin, int zmax) { + protected void onStructureCreated(T structure, int origX, int origY, int origZ, int xmin, int xmax, int ymin, int ymax, int zmin, int zmax) { } - public void onStructureDestroyed(T structure) { + protected void onStructureDestroyed(T structure) { for (Coord4D coord : structure.internalLocations) { - TileEntity tile = coord.getTileEntity(pointer.getWorld()); - - if (tile instanceof TileEntityInternalMultiblock) { - ((TileEntityInternalMultiblock) tile).setMultiblock(null); - } + killInnerNode(coord); } } - public void killInnerNode(Coord4D coord) { + private void killInnerNode(Coord4D coord) { TileEntity tile = coord.getTileEntity(pointer.getWorld()); - if (tile instanceof TileEntityInternalMultiblock) { ((TileEntityInternalMultiblock) tile).setMultiblock(null); } @@ -408,28 +332,22 @@ public abstract class UpdateProtocol> { if (!structureFound.locations.contains(coord)) { for (Coord4D newCoord : iteratedNodes) { TileEntity tile = newCoord.getTileEntity(pointer.getWorld()); - if (tile instanceof TileEntityMultiblock) { ((TileEntityMultiblock) tile).structure = null; } else if (tile instanceof IStructuralMultiblock) { ((IStructuralMultiblock) tile).setController(null); } } - for (Coord4D newCoord : innerNodes) { killInnerNode(newCoord); } - return; } } List idsFound = new ArrayList<>(); - String idToUse = null; - for (Coord4D obj : structureFound.locations) { TileEntity tileEntity = obj.getTileEntity(pointer.getWorld()); - if (tileEntity instanceof TileEntityMultiblock && ((TileEntityMultiblock) tileEntity).cachedID != null) { idsFound.add(((TileEntityMultiblock) tileEntity).cachedID); @@ -437,9 +355,11 @@ public abstract class UpdateProtocol> { } MultiblockCache cache = getNewCache(); - List rejectedItems = new ArrayList<>(); - - if (!idsFound.isEmpty()) { + String idToUse = null; + if (idsFound.isEmpty()) { + idToUse = getManager().getUniqueInventoryID(); + } else { + List rejectedItems = new ArrayList<>(); for (String id : idsFound) { if (getManager().inventories.get(id) != null) { if (cache == null) { @@ -447,18 +367,14 @@ public abstract class UpdateProtocol> { } else { mergeCaches(rejectedItems, cache, getManager().pullInventory(pointer.getWorld(), id)); } - idToUse = id; } } - } else { - idToUse = getManager().getUniqueInventoryID(); + //TODO someday: drop all items in rejectedItems + //TODO seriously this needs to happen soon + //TODO perhaps drop from pointer? } - //TODO someday: drop all items in rejectedItems - //TODO seriously this needs to happen soon - //TODO perhaps drop from pointer? - cache.apply(structureFound); structureFound.inventoryID = idToUse; @@ -469,10 +385,8 @@ public abstract class UpdateProtocol> { for (Coord4D obj : structureFound.locations) { TileEntity tileEntity = obj.getTileEntity(pointer.getWorld()); - if (tileEntity instanceof TileEntityMultiblock) { ((TileEntityMultiblock) tileEntity).structure = structureFound; - if (toUse == null) { toUse = obj; } @@ -489,21 +403,17 @@ public abstract class UpdateProtocol> { } else { for (Coord4D coord : iteratedNodes) { TileEntity tile = coord.getTileEntity(pointer.getWorld()); - if (tile instanceof TileEntityMultiblock) { TileEntityMultiblock tileEntity = (TileEntityMultiblock) tile; - if (tileEntity.structure != null && !tileEntity.structure.destroyed) { onStructureDestroyed(tileEntity.structure); tileEntity.structure.destroyed = true; } - tileEntity.structure = null; } else if (tile instanceof IStructuralMultiblock) { ((IStructuralMultiblock) tile).setController(null); } } - for (Coord4D coord : innerNodes) { killInnerNode(coord); } @@ -531,11 +441,14 @@ public abstract class UpdateProtocol> { public void loop(Coord4D pos) { iterated.add(pos); + if (!checker.shouldContinue(iterated.size())) { return; } + for (EnumFacing side : EnumFacing.VALUES) { Coord4D coord = pos.offset(side); + if (!iterated.contains(coord) && checker.isValid(coord)) { loop(coord); } diff --git a/src/main/java/mekanism/common/tile/TileEntityEnergyCube.java b/src/main/java/mekanism/common/tile/TileEntityEnergyCube.java index 274e704b3..1bca8992c 100644 --- a/src/main/java/mekanism/common/tile/TileEntityEnergyCube.java +++ b/src/main/java/mekanism/common/tile/TileEntityEnergyCube.java @@ -90,7 +90,6 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements ICo if (MekanismUtils.canFunction(this) && configComponent.isEjecting(TransmissionType.ENERGY)) { CableUtils.emit(this); } - int newScale = getScaledEnergyLevel(20); if (newScale != prevScale) { Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new TileNetworkList())), new Range4D(Coord4D.get(this))); @@ -118,9 +117,6 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements ICo @Override public double getMaxOutput() { - if (tier == EnergyCubeTier.CREATIVE) { - return Integer.MAX_VALUE; - } return tier.getOutput(); } @@ -185,7 +181,7 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements ICo case 2: return new Object[]{getMaxEnergy()}; case 3: - return new Object[]{getMaxEnergy() - getEnergy()}; + return new Object[]{(getMaxEnergy() - getEnergy())}; default: throw new NoSuchMethodException(); } diff --git a/src/main/java/mekanism/common/tile/TileEntityInductionCasing.java b/src/main/java/mekanism/common/tile/TileEntityInductionCasing.java index e08b75bb3..fb087d61e 100644 --- a/src/main/java/mekanism/common/tile/TileEntityInductionCasing.java +++ b/src/main/java/mekanism/common/tile/TileEntityInductionCasing.java @@ -17,7 +17,6 @@ import mekanism.common.network.PacketTileEntity.TileEntityMessage; import mekanism.common.util.ChargeUtils; import mekanism.common.util.InventoryUtils; import mekanism.common.util.LangUtils; -import mekanism.common.util.MekanismUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; @@ -33,8 +32,6 @@ public class TileEntityInductionCasing extends TileEntityMultiblock capability, EnumFacing facing) { - return capability == Capabilities.ENERGY_STORAGE_CAPABILITY - || capability == Capabilities.ENERGY_ACCEPTOR_CAPABILITY - || capability == Capabilities.ENERGY_OUTPUTTER_CAPABILITY - || capability == Capabilities.TESLA_HOLDER_CAPABILITY - || capability == Capabilities.CONFIGURABLE_CAPABILITY + return capability == Capabilities.ENERGY_STORAGE_CAPABILITY || capability == Capabilities.ENERGY_ACCEPTOR_CAPABILITY + || capability == Capabilities.ENERGY_OUTPUTTER_CAPABILITY || capability == Capabilities.TESLA_HOLDER_CAPABILITY + || capability == Capabilities.CONFIGURABLE_CAPABILITY || capability == CapabilityEnergy.ENERGY || (capability == Capabilities.TESLA_CONSUMER_CAPABILITY && sideIsConsumer(facing)) || (capability == Capabilities.TESLA_PRODUCER_CAPABILITY && sideIsOutput(facing)) - || capability == CapabilityEnergy.ENERGY || super.hasCapability(capability, facing); } @Override public T getCapability(@Nonnull Capability capability, EnumFacing facing) { - if (capability == Capabilities.ENERGY_STORAGE_CAPABILITY - || capability == Capabilities.ENERGY_ACCEPTOR_CAPABILITY || - capability == Capabilities.ENERGY_OUTPUTTER_CAPABILITY - || capability == Capabilities.CONFIGURABLE_CAPABILITY) { + if (capability == Capabilities.ENERGY_STORAGE_CAPABILITY || capability == Capabilities.ENERGY_ACCEPTOR_CAPABILITY || + capability == Capabilities.ENERGY_OUTPUTTER_CAPABILITY || capability == Capabilities.CONFIGURABLE_CAPABILITY) { return (T) this; } - - if (capability == Capabilities.TESLA_HOLDER_CAPABILITY - || (capability == Capabilities.TESLA_CONSUMER_CAPABILITY && sideIsConsumer(facing)) + if (capability == Capabilities.TESLA_HOLDER_CAPABILITY || (capability == Capabilities.TESLA_CONSUMER_CAPABILITY && sideIsConsumer(facing)) || (capability == Capabilities.TESLA_PRODUCER_CAPABILITY && sideIsOutput(facing))) { return (T) teslaManager.getWrapper(this, facing); } - if (capability == CapabilityEnergy.ENERGY) { return CapabilityEnergy.ENERGY.cast(forgeEnergyManager.getWrapper(this, facing)); } - return super.getCapability(capability, facing); } @@ -480,8 +410,7 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement @Override public int[] getSlotsForFace(@Nonnull EnumFacing side) { //Inserting into input make it draw power from the item inserted - return (!world.isRemote && structure != null) || (world.isRemote && clientHasStructure) ? mode ? CHARGE_SLOT - : DISCHARGE_SLOT : InventoryUtils.EMPTY; + return (!world.isRemote && structure != null) || (world.isRemote && clientHasStructure) ? mode ? CHARGE_SLOT : DISCHARGE_SLOT : InventoryUtils.EMPTY; } @Override @@ -501,4 +430,9 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement } return super.isCapabilityDisabled(capability, side); } + + @Override + public int getRedstoneLevel() { + return MekanismUtils.redstoneLevelFromContents(getEnergy(), getMaxEnergy()); + } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/tile/TileEntityMultiblock.java b/src/main/java/mekanism/common/tile/TileEntityMultiblock.java index 49f281af5..ba0d51277 100644 --- a/src/main/java/mekanism/common/tile/TileEntityMultiblock.java +++ b/src/main/java/mekanism/common/tile/TileEntityMultiblock.java @@ -75,58 +75,59 @@ public abstract class TileEntityMultiblock> extend if (structure == null) { structure = getNewStructure(); } - if (structure != null && structure.renderLocation != null && clientHasStructure && isRendering) { - if (!prevStructure) { - Mekanism.proxy.doMultiblockSparkle(this, structure.renderLocation.getPos(), structure.volLength, - structure.volWidth, structure.volHeight, tile -> MultiblockManager.areEqual(this, tile)); - } + if (structure != null && structure.renderLocation != null && clientHasStructure && isRendering && !prevStructure) { + Mekanism.proxy.doMultiblockSparkle(this, structure.renderLocation.getPos(), structure.volLength, structure.volWidth, structure.volHeight, + tile -> MultiblockManager.areEqual(this, tile)); } prevStructure = clientHasStructure; } + if (playersUsing.size() > 0 && ((world.isRemote && !clientHasStructure) || (!world.isRemote && structure == null))) { for (EntityPlayer player : playersUsing) { player.closeScreen(); } } + if (!world.isRemote) { if (structure == null) { isRendering = false; if (cachedID != null) { getManager().updateCache(this); } + if (ticker == 5) { + doUpdate(); + } } - if (structure == null && ticker == 5) { - doUpdate(); - } + if (prevStructure == (structure == null)) { - if (structure != null && !getSynchronizedData().hasRenderer) { - getSynchronizedData().hasRenderer = true; + if (structure != null && !structure.hasRenderer) { + structure.hasRenderer = true; isRendering = true; sendStructure = true; } + + Coord4D thisCoord = Coord4D.get(this); for (EnumFacing side : EnumFacing.VALUES) { - Coord4D obj = Coord4D.get(this).offset(side); - if (structure != null && (structure.locations.contains(obj) || structure.internalLocations - .contains(obj))) { + Coord4D obj = thisCoord.offset(side); + if (structure != null && (structure.locations.contains(obj) || structure.internalLocations.contains(obj))) { continue; } TileEntity tile = obj.getTileEntity(world); - if (!obj.isAirBlock(world) && (tile == null || tile.getClass() != getClass()) && - !(tile instanceof IStructuralMultiblock || tile instanceof IMultiblock)) { + if (!obj.isAirBlock(world) && (tile == null || tile.getClass() != getClass()) && !(tile instanceof IStructuralMultiblock || tile instanceof IMultiblock)) { MekanismUtils.notifyNeighborofChange(world, obj, getPos()); } } - Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new TileNetworkList())), new Range4D(Coord4D.get(this))); + Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(thisCoord, getNetworkedData(new TileNetworkList())), new Range4D(thisCoord)); } prevStructure = structure != null; if (structure != null) { - getSynchronizedData().didTick = false; - if (getSynchronizedData().inventoryID != null) { - cachedData.sync(getSynchronizedData()); - cachedID = getSynchronizedData().inventoryID; + structure.didTick = false; + if (structure.inventoryID != null) { + cachedData.sync(structure); + cachedID = structure.inventoryID; getManager().updateCache(this); } } @@ -135,21 +136,21 @@ public abstract class TileEntityMultiblock> extend @Override public void doUpdate() { - if (!world.isRemote && (structure == null || !getSynchronizedData().didTick)) { + if (!world.isRemote && (structure == null || !structure.didTick)) { getProtocol().doUpdate(); if (structure != null) { - getSynchronizedData().didTick = true; + structure.didTick = true; } } } public void sendPacketToRenderer() { if (structure != null) { - for (Coord4D obj : getSynchronizedData().locations) { + for (Coord4D obj : structure.locations) { TileEntityMultiblock tileEntity = (TileEntityMultiblock) obj.getTileEntity(world); if (tileEntity != null && tileEntity.isRendering) { - Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(tileEntity), - tileEntity.getNetworkedData(new TileNetworkList())), new Range4D(Coord4D.get(tileEntity))); + Coord4D tileCoord = Coord4D.get(tileEntity); + Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(tileCoord, tileEntity.getNetworkedData(new TileNetworkList())), new Range4D(tileCoord)); } } } @@ -166,7 +167,6 @@ public abstract class TileEntityMultiblock> extend @Override public TileNetworkList getNetworkedData(TileNetworkList data) { super.getNetworkedData(data); - data.add(isRendering); data.add(structure != null); @@ -176,20 +176,19 @@ public abstract class TileEntityMultiblock> extend data.add(true); - data.add(getSynchronizedData().volHeight); - data.add(getSynchronizedData().volWidth); - data.add(getSynchronizedData().volLength); + data.add(structure.volHeight); + data.add(structure.volWidth); + data.add(structure.volLength); - getSynchronizedData().renderLocation.write(data); - data.add(getSynchronizedData().inventoryID != null);//boolean for if has inv id - if (getSynchronizedData().inventoryID != null) { - data.add(getSynchronizedData().inventoryID); + structure.renderLocation.write(data); + data.add(structure.inventoryID != null);//boolean for if has inv id + if (structure.inventoryID != null) { + data.add(structure.inventoryID); } } else { data.add(false); } } - return data; } @@ -203,17 +202,16 @@ public abstract class TileEntityMultiblock> extend isRendering = dataStream.readBoolean(); clientHasStructure = dataStream.readBoolean(); - if (clientHasStructure && isRendering) { if (dataStream.readBoolean()) { - getSynchronizedData().volHeight = dataStream.readInt(); - getSynchronizedData().volWidth = dataStream.readInt(); - getSynchronizedData().volLength = dataStream.readInt(); - getSynchronizedData().renderLocation = Coord4D.read(dataStream); + structure.volHeight = dataStream.readInt(); + structure.volWidth = dataStream.readInt(); + structure.volLength = dataStream.readInt(); + structure.renderLocation = Coord4D.read(dataStream); if (dataStream.readBoolean()) { - getSynchronizedData().inventoryID = PacketHandler.readString(dataStream); + structure.inventoryID = PacketHandler.readString(dataStream); } else { - getSynchronizedData().inventoryID = null; + structure.inventoryID = null; } } } diff --git a/src/main/java/mekanism/common/util/CableUtils.java b/src/main/java/mekanism/common/util/CableUtils.java index 9634baffe..e7dfe303b 100644 --- a/src/main/java/mekanism/common/util/CableUtils.java +++ b/src/main/java/mekanism/common/util/CableUtils.java @@ -15,6 +15,7 @@ import mekanism.common.base.IEnergyWrapper; import mekanism.common.base.target.EnergyAcceptorTarget; import mekanism.common.capabilities.Capabilities; import mekanism.common.integration.ic2.IC2Integration; +import mekanism.common.tile.TileEntityInductionPort; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; @@ -147,7 +148,12 @@ public final class CableUtils { Set targets = new HashSet<>(); targets.add(target); double sent = EmitUtils.sendToAcceptors(targets, curHandlers, energyToSend); - emitter.setEnergy(emitter.getEnergy() - sent); + if (emitter instanceof TileEntityInductionPort) { + //Streamline sideless removal method for induction port. + ((TileEntityInductionPort) emitter).removeEnergy(sent, false); + } else { + emitter.setEnergy(emitter.getEnergy() - sent); + } } } } diff --git a/src/main/java/mekanism/generators/common/content/turbine/TurbineUpdateProtocol.java b/src/main/java/mekanism/generators/common/content/turbine/TurbineUpdateProtocol.java index db5e08bd0..858e88180 100644 --- a/src/main/java/mekanism/generators/common/content/turbine/TurbineUpdateProtocol.java +++ b/src/main/java/mekanism/generators/common/content/turbine/TurbineUpdateProtocol.java @@ -41,144 +41,135 @@ public class TurbineUpdateProtocol extends UpdateProtocol= Math.ceil((structure.volHeight - 2) / 4)) { - int centerX = structure.minLocation.x + (structure.volLength - 1) / 2; - int centerZ = structure.minLocation.z + (structure.volWidth - 1) / 2; + if (structure.volLength % 2 != 1 || structure.volWidth % 2 != 1) { + return false; + } + int innerRadius = (Math.min(structure.volLength, structure.volWidth) - 3) / 2; + if (innerRadius < Math.ceil((structure.volHeight - 2) / 4)) { + return false; + } + int centerX = structure.minLocation.x + (structure.volLength - 1) / 2; + int centerZ = structure.minLocation.z + (structure.volWidth - 1) / 2; - Coord4D complex = null; + Coord4D complex = null; - Set turbines = new HashSet<>(); - Set dispersers = new HashSet<>(); - Set coils = new HashSet<>(); - Set condensers = new HashSet<>(); + Set turbines = new HashSet<>(); + Set dispersers = new HashSet<>(); + Set coils = new HashSet<>(); + Set condensers = new HashSet<>(); - //Scan for complex - for (Coord4D coord : innerNodes) { - TileEntity tile = coord.getTileEntity(pointer.getWorld()); - - if (tile instanceof TileEntityRotationalComplex) { - if (complex != null) { - return false; - } else if (coord.x != centerX || coord.z != centerZ) { - return false; - } - - structure.internalLocations.add(coord); - complex = coord; - } else if (tile instanceof TileEntityTurbineRotor) { - if (coord.x != centerX || coord.z != centerZ) { - return false; - } - - turbines.add(coord); - } else if (tile instanceof TileEntityPressureDisperser) { - dispersers.add(coord); - } else if (tile instanceof TileEntityElectromagneticCoil) { - coils.add(coord); - } else if (tile instanceof TileEntitySaturatingCondenser) { - condensers.add(coord); - } - } - - //Terminate if complex doesn't exist - if (complex == null) { + //Scan for complex + for (Coord4D coord : innerNodes) { + TileEntity tile = coord.getTileEntity(pointer.getWorld()); + if (tile instanceof TileEntityRotationalComplex) { + if (complex != null || coord.x != centerX || coord.z != centerZ) { return false; } - - //Make sure a flat, horizontal plane of dispersers exists within the multiblock around the complex - for (int x = complex.x - innerRadius; x <= complex.x + innerRadius; x++) { - for (int z = complex.z - innerRadius; z <= complex.z + innerRadius; z++) { - if (!(x == centerX && z == centerZ)) { - TileEntity tile = pointer.getWorld().getTileEntity(new BlockPos(x, complex.y, z)); - if (!(tile instanceof TileEntityPressureDisperser)) { - return false; - } - dispersers.remove(new Coord4D(x, complex.y, z, pointer.getWorld().provider.getDimension())); - } - } - } - - //If any dispersers were not processed, they're in the wrong place - if (dispersers.size() > 0) { + structure.internalLocations.add(coord); + complex = coord; + } else if (tile instanceof TileEntityTurbineRotor) { + if (coord.x != centerX || coord.z != centerZ) { return false; } - - //Make sure all condensers are in proper locations - for (Coord4D coord : condensers) { - if (coord.y <= complex.y) { - return false; - } - } - - structure.condensers = condensers.size(); - - int turbineHeight = 0; - int blades = 0; - - // Starting from the complex, walk down and count the number of rotors/blades in the structure - for (int y = complex.y - 1; y > structure.minLocation.y; y--) { - TileEntity tile = pointer.getWorld().getTileEntity(new BlockPos(centerX, y, centerZ)); - if (tile instanceof TileEntityTurbineRotor) { - TileEntityTurbineRotor rotor = (TileEntityTurbineRotor) tile; - turbineHeight++; - blades += rotor.getHousedBlades(); - structure.internalLocations.add(Coord4D.get(tile)); - turbines.remove(new Coord4D(centerX, y, centerZ, pointer.getWorld().provider.getDimension())); - } else { - // Not a contiguous set of rotors - return false; - } - } - - // If there are any rotors left over, they are in the wrong place in the structure - if (turbines.size() > 0) { - return false; - } - - // Update the structure with number of blades found on rotors - structure.blades = blades; - - Coord4D startCoord = complex.offset(EnumFacing.UP); - - if (startCoord.getTileEntity(pointer.getWorld()) instanceof TileEntityElectromagneticCoil) { - structure.coils = new NodeCounter(new NodeChecker() { - @Override - public boolean isValid(Coord4D coord) { - return coord.getTileEntity(pointer.getWorld()) instanceof TileEntityElectromagneticCoil; - } - }).calculate(startCoord); - } - - if (coils.size() > structure.coils) { - return false; - } - - for (Coord4D coord : structure.locations) { - if (coord.getTileEntity(pointer.getWorld()) instanceof TileEntityTurbineVent) { - if (coord.y >= complex.y) { - structure.vents++; - } else { - return false; - } - } - } - structure.lowerVolume = structure.volLength * structure.volWidth * turbineHeight; - structure.complex = complex; - return true; + turbines.add(coord); + } else if (tile instanceof TileEntityPressureDisperser) { + dispersers.add(coord); + } else if (tile instanceof TileEntityElectromagneticCoil) { + coils.add(coord); + } else if (tile instanceof TileEntitySaturatingCondenser) { + condensers.add(coord); } } - return false; + + //Terminate if complex doesn't exist + if (complex == null) { + return false; + } + + //Make sure a flat, horizontal plane of dispersers exists within the multiblock around the complex + for (int x = complex.x - innerRadius; x <= complex.x + innerRadius; x++) { + for (int z = complex.z - innerRadius; z <= complex.z + innerRadius; z++) { + if (x != centerX || z != centerZ) { + TileEntity tile = pointer.getWorld().getTileEntity(new BlockPos(x, complex.y, z)); + if (!(tile instanceof TileEntityPressureDisperser)) { + return false; + } + dispersers.remove(new Coord4D(x, complex.y, z, pointer.getWorld().provider.getDimension())); + } + } + } + + //If any dispersers were not processed, they're in the wrong place + if (!dispersers.isEmpty()) { + return false; + } + + //Make sure all condensers are in proper locations + for (Coord4D coord : condensers) { + if (coord.y <= complex.y) { + return false; + } + } + + structure.condensers = condensers.size(); + int turbineHeight = 0; + int blades = 0; + + // Starting from the complex, walk down and count the number of rotors/blades in the structure + for (int y = complex.y - 1; y > structure.minLocation.y; y--) { + TileEntity tile = pointer.getWorld().getTileEntity(new BlockPos(centerX, y, centerZ)); + if (tile instanceof TileEntityTurbineRotor) { + TileEntityTurbineRotor rotor = (TileEntityTurbineRotor) tile; + turbineHeight++; + blades += rotor.getHousedBlades(); + structure.internalLocations.add(Coord4D.get(tile)); + turbines.remove(new Coord4D(centerX, y, centerZ, pointer.getWorld().provider.getDimension())); + } else { + // Not a contiguous set of rotors + return false; + } + } + + // If there are any rotors left over, they are in the wrong place in the structure + if (!turbines.isEmpty()) { + return false; + } + + // Update the structure with number of blades found on rotors + structure.blades = blades; + + Coord4D startCoord = complex.offset(EnumFacing.UP); + if (startCoord.getTileEntity(pointer.getWorld()) instanceof TileEntityElectromagneticCoil) { + structure.coils = new NodeCounter(new NodeChecker() { + @Override + public boolean isValid(Coord4D coord) { + return coord.getTileEntity(pointer.getWorld()) instanceof TileEntityElectromagneticCoil; + } + }).calculate(startCoord); + } + + if (coils.size() > structure.coils) { + return false; + } + + for (Coord4D coord : structure.locations) { + if (coord.getTileEntity(pointer.getWorld()) instanceof TileEntityTurbineVent) { + if (coord.y < complex.y) { + return false; + } + structure.vents++; + } + } + structure.lowerVolume = structure.volLength * structure.volWidth * turbineHeight; + structure.complex = complex; + return true; } @Override @@ -197,16 +188,16 @@ public class TurbineUpdateProtocol extends UpdateProtocol rejectedItems, MultiblockCache cache, - MultiblockCache merge) { - if (((TurbineCache) cache).fluid == null) { - ((TurbineCache) cache).fluid = ((TurbineCache) merge).fluid; - } else if (((TurbineCache) merge).fluid != null && ((TurbineCache) cache).fluid - .isFluidEqual(((TurbineCache) merge).fluid)) { - ((TurbineCache) cache).fluid.amount += ((TurbineCache) merge).fluid.amount; + protected void mergeCaches(List rejectedItems, MultiblockCache cache, MultiblockCache merge) { + TurbineCache turbineCache = (TurbineCache) cache; + TurbineCache mergeCache = (TurbineCache) merge; + if (turbineCache.fluid == null) { + turbineCache.fluid = mergeCache.fluid; + } else if (mergeCache.fluid != null && turbineCache.fluid.isFluidEqual(mergeCache.fluid)) { + turbineCache.fluid.amount += mergeCache.fluid.amount; } - ((TurbineCache) cache).electricity += ((TurbineCache) merge).electricity; - ((TurbineCache) cache).dumpMode = ((TurbineCache) merge).dumpMode; + turbineCache.electricity += mergeCache.electricity; + turbineCache.dumpMode = mergeCache.dumpMode; } @Override