Reactor now auto-forms

This commit is contained in:
Aidan Brady 2014-08-01 00:55:24 -04:00
parent 22db67c895
commit 4090fcf490
14 changed files with 212 additions and 80 deletions

View file

@ -1146,9 +1146,9 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer
if(!world.isRemote)
{
if(tileEntity instanceof TileEntityElectricBlock && MekanismUtils.useIC2())
if(tileEntity instanceof TileEntityBasicBlock)
{
((TileEntityElectricBlock)tileEntity).register();
((TileEntityBasicBlock)tileEntity).onAdded();
}
}
}

View file

@ -239,4 +239,9 @@ public abstract class TileEntityBasicBlock extends TileEntity implements IWrench
}
}
}
public void onAdded()
{
}
}

View file

@ -104,7 +104,9 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
public void onUpdate()
{
if(MekanismUtils.useBuildCraft())
{
reconfigure();
}
}
public EnumSet<ForgeDirection> getOutputtingSides()
@ -157,12 +159,25 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
data.add(getEnergy());
return data;
}
@Override
public void onAdded()
{
super.onAdded();
if(MekanismUtils.useIC2())
{
register();
}
}
@Override
public void onChunkUnload()
{
if(MekanismUtils.useIC2())
{
deregister();
}
super.onChunkUnload();
}
@ -173,7 +188,9 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
super.invalidate();
if(MekanismUtils.useIC2())
{
deregister();
}
}
@Override
@ -184,7 +201,9 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
electricityStored = nbtTags.getDouble("electricityStored");
if(MekanismUtils.useBuildCraft())
{
reconfigure();
}
}
@Override
@ -210,7 +229,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
@Method(modid = "BuildCraftAPI|power")
protected void reconfigure()
{
powerHandler.configure(0, (float)((getMaxEnergy()-getEnergy())* general.TO_BC), 0, (float)(getMaxEnergy()* general.TO_BC));
powerHandler.configure(0, (float)((getMaxEnergy()-getEnergy())*general.TO_BC), 0, (float)(getMaxEnergy()*general.TO_BC));
}
@Override

View file

@ -47,7 +47,7 @@ public class TileEntitySalinationBlock extends TileEntityContainerBlock
if(master != null)
{
master.refresh(true);
master.refresh();
}
}
@ -60,7 +60,7 @@ public class TileEntitySalinationBlock extends TileEntityContainerBlock
{
if(master != null)
{
master.refresh(true);
master.refresh();
}
else {
if(!(this instanceof TileEntitySalinationController))
@ -69,7 +69,7 @@ public class TileEntitySalinationBlock extends TileEntityContainerBlock
if(found != null)
{
found.refresh(true);
found.refresh();
}
}
}

View file

@ -78,7 +78,7 @@ public class TileEntitySalinationController extends TileEntitySalinationBlock
if(ticker == 5)
{
refresh(true);
refresh();
}
updateTemperature();
@ -123,7 +123,7 @@ public class TileEntitySalinationController extends TileEntitySalinationBlock
{
super.onChunkUnload();
refresh(true);
refresh();
}
@Override
@ -131,14 +131,14 @@ public class TileEntitySalinationController extends TileEntitySalinationBlock
{
super.onNeighborChange(block);
refresh(true);
refresh();
}
protected void refresh(boolean canCreate)
protected void refresh()
{
if(!worldObj.isRemote)
{
if((structured || canCreate) && !updatedThisTick)
if(!updatedThisTick)
{
boolean prev = structured;

View file

@ -53,12 +53,12 @@ public class GuiReactorController extends GuiMekanism
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
fontRendererObj.drawString(tileEntity.getInventoryName(), 6, 6, 0x404040);
if(tileEntity.getActive())
{
fontRendererObj.drawString(MekanismUtils.localize("container.reactor.formed"), 8, 16, 0x404040);
}
else
{
else {
fontRendererObj.drawString(MekanismUtils.localize("container.reactor.notFormed"), 8, 16, 0x404040);
}
}
@ -74,25 +74,4 @@ public class GuiReactorController extends GuiMekanism
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
}
@Override
protected void mouseClicked(int x, int y, int button)
{
super.mouseClicked(x, y, button);
if(button == 0)
{
int xAxis = (x - (width - xSize) / 2);
int yAxis = (y - (height - ySize) / 2);
if(xAxis >= 48 && xAxis <= 128 && yAxis >= 5 && yAxis <= 17)
{
ArrayList data = new ArrayList();
data.add(0);
Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data));
SoundHandler.playSound("gui.button.press");
}
}
}
}

View file

@ -161,7 +161,7 @@ public class GuiReactorFuel extends GuiMekanism
int toUse = Math.max(0, Integer.parseInt(injectionRateField.getText()));
ArrayList data = new ArrayList();
data.add(1);
data.add(0);
data.add(toUse);
Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data));

View file

@ -15,9 +15,9 @@ import mekanism.api.reactor.IFusionReactor;
import mekanism.api.reactor.INeutronCapture;
import mekanism.api.reactor.IReactorBlock;
import mekanism.common.Mekanism;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.generators.common.item.ItemHohlraum;
import mekanism.generators.common.tile.reactor.TileEntityReactorController;
import net.minecraft.block.Block;
import net.minecraft.item.ItemCoal;
import net.minecraft.tileentity.TileEntity;
@ -26,7 +26,6 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import static java.lang.Math.min;
import static java.lang.Math.max;
@ -64,6 +63,8 @@ public class FusionReactor implements IFusionReactor
public boolean burning = false;
public boolean activelyCooled = true;
public boolean updatedThisTick;
public boolean formed = false;
@ -90,9 +91,12 @@ public class FusionReactor implements IFusionReactor
{
lastPlasmaTemperature = plasmaTemperature;
lastCaseTemperature = caseTemperature;
return;
}
updatedThisTick = false;
//Only thermal transfer happens unless we're hot enough to burn.
if(plasmaTemperature >= burnTemperature)
{
@ -106,9 +110,7 @@ public class FusionReactor implements IFusionReactor
if(burning)
{
injectFuel();
int fuelBurned = burnFuel();
neutronFlux(fuelBurned);
neutronFlux(burnFuel());
}
}
else {
@ -284,7 +286,7 @@ public class FusionReactor implements IFusionReactor
public void unformMultiblock()
{
for(IReactorBlock block: reactorBlocks)
for(IReactorBlock block : reactorBlocks)
{
block.setReactor(null);
}
@ -294,12 +296,19 @@ public class FusionReactor implements IFusionReactor
reactorBlocks.clear();
neutronCaptors.clear();
formed = false;
if(!controller.getWorldObj().isRemote)
{
Mekanism.packetHandler.sendToDimension(new TileEntityMessage(Coord4D.get(controller), controller.getNetworkedData(new ArrayList())), controller.getWorldObj().provider.dimensionId);
}
}
@Override
public void formMultiblock()
{
Mekanism.logger.trace("Attempting to form multiblock");
updatedThisTick = true;
Mekanism.logger.info("Attempting to form multiblock");
Coord4D controllerPosition = Coord4D.get(controller);
Coord4D centreOfReactor = controllerPosition.getFromSide(ForgeDirection.DOWN, 2);
@ -308,32 +317,38 @@ public class FusionReactor implements IFusionReactor
reactorBlocks.add(controller);
Mekanism.logger.trace("Centre at " + centreOfReactor.toString());
Mekanism.logger.info("Centre at " + centreOfReactor.toString());
if(!createFrame(centreOfReactor))
{
unformMultiblock();
Mekanism.logger.trace("Reactor failed: Frame not complete.");
Mekanism.logger.info("Reactor failed: Frame not complete.");
return;
}
Mekanism.logger.trace("Frame valid");
Mekanism.logger.info("Frame valid");
if(!addSides(centreOfReactor))
{
unformMultiblock();
Mekanism.logger.trace("Reactor failed: Sides not complete.");
Mekanism.logger.info("Reactor failed: Sides not complete.");
return;
}
Mekanism.logger.trace("Side Blocks Valid");
Mekanism.logger.info("Side Blocks Valid");
if(!centreIsClear(centreOfReactor))
{
unformMultiblock();
Mekanism.logger.trace("Blocks in chamber.");
Mekanism.logger.info("Blocks in chamber.");
return;
}
Mekanism.logger.trace("Centre is clear");
Mekanism.logger.info("Centre is clear");
formed = true;
if(!controller.getWorldObj().isRemote)
{
Mekanism.packetHandler.sendToDimension(new TileEntityMessage(Coord4D.get(controller), controller.getNetworkedData(new ArrayList())), controller.getWorldObj().provider.dimensionId);
}
}
public boolean createFrame(Coord4D centre)
@ -387,6 +402,7 @@ public class FusionReactor implements IFusionReactor
{
reactorBlocks.add((IReactorBlock)tile);
((IReactorBlock)tile).setReactor(this);
if(tile instanceof INeutronCapture)
{
neutronCaptors.add((INeutronCapture)tile);

View file

@ -511,9 +511,9 @@ public class BlockGenerator extends BlockContainer implements ISpecialBounds
if(!world.isRemote)
{
if(tileEntity != null && MekanismUtils.useIC2())
if(tileEntity instanceof TileEntityBasicBlock)
{
((TileEntityElectricBlock)tileEntity).register();
((TileEntityBasicBlock)tileEntity).onAdded();
}
}
}

View file

@ -5,6 +5,7 @@ import java.util.Random;
import mekanism.common.ItemAttacher;
import mekanism.common.Mekanism;
import mekanism.common.tile.TileEntityBasicBlock;
import mekanism.common.tile.TileEntityElectricBlock;
import mekanism.common.util.MekanismUtils;
import mekanism.generators.common.GeneratorsBlocks;
@ -123,6 +124,20 @@ public class BlockReactor extends BlockContainer
return i;
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
{
if(!world.isRemote)
{
TileEntity tileEntity = world.getTileEntity(x, y, z);
if(tileEntity instanceof TileEntityBasicBlock)
{
((TileEntityBasicBlock)tileEntity).onNeighborChange(block);
}
}
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int facing, float playerX, float playerY, float playerZ)
{
@ -181,9 +196,6 @@ public class BlockReactor extends BlockContainer
{
entityplayer.openGui(MekanismGenerators.instance, ReactorBlockType.get(this, metadata).guiId, world, x, y, z);
}
else {
((TileEntityReactorController)tileEntity).formMultiblock();
}
return true;
}
@ -246,6 +258,20 @@ public class BlockReactor extends BlockContainer
{
return false;
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
TileEntity tileEntity = world.getTileEntity(x, y, z);
if(!world.isRemote)
{
if(tileEntity instanceof TileEntityBasicBlock)
{
((TileEntityBasicBlock)tileEntity).onAdded();
}
}
}
/*This method is not used, metadata manipulation is required to create a Tile Entity.*/
@Override

View file

@ -1,18 +1,23 @@
package mekanism.generators.common.tile.reactor;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.api.reactor.IFusionReactor;
import mekanism.api.reactor.IReactorBlock;
import mekanism.common.Mekanism;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.TileEntityElectricBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public abstract class TileEntityReactorBlock extends TileEntityElectricBlock implements IReactorBlock
{
public IFusionReactor fusionReactor;
public boolean changed;
public TileEntityReactorBlock()
@ -46,6 +51,8 @@ public abstract class TileEntityReactorBlock extends TileEntityElectricBlock imp
@Override
public void invalidate()
{
super.invalidate();
if(getReactor() != null)
{
getReactor().formMultiblock();
@ -55,32 +62,99 @@ public abstract class TileEntityReactorBlock extends TileEntityElectricBlock imp
@Override
public void onUpdate()
{
super.onUpdate();
if(changed)
{
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
changed = false;
}
}
@Override
public double transferEnergyToAcceptor(ForgeDirection side, double energy)
{
return 0;
}
@Override
public boolean canReceiveEnergy(ForgeDirection side)
{
return false;
}
public EnumSet<ForgeDirection> getOutputtingSides()
{
return EnumSet.noneOf(ForgeDirection.class);
}
@Override
protected EnumSet<ForgeDirection> getConsumingSides()
{
return EnumSet.noneOf(ForgeDirection.class);
}
@Override
public void onChunkUnload()
{
super.onChunkUnload();
if(!(this instanceof TileEntityReactorController) && getReactor() != null)
{
getReactor().formMultiblock();
}
}
@Override
public void onAdded()
{
super.onAdded();
if(!worldObj.isRemote)
{
if(getReactor() != null)
{
getReactor().formMultiblock();
}
else {
if(!(this instanceof TileEntityReactorController))
{
TileEntityReactorController found = new ControllerFinder().find();
if(found != null && (found.getReactor() == null || !found.getReactor().isFormed()))
{
found.formMultiblock();
}
}
}
}
}
public class ControllerFinder
{
public TileEntityReactorController found;
public Set<Coord4D> iterated = new HashSet<Coord4D>();
public void loop(Coord4D pos)
{
if(iterated.size() > 512 || found != null)
{
return;
}
iterated.add(pos);
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
Coord4D coord = pos.getFromSide(side);
if(!iterated.contains(coord) && coord.getTileEntity(worldObj) instanceof TileEntityReactorBlock)
{
if(coord.getTileEntity(worldObj) instanceof TileEntityReactorController)
{
found = (TileEntityReactorController)coord.getTileEntity(worldObj);
return;
}
loop(coord);
}
}
}
public TileEntityReactorController find()
{
loop(Coord4D.get(TileEntityReactorBlock.this));
return found;
}
}
}

View file

@ -11,7 +11,7 @@ import mekanism.common.Mekanism;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.util.MekanismUtils;
import mekanism.generators.common.FusionReactor;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
@ -19,10 +19,8 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
public class TileEntityReactorController extends TileEntityReactorBlock implements IActiveState
@ -41,8 +39,6 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
public AxisAlignedBB box;
public boolean tryForm = false;
public double clientTemp = 0;
public boolean clientBurning = false;
@ -108,12 +104,26 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
clientTemp = getReactor().getPlasmaTemp();
}
}
else if(tryForm && !worldObj.isRemote)
else if(ticker == 5 && !worldObj.isRemote)
{
formMultiblock();
tryForm = false;
}
}
@Override
public void onChunkUnload()
{
super.onChunkUnload();
formMultiblock();
}
@Override
public void onAdded()
{
super.onAdded();
formMultiblock();
}
@Override
@ -153,7 +163,6 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
if(formed)
{
tryForm = true;
setReactor(new FusionReactor(this));
getReactor().setPlasmaTemp(tag.getDouble("plasmaTemp"));
getReactor().setCaseTemp(tag.getDouble("caseTemp"));
@ -201,9 +210,6 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
switch(type)
{
case 0:
formMultiblock();
break;
case 1:
if(getReactor() != null) getReactor().setInjectionRate(dataStream.readInt());
break;
}

View file

@ -17,7 +17,9 @@ public class TileEntityReactorLaserFocusMatrix extends TileEntityReactorBlock im
public void receiveLaserEnergy(double energy, ForgeDirection side)
{
if(getReactor() != null)
{
getReactor().addTemperatureFromEnergyInput(energy);
}
}
@Override

View file

@ -37,6 +37,11 @@ public class TileEntityReactorPort extends TileEntityReactorBlock implements IFl
@Override
public void onUpdate()
{
if(changed)
{
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
}
super.onUpdate();
CableUtils.emit(this);