New "InternalMultiblock" framework to allow for easier multiblock component management, added "hot" state to superheating elements

This commit is contained in:
aidancbrady 2016-03-22 19:29:18 -04:00
parent 5dcddaf25b
commit e6f4102087
19 changed files with 237 additions and 121 deletions

View file

@ -6,8 +6,9 @@ import mekanism.api.MekanismConfig.general;
import mekanism.client.sound.SoundHandler;
import mekanism.client.voice.VoiceClient;
import mekanism.common.Mekanism;
import mekanism.common.base.IModule;
import mekanism.common.content.boiler.SynchronizedBoilerData;
import mekanism.common.network.PacketKey.KeyMessage;
import mekanism.generators.common.tile.turbine.TileEntityRotationalComplex;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.common.MinecraftForge;
@ -50,7 +51,12 @@ public class MekanismClient extends Mekanism
Mekanism.flamethrowerActive.clear();
Mekanism.activeVibrators.clear();
TileEntityRotationalComplex.clientRotationMap.clear();
SynchronizedBoilerData.clientHotMap.clear();
for(IModule module : Mekanism.modulesLoaded)
{
module.resetClient();
}
SoundHandler.soundMaps.clear();

View file

@ -37,4 +37,9 @@ public interface IModule
* @param dataStream - the incoming ByteBuf of the sync packet
*/
public void readConfig(ByteBuf dataStream) throws IOException;
/**
* Called when the player returns to the main menu.
*/
public void resetClient();
}

View file

@ -18,6 +18,7 @@ import mekanism.common.base.IActiveState;
import mekanism.common.base.IBlockCTM;
import mekanism.common.base.IBoundingBlock;
import mekanism.common.base.ITierItem;
import mekanism.common.content.boiler.SynchronizedBoilerData;
import mekanism.common.content.tank.TankUpdateProtocol;
import mekanism.common.inventory.InventoryBin;
import mekanism.common.item.ItemBlockBasic;
@ -745,6 +746,20 @@ public class BlockBasic extends Block implements IBlockCTM, ICustomBlockIcon
return 12;
}
}
else if(blockType == BasicBlock.BASIC_BLOCK_2)
{
if(metadata == 5)
{
TileEntitySuperheatingElement element = (TileEntitySuperheatingElement)tileEntity;
if(element.multiblockUUID != null && SynchronizedBoilerData.clientHotMap.get(element.multiblockUUID) != null)
{
return SynchronizedBoilerData.clientHotMap.get(element.multiblockUUID) ? 15 : 0;
}
return 0;
}
}
return 0;
}

View file

@ -65,6 +65,7 @@ public class BoilerUpdateProtocol extends UpdateProtocol<SynchronizedBoilerData>
}
else if(tile instanceof TileEntitySuperheatingElement)
{
structure.internalLocations.add(coord);
elements.add(coord);
}
}
@ -221,6 +222,8 @@ public class BoilerUpdateProtocol extends UpdateProtocol<SynchronizedBoilerData>
@Override
protected void onFormed()
{
super.onFormed();
if((structureFound).waterStored != null)
{
(structureFound).waterStored.amount = Math.min((structureFound).waterStored.amount, structureFound.waterVolume*WATER_PER_TANK);

View file

@ -1,6 +1,8 @@
package mekanism.common.content.boiler;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import mekanism.api.Coord4D;
@ -16,6 +18,8 @@ import net.minecraftforge.fluids.FluidStack;
public class SynchronizedBoilerData extends SynchronizedData<SynchronizedBoilerData> implements IHeatTransfer
{
public static Map<String, Boolean> clientHotMap = new HashMap<String, Boolean>();
public static double CASING_INSULATION_COEFFICIENT = 1;
public static double CASING_INVERSE_CONDUCTION_COEFFICIENT = 1;
public static double BASE_BOIL_TEMP = 100-(TemperatureUnit.AMBIENT.zeroOffset-TemperatureUnit.CELSIUS.zeroOffset);
@ -29,6 +33,8 @@ public class SynchronizedBoilerData extends SynchronizedData<SynchronizedBoilerD
public double lastEnvironmentLoss;
public int lastBoilRate;
public int lastMaxBoil;
public boolean clientHot;
public double temperature;

View file

@ -5,7 +5,7 @@ import java.util.List;
import mekanism.api.Coord4D;
import mekanism.api.util.StackUtils;
import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks;
import mekanism.common.block.BlockBasic.BasicType;
import mekanism.common.content.tank.SynchronizedTankData.ValveData;
import mekanism.common.multiblock.MultiblockCache;
import mekanism.common.multiblock.MultiblockManager;
@ -26,7 +26,7 @@ public class TankUpdateProtocol extends UpdateProtocol<SynchronizedTankData>
@Override
protected boolean isValidFrame(int x, int y, int z)
{
return pointer.getWorldObj().getBlock(x, y, z) == MekanismBlocks.BasicBlock && pointer.getWorldObj().getBlockMetadata(x, y, z) == 9;
return BasicType.get(pointer.getWorldObj().getBlock(x, y, z), pointer.getWorldObj().getBlockMetadata(x, y, z)) == BasicType.DYNAMIC_TANK;
}
@Override
@ -72,6 +72,8 @@ public class TankUpdateProtocol extends UpdateProtocol<SynchronizedTankData>
@Override
protected void onFormed()
{
super.onFormed();
if(structureFound.fluidStored != null)
{
structureFound.fluidStored.amount = Math.min(structureFound.fluidStored.amount, structureFound.volume*FLUID_PER_TANK);

View file

@ -31,6 +31,8 @@ public abstract class SynchronizedData<T extends SynchronizedData<T>>
public boolean destroyed;
public Set<Coord4D> internalLocations = new HashSet<Coord4D>();
public ItemStack[] getInventory()
{
return null;

View file

@ -0,0 +1,58 @@
package mekanism.common.multiblock;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import mekanism.common.PacketHandler;
import mekanism.common.tile.TileEntityBasicBlock;
public class TileEntityInternalMultiblock extends TileEntityBasicBlock
{
public String multiblockUUID;
@Override
public void onUpdate() {}
@Override
public boolean canUpdate()
{
return false;
}
@Override
public void handlePacketData(ByteBuf dataStream)
{
super.handlePacketData(dataStream);
if(dataStream.readBoolean())
{
multiblockUUID = PacketHandler.readString(dataStream);
}
else {
multiblockUUID = null;
}
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
super.getNetworkedData(data);
if(multiblockUUID != null)
{
data.add(true);
data.add(multiblockUUID);
}
else {
data.add(false);
}
return data;
}
public void setMultiblock(String id)
{
multiblockUUID = id;
}
}

View file

@ -388,13 +388,43 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
protected abstract void mergeCaches(List<ItemStack> rejectedItems, MultiblockCache<T> cache, MultiblockCache<T> merge);
protected void onFormed() {}
protected void onFormed()
{
for(Coord4D coord : structureFound.internalLocations)
{
TileEntity tile = coord.getTileEntity(pointer.getWorldObj());
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) {}
public void onStructureDestroyed(T structure) {}
public void onStructureDestroyed(T structure)
{
for(Coord4D coord : structure.internalLocations)
{
TileEntity tile = coord.getTileEntity(pointer.getWorldObj());
if(tile instanceof TileEntityInternalMultiblock)
{
((TileEntityInternalMultiblock)tile).setMultiblock(null);
}
}
}
public void killInnerNode(Coord4D coord) {}
public void killInnerNode(Coord4D coord)
{
TileEntity tile = coord.getTileEntity(pointer.getWorldObj());
if(tile instanceof TileEntityInternalMultiblock)
{
((TileEntityInternalMultiblock)tile).setMultiblock(null);
}
}
/**
* Runs the protocol and updates all nodes that make a part of the multiblock.

View file

@ -39,7 +39,7 @@ public class TileEntityBoilerCasing extends TileEntityMultiblock<SynchronizedBoi
public TileEntityBoilerCasing()
{
this("SteamBoiler");
this("BoilerCasing");
}
public TileEntityBoilerCasing(String name)
@ -116,9 +116,13 @@ public class TileEntityBoilerCasing extends TileEntityMultiblock<SynchronizedBoi
data.prevActive = data.activeTicks > 0;
}
if(needsValveUpdate || structure.needsRenderUpdate())
boolean needsHotUpdate = false;
boolean newHot = structure.temperature >= SynchronizedBoilerData.BASE_BOIL_TEMP-0.01F;
if(newHot != structure.clientHot)
{
sendPacketToRenderer();
needsHotUpdate = true;
structure.clientHot = newHot;
}
double[] d = structure.simulateHeat();
@ -155,6 +159,11 @@ public class TileEntityBoilerCasing extends TileEntityMultiblock<SynchronizedBoi
structure.prevWater = structure.waterStored;
structure.prevSteam = structure.steamStored;
if(needsValveUpdate || structure.needsRenderUpdate() || needsHotUpdate)
{
sendPacketToRenderer();
}
MekanismUtils.saveChunk(this);
}
}
@ -239,6 +248,8 @@ public class TileEntityBoilerCasing extends TileEntityMultiblock<SynchronizedBoi
if(isRendering)
{
data.add(structure.clientHot);
Set<ValveData> toSend = new HashSet<ValveData>();
for(ValveData valveData : structure.valves)
@ -298,6 +309,9 @@ public class TileEntityBoilerCasing extends TileEntityMultiblock<SynchronizedBoi
if(isRendering)
{
structure.clientHot = dataStream.readBoolean();
SynchronizedBoilerData.clientHotMap.put(structure.inventoryID, structure.clientHot);
int size = dataStream.readInt();
valveViewing.clear();

View file

@ -7,6 +7,7 @@ import java.util.ArrayList;
import mekanism.api.Coord4D;
import mekanism.api.Range4D;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.multiblock.IMultiblock;
import mekanism.common.multiblock.MultiblockCache;
import mekanism.common.multiblock.MultiblockManager;
@ -192,6 +193,7 @@ public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extend
data.add(getSynchronizedData().volLength);
getSynchronizedData().renderLocation.write(data);
data.add(getSynchronizedData().inventoryID);
}
else {
data.add(false);
@ -223,6 +225,7 @@ public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extend
getSynchronizedData().volLength = dataStream.readInt();
getSynchronizedData().renderLocation = Coord4D.read(dataStream);
getSynchronizedData().inventoryID = PacketHandler.readString(dataStream);
}
}
}

View file

@ -1,13 +1,48 @@
package mekanism.common.tile;
public class TileEntitySuperheatingElement extends TileEntityBasicBlock
import mekanism.common.content.boiler.SynchronizedBoilerData;
import mekanism.common.multiblock.TileEntityInternalMultiblock;
import mekanism.common.util.MekanismUtils;
public class TileEntitySuperheatingElement extends TileEntityInternalMultiblock
{
public boolean prevHot;
@Override
public void setMultiblock(String id)
{
if(id == null && multiblockUUID != null)
{
SynchronizedBoilerData.clientHotMap.remove(multiblockUUID);
}
super.setMultiblock(id);
}
@Override
public boolean canUpdate()
{
return false;
return true;
}
@Override
public void onUpdate() {}
public void onUpdate()
{
if(worldObj.isRemote)
{
boolean newHot = false;
if(multiblockUUID != null && SynchronizedBoilerData.clientHotMap.get(multiblockUUID) != null)
{
newHot = SynchronizedBoilerData.clientHotMap.get(multiblockUUID);
}
if(prevHot != newHot)
{
MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord);
prevHot = newHot;
}
}
}
}

View file

@ -4,7 +4,7 @@ import mekanism.common.Mekanism;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import mekanism.generators.client.model.ModelTurbine;
import mekanism.generators.common.tile.turbine.TileEntityRotationalComplex;
import mekanism.generators.common.content.turbine.SynchronizedTurbineData;
import mekanism.generators.common.tile.turbine.TileEntityTurbineRotor;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
@ -43,9 +43,9 @@ public class RenderTurbineRotor extends TileEntitySpecialRenderer
int baseIndex = tileEntity.clientIndex*2;
float rotateSpeed = 0.0F;
if(tileEntity.multiblockUUID != null && TileEntityRotationalComplex.clientRotationMap.containsKey(tileEntity.multiblockUUID))
if(tileEntity.multiblockUUID != null && SynchronizedTurbineData.clientRotationMap.containsKey(tileEntity.multiblockUUID))
{
rotateSpeed = TileEntityRotationalComplex.clientRotationMap.get(tileEntity.multiblockUUID);
rotateSpeed = SynchronizedTurbineData.clientRotationMap.get(tileEntity.multiblockUUID);
}
if(!Mekanism.proxy.isPaused())

View file

@ -232,6 +232,12 @@ public class MekanismGenerators implements IModule
generators.turbineVentGasFlow = dataStream.readDouble();
generators.turbineDisperserGasFlow = dataStream.readDouble();
}
@Override
public void resetClient()
{
SynchronizedTurbineData.clientRotationMap.clear();
}
@SubscribeEvent
public void onConfigChanged(OnConfigChangedEvent event)

View file

@ -1,11 +1,18 @@
package mekanism.generators.common.content.turbine;
import java.util.HashMap;
import java.util.Map;
import mekanism.api.Coord4D;
import mekanism.common.multiblock.SynchronizedData;
import net.minecraftforge.fluids.FluidStack;
public class SynchronizedTurbineData extends SynchronizedData<SynchronizedTurbineData>
{
public static Map<String, Float> clientRotationMap = new HashMap<String, Float>();
public static final float ROTATION_THRESHOLD = 0.001F;
public FluidStack fluidStored;
public FluidStack prevFluid;
@ -25,6 +32,7 @@ public class SynchronizedTurbineData extends SynchronizedData<SynchronizedTurbin
public int clientDispersers;
public int clientFlow;
public float clientRotation;
public int getDispersers()
{

View file

@ -53,28 +53,6 @@ public class TurbineUpdateProtocol extends UpdateProtocol<SynchronizedTurbineDat
tile instanceof TileEntityPressureDisperser || tile instanceof TileEntityElectromagneticCoil;
}
@Override
public void killInnerNode(Coord4D coord)
{
TileEntity tile = coord.getTileEntity(pointer.getWorldObj());
if(tile instanceof TileEntityRotationalComplex)
{
((TileEntityRotationalComplex)tile).setMultiblock(null);
}
}
@Override
public void onStructureDestroyed(SynchronizedTurbineData structure)
{
TileEntity tile = structure.complex.getTileEntity(pointer.getWorldObj());
if(tile instanceof TileEntityRotationalComplex)
{
((TileEntityRotationalComplex)tile).setMultiblock(null);
}
}
@Override
protected boolean canForm(SynchronizedTurbineData structure)
{
@ -109,6 +87,7 @@ public class TurbineUpdateProtocol extends UpdateProtocol<SynchronizedTurbineDat
return false;
}
structure.internalLocations.add(coord);
complex = coord;
}
else if(tile instanceof TileEntityTurbineRotor)
@ -269,13 +248,13 @@ public class TurbineUpdateProtocol extends UpdateProtocol<SynchronizedTurbineDat
@Override
protected void onFormed()
{
super.onFormed();
if(structureFound.fluidStored != null)
{
structureFound.fluidStored.amount = Math.min(structureFound.fluidStored.amount, structureFound.getFluidCapacity());
}
structureFound.electricityStored = Math.min(structureFound.electricityStored, structureFound.getEnergyCapacity());
((TileEntityRotationalComplex)structureFound.complex.getTileEntity(pointer.getWorldObj())).setMultiblock(structureFound.inventoryID);
}
}

View file

@ -1,77 +1,22 @@
package mekanism.generators.common.tile.turbine;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import mekanism.api.Coord4D;
import mekanism.api.Range4D;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.TileEntityBasicBlock;
import mekanism.common.multiblock.TileEntityInternalMultiblock;
import mekanism.generators.common.content.turbine.SynchronizedTurbineData;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityRotationalComplex extends TileEntityBasicBlock
{
public static Map<String, Float> clientRotationMap = new HashMap<String, Float>();
public static final float ROTATION_THRESHOLD = 0.001F;
public String multiblockUUID;
public float rotation;
public class TileEntityRotationalComplex extends TileEntityInternalMultiblock
{
@Override
public void onUpdate() {}
@Override
public boolean canUpdate()
{
return false;
}
@Override
public void handlePacketData(ByteBuf dataStream)
{
super.handlePacketData(dataStream);
rotation = dataStream.readFloat();
if(dataStream.readBoolean())
{
multiblockUUID = PacketHandler.readString(dataStream);
clientRotationMap.put(multiblockUUID, rotation);
}
else {
multiblockUUID = null;
}
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
super.getNetworkedData(data);
data.add(rotation);
if(multiblockUUID != null)
{
data.add(true);
data.add(multiblockUUID);
}
else {
data.add(false);
}
return data;
}
public void setMultiblock(String id)
{
multiblockUUID = id;
if(id == null && multiblockUUID != null)
{
SynchronizedTurbineData.clientRotationMap.remove(multiblockUUID);
}
super.setMultiblock(id);
Coord4D coord = Coord4D.get(this).getFromSide(ForgeDirection.DOWN);
TileEntity tile = coord.getTileEntity(worldObj);
@ -81,13 +26,4 @@ public class TileEntityRotationalComplex extends TileEntityBasicBlock
((TileEntityTurbineRotor)tile).updateRotors();
}
}
public void setRotation(float newRotation)
{
if(Math.abs(newRotation-rotation) > ROTATION_THRESHOLD)
{
rotation = newRotation;
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this)));
}
}
}

View file

@ -22,12 +22,11 @@ import mekanism.generators.common.content.turbine.SynchronizedTurbineData;
import mekanism.generators.common.content.turbine.TurbineCache;
import mekanism.generators.common.content.turbine.TurbineUpdateProtocol;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
public class TileEntityTurbineCasing extends TileEntityMultiblock<SynchronizedTurbineData> implements IStrictEnergyStorage
{
{
public TileEntityTurbineCasing()
{
this("TurbineCasing");
@ -87,14 +86,16 @@ public class TileEntityTurbineCasing extends TileEntityMultiblock<SynchronizedTu
structure.clientFlow = 0;
}
TileEntity tile = structure.complex.getTileEntity(worldObj);
float newRotation = (float)flowRate;
boolean needsRotationUpdate = false;
if(tile instanceof TileEntityRotationalComplex)
if(Math.abs(newRotation-structure.clientRotation) > SynchronizedTurbineData.ROTATION_THRESHOLD)
{
((TileEntityRotationalComplex)tile).setRotation((float)flowRate);
structure.clientRotation = newRotation;
needsRotationUpdate = true;
}
if(structure.needsRenderUpdate())
if(structure.needsRenderUpdate() || needsRotationUpdate)
{
sendPacketToRenderer();
}
@ -187,6 +188,7 @@ public class TileEntityTurbineCasing extends TileEntityMultiblock<SynchronizedTu
if(isRendering)
{
structure.complex.write(data);
data.add(structure.clientRotation);
}
}
@ -221,6 +223,9 @@ public class TileEntityTurbineCasing extends TileEntityMultiblock<SynchronizedTu
if(isRendering)
{
structure.complex = Coord4D.read(dataStream);
structure.clientRotation = dataStream.readFloat();
SynchronizedTurbineData.clientRotationMap.put(structure.inventoryID, structure.clientRotation);
}
}
}

View file

@ -550,6 +550,9 @@ public class MekanismTools implements IModule
{
tools.armorSpawnRate = dataStream.readDouble();
}
@Override
public void resetClient() {}
@SubscribeEvent
public void onConfigChanged(OnConfigChangedEvent event)