Started work on Reactor Logic Adapters

This commit is contained in:
Aidan C. Brady 2015-03-29 12:50:15 -04:00
parent a87fb35c2c
commit 9b1aa2099b
10 changed files with 257 additions and 16 deletions

View file

@ -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();
}

View file

@ -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;
}

View file

@ -607,4 +607,10 @@ public class FusionReactor implements IFusionReactor
{
return null;
}
@Override
public ItemStack[] getInventory()
{
return isFormed() ? controller.inventory : null;
}
}

View file

@ -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;

View file

@ -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);

View file

@ -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<String> ret = new ArrayList<String>();
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");
}
}
}

View file

@ -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;
}
}

View file

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB