diff --git a/src/main/java/mekanism/api/reactor/IFusionReactor.java b/src/main/java/mekanism/api/reactor/IFusionReactor.java index ef19fc066..ecb2f66e7 100644 --- a/src/main/java/mekanism/api/reactor/IFusionReactor.java +++ b/src/main/java/mekanism/api/reactor/IFusionReactor.java @@ -2,7 +2,7 @@ package mekanism.api.reactor; import mekanism.api.IHeatTransfer; import mekanism.api.gas.GasTank; - +import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidTank; public interface IFusionReactor extends IHeatTransfer @@ -60,4 +60,6 @@ public interface IFusionReactor extends IHeatTransfer public int getSteamPerTick(boolean current); public void updateTemperatures(); + + public ItemStack[] getInventory(); } diff --git a/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java b/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java index 9201df98d..db4f367b0 100644 --- a/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java +++ b/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java @@ -136,6 +136,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i public void handlePacketData(ByteBuf dataStream) { super.handlePacketData(dataStream); + setEnergy(dataStream.readDouble()); } @@ -143,7 +144,9 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i public ArrayList getNetworkedData(ArrayList data) { super.getNetworkedData(data); + data.add(getEnergy()); + return data; } diff --git a/src/main/java/mekanism/generators/common/FusionReactor.java b/src/main/java/mekanism/generators/common/FusionReactor.java index 20897fd37..4a247485b 100644 --- a/src/main/java/mekanism/generators/common/FusionReactor.java +++ b/src/main/java/mekanism/generators/common/FusionReactor.java @@ -607,4 +607,10 @@ public class FusionReactor implements IFusionReactor { return null; } + + @Override + public ItemStack[] getInventory() + { + return isFormed() ? controller.inventory : null; + } } diff --git a/src/main/java/mekanism/generators/common/GeneratorsCommonProxy.java b/src/main/java/mekanism/generators/common/GeneratorsCommonProxy.java index c6ea83c61..63099c4c0 100644 --- a/src/main/java/mekanism/generators/common/GeneratorsCommonProxy.java +++ b/src/main/java/mekanism/generators/common/GeneratorsCommonProxy.java @@ -3,6 +3,7 @@ package mekanism.generators.common; import mekanism.api.MekanismConfig.generators; import mekanism.common.Mekanism; import mekanism.common.inventory.container.ContainerNull; +import mekanism.common.tile.TileEntityContainerBlock; import mekanism.generators.common.inventory.container.ContainerBioGenerator; import mekanism.generators.common.inventory.container.ContainerGasGenerator; import mekanism.generators.common.inventory.container.ContainerHeatGenerator; @@ -20,9 +21,9 @@ import mekanism.generators.common.tile.reactor.TileEntityReactorController; import mekanism.generators.common.tile.reactor.TileEntityReactorFrame; import mekanism.generators.common.tile.reactor.TileEntityReactorGlass; import mekanism.generators.common.tile.reactor.TileEntityReactorLaserFocusMatrix; +import mekanism.generators.common.tile.reactor.TileEntityReactorLogicAdapter; import mekanism.generators.common.tile.reactor.TileEntityReactorNeutronCapture; import mekanism.generators.common.tile.reactor.TileEntityReactorPort; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.tileentity.TileEntity; @@ -49,6 +50,7 @@ public class GeneratorsCommonProxy GameRegistry.registerTileEntity(TileEntityReactorLaserFocusMatrix.class, "ReactorLaserFocus"); GameRegistry.registerTileEntity(TileEntityReactorNeutronCapture.class, "ReactorNeutronCapture"); GameRegistry.registerTileEntity(TileEntityReactorPort.class, "ReactorPort"); + GameRegistry.registerTileEntity(TileEntityReactorLogicAdapter.class, "ReactorLogicAdapter"); } /** @@ -161,9 +163,11 @@ public class GeneratorsCommonProxy case 11: case 12: case 13: - return new ContainerNull(player, (TileEntityReactorController)tileEntity); + return new ContainerNull(player, (TileEntityContainerBlock)tileEntity); case 14: return new ContainerNeutronCapture(player.inventory, (TileEntityReactorNeutronCapture)tileEntity); + case 15: + return new ContainerNull(player, (TileEntityContainerBlock)tileEntity); } return null; diff --git a/src/main/java/mekanism/generators/common/block/BlockReactor.java b/src/main/java/mekanism/generators/common/block/BlockReactor.java index 6976fb9e6..f2ec2d0c2 100644 --- a/src/main/java/mekanism/generators/common/block/BlockReactor.java +++ b/src/main/java/mekanism/generators/common/block/BlockReactor.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Random; import mekanism.api.Coord4D; -import mekanism.client.ClientProxy; import mekanism.common.CTMData; import mekanism.common.ItemAttacher; import mekanism.common.Mekanism; @@ -19,9 +18,9 @@ import mekanism.generators.common.tile.reactor.TileEntityReactorController; import mekanism.generators.common.tile.reactor.TileEntityReactorFrame; import mekanism.generators.common.tile.reactor.TileEntityReactorGlass; import mekanism.generators.common.tile.reactor.TileEntityReactorLaserFocusMatrix; +import mekanism.generators.common.tile.reactor.TileEntityReactorLogicAdapter; import mekanism.generators.common.tile.reactor.TileEntityReactorNeutronCapture; import mekanism.generators.common.tile.reactor.TileEntityReactorPort; - import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; @@ -36,12 +35,10 @@ import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import cpw.mods.fml.common.ModAPIManager; +import buildcraft.api.tools.IToolWrench; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import buildcraft.api.tools.IToolWrench; - public class BlockReactor extends BlockContainer implements IBlockCTM { public IIcon[][] icons = new IIcon[16][16]; @@ -62,11 +59,12 @@ public class BlockReactor extends BlockContainer implements IBlockCTM { if(this == GeneratorsBlocks.Reactor) { - ctms[0][0] = new CTMData("ctm/ReactorFrame", this, Arrays.asList(0, 1, 2, 3)).addSideOverride(ForgeDirection.UP, "ctm/ReactorControllerOff").registerIcons(register); - ctms[0][1] = new CTMData("ctm/ReactorFrame", this, Arrays.asList(0, 1, 2, 3)).addSideOverride(ForgeDirection.UP, "ctm/ReactorControllerOn").registerIcons(register); - ctms[1][0] = new CTMData("ctm/ReactorFrame", this, Arrays.asList(0, 1, 2, 3)).registerIcons(register); - ctms[2][0] = new CTMData("ctm/ReactorNeutronCapture", this, Arrays.asList(0, 1, 2, 3)).registerIcons(register); - ctms[3][0] = new CTMData("ctm/ReactorPort", this, Arrays.asList(0, 1, 2, 3)).registerIcons(register); + ctms[0][0] = new CTMData("ctm/ReactorFrame", this, Arrays.asList(0, 1, 2, 3, 4)).addSideOverride(ForgeDirection.UP, "ctm/ReactorControllerOff").registerIcons(register); + ctms[0][1] = new CTMData("ctm/ReactorFrame", this, Arrays.asList(0, 1, 2, 3, 4)).addSideOverride(ForgeDirection.UP, "ctm/ReactorControllerOn").registerIcons(register); + ctms[1][0] = new CTMData("ctm/ReactorFrame", this, Arrays.asList(0, 1, 2, 3, 4)).registerIcons(register); + ctms[2][0] = new CTMData("ctm/ReactorNeutronCapture", this, Arrays.asList(0, 1, 2, 3, 4)).registerIcons(register); + ctms[3][0] = new CTMData("ctm/ReactorPort", this, Arrays.asList(0, 1, 2, 3, 4)).registerIcons(register); + ctms[4][0] = new CTMData("ctm/ReactorLogicAdapter", this, Arrays.asList(0, 1, 2, 3, 4)).registerIcons(register); icons[0][0] = ctms[0][0].sideOverrides[1].icon; icons[0][1] = ctms[0][1].sideOverrides[1].icon; @@ -74,6 +72,7 @@ public class BlockReactor extends BlockContainer implements IBlockCTM icons[1][0] = ctms[1][0].mainTextureData.icon; icons[2][0] = ctms[2][0].mainTextureData.icon; icons[3][0] = ctms[3][0].mainTextureData.icon; + icons[4][0] = ctms[4][0].mainTextureData.icon; } else if(this == GeneratorsBlocks.ReactorGlass) { @@ -321,9 +320,11 @@ public class BlockReactor extends BlockContainer implements IBlockCTM public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side) { Coord4D obj = new Coord4D(x, y, z).getFromSide(ForgeDirection.getOrientation(side).getOpposite()); + if(this == GeneratorsBlocks.ReactorGlass) { int metadata = obj.getMetadata(world); + switch(metadata) { case 0: @@ -343,7 +344,8 @@ public class BlockReactor extends BlockContainer implements IBlockCTM CONTROLLER(GeneratorsBlocks.Reactor, 0, "ReactorController", 10, TileEntityReactorController.class), FRAME(GeneratorsBlocks.Reactor, 1, "ReactorFrame", -1, TileEntityReactorFrame.class), NEUTRON_CAPTURE(GeneratorsBlocks.Reactor, 2, "ReactorNeutronCapturePlate", 14, TileEntityReactorNeutronCapture.class), - PORT(GeneratorsBlocks.Reactor, 3, "ReactorInOutPort", -1, TileEntityReactorPort.class), + PORT(GeneratorsBlocks.Reactor, 3, "ReactorPort", -1, TileEntityReactorPort.class), + ADAPTER(GeneratorsBlocks.Reactor, 4, "ReactorLogicAdapter", 15, TileEntityReactorLogicAdapter.class), GLASS(GeneratorsBlocks.ReactorGlass, 0, "ReactorGlass", -1, TileEntityReactorGlass.class), LASER_FOCUS_MATRIX(GeneratorsBlocks.ReactorGlass, 1, "ReactorLaserFocusMatrix", -1, TileEntityReactorLaserFocusMatrix.class); diff --git a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLogicAdapter.java b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLogicAdapter.java new file mode 100644 index 000000000..bebdadb75 --- /dev/null +++ b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLogicAdapter.java @@ -0,0 +1,167 @@ +package mekanism.generators.common.tile.reactor; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.List; + +import mekanism.common.util.MekanismUtils; +import net.minecraft.nbt.NBTTagCompound; +import cpw.mods.fml.common.Optional.Method; +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.peripheral.IPeripheral; + +public class TileEntityReactorLogicAdapter extends TileEntityReactorBlock implements IPeripheral +{ + public ReactorLogic logicType; + + public boolean activeCooled; + + @Override + public boolean isFrame() + { + return false; + } + + public boolean checkMode(ReactorLogic type) + { + if(getReactor() == null || !getReactor().isFormed()) + { + return false; + } + + switch(type) + { + case DISABLED: + return false; + case READY: + return getReactor().getPlasmaTemp() >= getReactor().getIgnitionTemperature(activeCooled); + case CAPACITY: + return getReactor().getPlasmaTemp() >= getReactor().getMaxPlasmaTemperature(activeCooled); + case DEPLETED: + return (getReactor().getDeuteriumTank().getStored() < getReactor().getInjectionRate()/2) || + (getReactor().getTritiumTank().getStored() < getReactor().getInjectionRate()/2); + default: + return false; + } + } + + @Override + public void readFromNBT(NBTTagCompound nbtTags) + { + super.readFromNBT(nbtTags); + + logicType = ReactorLogic.values()[nbtTags.getInteger("logicType")]; + activeCooled = nbtTags.getBoolean("activeCooled"); + } + + @Override + public void writeToNBT(NBTTagCompound nbtTags) + { + super.writeToNBT(nbtTags); + + nbtTags.setInteger("logicType", logicType.ordinal()); + nbtTags.setBoolean("activeCooled", activeCooled); + } + + @Override + public void handlePacketData(ByteBuf dataStream) + { + super.handlePacketData(dataStream); + + logicType = ReactorLogic.values()[dataStream.readInt()]; + activeCooled = dataStream.readBoolean(); + } + + @Override + public ArrayList getNetworkedData(ArrayList data) + { + super.getNetworkedData(data); + + data.add(logicType.ordinal()); + data.add(activeCooled); + + return data; + } + + @Override + @Method(modid = "ComputerCraft") + public String getType() + { + return getInventoryName(); + } + + @Override + @Method(modid = "ComputerCraft") + public boolean equals(IPeripheral other) + { + return this == other; + } + + @Override + @Method(modid = "ComputerCraft") + public void attach(IComputerAccess computer) {} + + @Override + @Method(modid = "ComputerCraft") + public void detach(IComputerAccess computer) {} + + @Override + @Method(modid = "ComputerCraft") + public String[] getMethodNames() + { + List ret = new ArrayList(); + + for(ReactorLogic type : ReactorLogic.values()) + { + if(type != ReactorLogic.DISABLED) + { + ret.add(type.name); + } + } + + return (String[])ret.toArray(); + } + + @Override + @Method(modid = "ComputerCraft") + public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException + { + if(method >= 0 && method < ReactorLogic.values().length-1) + { + ReactorLogic type = ReactorLogic.values()[method+1]; + + return new Object[] {checkMode(type)}; + } + else { + return new Object[] {"Unknown command."}; + } + } + + public static enum ReactorLogic + { + DISABLED("disabled"), + READY("ready"), + CAPACITY("capacity"), + DEPLETED("depleted"); + + private String name; + + private ReactorLogic(String s) + { + name = s; + } + + public String getLocalizedName() + { + return MekanismUtils.localize("reactor." + name); + } + + public String getDescription() + { + return MekanismUtils.localize("reactor." + name + ".desc"); + } + } +} diff --git a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorPort.java b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorPort.java index c5588a9de..fde17a63d 100644 --- a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorPort.java +++ b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorPort.java @@ -12,7 +12,8 @@ import mekanism.api.gas.ITubeConnection; import mekanism.api.reactor.IReactorBlock; import mekanism.common.util.CableUtils; import mekanism.common.util.HeatUtils; - +import mekanism.common.util.InventoryUtils; +import mekanism.generators.common.item.ItemHohlraum; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; @@ -280,6 +281,7 @@ public class TileEntityReactorPort extends TileEntityReactorBlock implements IFl { return getReactor().applyTemperatureChange(); } + return 0; } @@ -293,10 +295,64 @@ public class TileEntityReactorPort extends TileEntityReactorBlock implements IFl public IHeatTransfer getAdjacent(ForgeDirection side) { TileEntity adj = Coord4D.get(this).getFromSide(side).getTileEntity(worldObj); + if(adj instanceof IHeatTransfer && !(adj instanceof IReactorBlock)) { return (IHeatTransfer)adj; } + return null; } + + @Override + public ItemStack getStackInSlot(int slotID) + { + return getReactor() != null && getReactor().isFormed() ? getReactor().getInventory()[slotID] : null; + } + + @Override + public void setInventorySlotContents(int slotID, ItemStack itemstack) + { + if(getReactor() != null && getReactor().isFormed()) + { + getReactor().getInventory()[slotID] = itemstack; + + if(itemstack != null && itemstack.stackSize > getInventoryStackLimit()) + { + itemstack.stackSize = getInventoryStackLimit(); + } + } + } + + @Override + public int[] getAccessibleSlotsFromSide(int side) + { + return getReactor() != null && getReactor().isFormed() ? new int[] {0} : InventoryUtils.EMPTY; + } + + @Override + public boolean isItemValidForSlot(int slotID, ItemStack itemstack) + { + if(getReactor() != null && getReactor().isFormed() && itemstack.getItem() instanceof ItemHohlraum) + { + ItemHohlraum hohlraum = (ItemHohlraum)itemstack.getItem(); + + return hohlraum.getGas(itemstack) != null && hohlraum.getGas(itemstack).amount == hohlraum.getMaxGas(itemstack); + } + + return false; + } + + @Override + public boolean canExtractItem(int slotID, ItemStack itemstack, int side) + { + if(getReactor() != null && getReactor().isFormed() && itemstack.getItem() instanceof ItemHohlraum) + { + ItemHohlraum hohlraum = (ItemHohlraum)itemstack.getItem(); + + return hohlraum.getGas(itemstack) == null; + } + + return false; + } } \ No newline at end of file diff --git a/src/main/resources/assets/mekanism/lang/en_US.lang b/src/main/resources/assets/mekanism/lang/en_US.lang index 66d9aadca..539af6057 100644 --- a/src/main/resources/assets/mekanism/lang/en_US.lang +++ b/src/main/resources/assets/mekanism/lang/en_US.lang @@ -814,7 +814,8 @@ tile.Generator.WindTurbine.name=Wind Turbine tile.Reactor.ReactorController.name=Reactor Controller tile.Reactor.ReactorFrame.name=Reactor Frame tile.Reactor.ReactorNeutronCapturePlate.name=Neutron Capture Plate -tile.Reactor.ReactorInOutPort.name=Reactor Port +tile.Reactor.ReactorPort.name=Reactor Port +tile.Reactor.ReactorLogicAdapter.name=Reactor Logic Adapter tile.ReactorGlass.ReactorGlass.name=Reactor Glass tile.ReactorGlass.ReactorLaserFocusMatrix.name=Laser Focus Matrix diff --git a/src/main/resources/assets/mekanism/textures/blocks/ctm/ReactorLogicAdapter-ctm.png b/src/main/resources/assets/mekanism/textures/blocks/ctm/ReactorLogicAdapter-ctm.png new file mode 100644 index 000000000..aba84ffe8 Binary files /dev/null and b/src/main/resources/assets/mekanism/textures/blocks/ctm/ReactorLogicAdapter-ctm.png differ diff --git a/src/main/resources/assets/mekanism/textures/blocks/ctm/ReactorLogicAdapter.png b/src/main/resources/assets/mekanism/textures/blocks/ctm/ReactorLogicAdapter.png new file mode 100644 index 000000000..d230f9811 Binary files /dev/null and b/src/main/resources/assets/mekanism/textures/blocks/ctm/ReactorLogicAdapter.png differ