Files
Mekanism-Community-Edition/src/main/java/mekanism/common/tile/TileEntityResistiveHeater.java
T
Dave Smith 95ca29fa19 Squashed commit of the following:
commit 0d4dc5991e572793134c0c1af8bb35db528071ad
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 19:25:28 2019 -0500

    IntelliJ inspections, Unused Import

commit c757d3236b6304b1d3295ad392b88677bccf3003
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 19:09:24 2019 -0500

    IntelliJ inspections, Constant conditions & exceptions

commit c63a821ef9fc705941052a876cc1ef950471912e
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 17:41:31 2019 -0500

    IntelliJ inspections, @NotNull/@Nullable problems

commit 506bbfd3241336082b17e5d47f8cec496666dcff
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 16:50:46 2019 -0500

    IntelliJ inspections, Unused label

commit bad10c2428346b5feb1816e4a78d7cc2bc1259f0
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:33:54 2019 -0500

    IntelliJ inspections, Unused assignment

commit bfe633afbfb6380d0f5ee2e8ab14f8981a455681
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:32:02 2019 -0500

    IntelliJ inspections, 'equals()' between objects of inconvertible types

commit 6d179f8639fad1a7c3fa01467c003a8fd309da09
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:29:28 2019 -0500

    IntelliJ inspections, Unused import

commit c21f1cfa5566308237dc8bddb8b79908e272a637
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:25:41 2019 -0500

    IntelliJ inspections, Unused import

commit e5d9e03af582c7315b057861b8f0019e46157dee
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:23:10 2019 -0500

    IntelliJ inspections, Redundant 'throws' clause

commit 1c589ba5740411a5595e9fda177696670bc7b7df
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:21:07 2019 -0500

    IntelliJ inspections, Static member referenced by instance variable

commit 6c17e9ca7fb22a0e285337133659e826f3bfdfee
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:20:02 2019 -0500

    IntelliJ inspections, Catch block may ignore exception

commit 42b3cd788ceb7d6ce657d582bbbd8345a2ec5676
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:16:29 2019 -0500

    IntelliJ inspections, Unnecessary label on 'break' statement

commit f6abc3c66f3aca147edb274720cdb94bff568b0b
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:15:29 2019 -0500

    IntelliJ inspections, Too weak variable type leads to unnecessary cast

commit 6356d1fea8d55907ae1c7b011223fbbc07236c1f
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:11:17 2019 -0500

    IntelliJ inspections, Redundant type cast

commit 559c1a2ff523fd7e23f3750d5c801af73876f1d0
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:04:45 2019 -0500

    IntelliJ inspections, Redundant type arguments

commit ae816ec2a79cf4c8fee776db651a54f68c1dacaa
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:01:27 2019 -0500

    IntelliJ inspections, Redundant Collection operation

commit 1da69b8baff922b98a32163c7d5f90aa77a6a8bc
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:00:55 2019 -0500

    IntelliJ inspections, Redundant array creation

commit 7e3ef81a3597c596d2206c93442e950ac9183de0
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 15:00:11 2019 -0500

    IntelliJ inspections, Condition is covered by further condition

commit f298bbb9f31ecbe935ef6cbf98b56951434a05f8
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:58:10 2019 -0500

    IntelliJ inspections, Redundant 'Collection.addAll()' call

commit ce715c5cd724c4dc71ff2cb53e5bc12f16289f12
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:56:56 2019 -0500

    IntelliJ inspections, 'Collection.toArray()' call style

commit 0bde4b0eb23ac5d8f40a410ed55315e4a422a30c
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:55:40 2019 -0500

    IntelliJ inspections, Calls to 'Arrays.asList()' with too few arguments

commit 6d06d11dcf9c077ed6b216a0bbd61434b10fc610
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:52:26 2019 -0500

    IntelliJ inspections, Pointless arithmetic expression

commit 6501d725af1eda5127489f77fd723396002b29b2
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:42:32 2019 -0500

    IntelliJ inspections, Anonymous type can be replaced with lambda

commit 85341ae5df9d63fb0ad7281c260c77d064adf0c2
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:41:40 2019 -0500

    IntelliJ inspections, Explicit type can be replaced with <>

commit 7e2feae7189b92cb513499aed113d4a2634622c6
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:38:47 2019 -0500

    IntelliJ inspections, Unnecessary 'null' check before method call

commit 2c75a38fe9a969f832cd5777f4fad81ef47d037b
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:37:33 2019 -0500

    IntelliJ inspections, 'switch' statement with too few branches

commit 2e2aff57f7910aef5a68f41a1918e2c8a98509ec
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:34:50 2019 -0500

    IntelliJ inspections, Simplifiable conditional statement

commit 243f6a975f8b3da5e70a5c1a116db2aedd10900e
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:33:09 2019 -0500

    IntelliJ inspections, Duplicate condition in 'if' statement

commit a80c67fc30b737990e7805a8741dce120232badc
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:32:17 2019 -0500

    IntelliJ inspections, Unnecessary semicolon

commit 5a7220ee574c9d38d71db07e4fa995a56fee1eed
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:31:58 2019 -0500

    IntelliJ inspections, Unnecessary enum/interface modifier

commit f3a66f4462033d2f446c2961a1ad8e9cfde3ed36
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:30:36 2019 -0500

    IntelliJ inspections, Unnecessary conversion to String

commit 1662540be864db4669cd80c8c46a9b35be202b62
Author: pupnewfster <[email protected]>
Date:   Thu Mar 7 14:29:33 2019 -0500

    IntelliJ inspections, C styled array declaration
2019-03-07 21:53:20 -07:00

388 lines
8.6 KiB
Java

package mekanism.common.tile;
import io.netty.buffer.ByteBuf;
import mekanism.api.Coord4D;
import mekanism.api.IHeatTransfer;
import mekanism.api.Range4D;
import mekanism.common.Mekanism;
import mekanism.common.base.IRedstoneControl;
import mekanism.common.base.TileNetworkList;
import mekanism.common.block.states.BlockStateMachine.MachineType;
import mekanism.common.capabilities.Capabilities;
import mekanism.common.config.MekanismConfig.general;
import mekanism.common.integration.computer.IComputerIntegration;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.security.ISecurityTile;
import mekanism.common.tile.component.TileComponentSecurity;
import mekanism.common.tile.prefab.TileEntityNoisyBlock;
import mekanism.common.util.CapabilityUtils;
import mekanism.common.util.ChargeUtils;
import mekanism.common.util.HeatUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.common.FMLCommonHandler;
import javax.annotation.Nonnull;
public class TileEntityResistiveHeater extends TileEntityNoisyBlock implements IHeatTransfer, IComputerIntegration, IRedstoneControl, ISecurityTile
{
public double energyUsage = 100;
public double temperature;
public double heatToAbsorb = 0;
/** Whether or not this machine is in it's active state. */
public boolean isActive;
/** The client's current active state. */
public boolean clientActive;
/** How many ticks must pass until this block's active state can sync with the client. */
public int updateDelay;
public float soundScale = 1;
public double lastEnvironmentLoss;
public RedstoneControl controlType = RedstoneControl.DISABLED;
public TileComponentSecurity securityComponent = new TileComponentSecurity(this);
public TileEntityResistiveHeater()
{
super("machine.resistiveheater", "ResistiveHeater", MachineType.RESISTIVE_HEATER.baseEnergy);
inventory = NonNullList.withSize(1, ItemStack.EMPTY);
}
@Override
public void onUpdate()
{
super.onUpdate();
if(world.isRemote && updateDelay > 0)
{
updateDelay--;
if(updateDelay == 0 && clientActive != isActive)
{
isActive = clientActive;
MekanismUtils.updateBlock(world, getPos());
}
}
if(!world.isRemote)
{
boolean packet = false;
if(updateDelay > 0)
{
updateDelay--;
if(updateDelay == 0 && clientActive != isActive)
{
packet = true;
}
}
ChargeUtils.discharge(0, this);
double toUse = 0;
if(MekanismUtils.canFunction(this))
{
toUse = Math.min(getEnergy(), energyUsage);
heatToAbsorb += toUse/general.energyPerHeat;
setEnergy(getEnergy() - toUse);
}
setActive(toUse > 0);
double[] loss = simulateHeat();
applyTemperatureChange();
lastEnvironmentLoss = loss[1];
float newSoundScale = (float)Math.max(0, (toUse/1E5));
if(Math.abs(newSoundScale-soundScale) > 0.01)
{
packet = true;
}
soundScale = newSoundScale;
if(packet)
{
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new TileNetworkList())), new Range4D(Coord4D.get(this)));
}
}
}
@Override
public boolean sideIsConsumer(EnumFacing side)
{
return side == MekanismUtils.getLeft(facing) || side == MekanismUtils.getRight(facing);
}
@Override
public boolean canSetFacing(int side)
{
return side != 0 && side != 1;
}
@Override
public float getInitialVolume()
{
return super.getInitialVolume()*Math.max(0.001F, soundScale);
}
@Override
public void readFromNBT(NBTTagCompound nbtTags)
{
super.readFromNBT(nbtTags);
energyUsage = nbtTags.getDouble("energyUsage");
temperature = nbtTags.getDouble("temperature");
clientActive = isActive = nbtTags.getBoolean("isActive");
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
maxEnergy = energyUsage * 400;
}
@Nonnull
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbtTags)
{
super.writeToNBT(nbtTags);
nbtTags.setDouble("energyUsage", energyUsage);
nbtTags.setDouble("temperature", temperature);
nbtTags.setBoolean("isActive", isActive);
nbtTags.setInteger("controlType", controlType.ordinal());
return nbtTags;
}
@Override
public void handlePacketData(ByteBuf dataStream)
{
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
{
energyUsage = MekanismUtils.convertToJoules(dataStream.readInt());
maxEnergy = energyUsage * 400;
return;
}
super.handlePacketData(dataStream);
if(FMLCommonHandler.instance().getEffectiveSide().isClient())
{
energyUsage = dataStream.readDouble();
temperature = dataStream.readDouble();
clientActive = dataStream.readBoolean();
maxEnergy = dataStream.readDouble();
soundScale = dataStream.readFloat();
controlType = RedstoneControl.values()[dataStream.readInt()];
lastEnvironmentLoss = dataStream.readDouble();
if(updateDelay == 0 && clientActive != isActive)
{
updateDelay = general.UPDATE_DELAY;
isActive = clientActive;
MekanismUtils.updateBlock(world, getPos());
}
}
}
@Override
public TileNetworkList getNetworkedData(TileNetworkList data)
{
super.getNetworkedData(data);
data.add(energyUsage);
data.add(temperature);
data.add(isActive);
data.add(maxEnergy);
data.add(soundScale);
data.add(controlType.ordinal());
data.add(lastEnvironmentLoss);
return data;
}
@Override
public double getTemp()
{
return temperature;
}
@Override
public double getInverseConductionCoefficient()
{
return 5;
}
@Override
public double getInsulationCoefficient(EnumFacing side)
{
return 1000;
}
@Override
public void transferHeatTo(double heat)
{
heatToAbsorb += heat;
}
@Override
public double[] simulateHeat()
{
return HeatUtils.simulate(this);
}
@Override
public double applyTemperatureChange()
{
temperature += heatToAbsorb;
heatToAbsorb = 0;
return temperature;
}
@Override
public boolean canConnectHeat(EnumFacing side)
{
return true;
}
@Override
public IHeatTransfer getAdjacent(EnumFacing side)
{
TileEntity adj = Coord4D.get(this).offset(side).getTileEntity(world);
if(CapabilityUtils.hasCapability(adj, Capabilities.HEAT_TRANSFER_CAPABILITY, side.getOpposite()))
{
return CapabilityUtils.getCapability(adj, Capabilities.HEAT_TRANSFER_CAPABILITY, side.getOpposite());
}
return null;
}
@Override
public boolean hasCapability(@Nonnull Capability<?> capability, EnumFacing side)
{
return capability == Capabilities.HEAT_TRANSFER_CAPABILITY || super.hasCapability(capability, side);
}
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, EnumFacing side)
{
if(capability == Capabilities.HEAT_TRANSFER_CAPABILITY)
{
return (T)this;
}
return super.getCapability(capability, side);
}
@Override
public void setActive(boolean active)
{
isActive = active;
if(clientActive != active && updateDelay == 0)
{
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new TileNetworkList())), new Range4D(Coord4D.get(this)));
updateDelay = 10;
clientActive = active;
}
}
@Override
public boolean getActive()
{
return isActive;
}
@Override
public boolean renderUpdate()
{
return false;
}
@Override
public boolean lightUpdate()
{
return true;
}
private static final String[] methods = new String[] {"getEnergy", "getMaxEnergy", "getTemperature", "setEnergyUsage"};
@Override
public String[] getMethods()
{
return methods;
}
@Override
public Object[] invoke(int method, Object[] arguments) throws Exception
{
switch(method)
{
case 0:
return new Object[] {getEnergy()};
case 1:
return new Object[] {getMaxEnergy()};
case 2:
return new Object[] {temperature};
case 3:
if(arguments.length == 1)
{
if(arguments[0] instanceof Double)
{
energyUsage = (Double)arguments[0];
return new Object[] {"Set energy usage."};
}
}
return new Object[] {"Invalid parameters."};
default:
throw new NoSuchMethodException();
}
}
@Override
public RedstoneControl getControlType()
{
return controlType;
}
@Override
public void setControlType(RedstoneControl type)
{
controlType = type;
}
@Override
public boolean canPulse()
{
return false;
}
@Override
public TileComponentSecurity getSecurity()
{
return securityComponent;
}
}