mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
129 lines
3.5 KiB
Java
129 lines
3.5 KiB
Java
package com.hbm.tileentity.machine.rbmk;
|
|
|
|
import com.hbm.interfaces.IControlReceiver;
|
|
import com.hbm.tileentity.machine.rbmk.TileEntityRBMKConsole.ColumnType;
|
|
import com.hbm.tileentity.machine.rbmk.TileEntityRBMKControlManual.RBMKColor;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.util.MathHelper;
|
|
import net.minecraft.util.Vec3;
|
|
|
|
public class TileEntityRBMKControlAuto extends TileEntityRBMKControl implements IControlReceiver {
|
|
|
|
public RBMKFunction function = RBMKFunction.LINEAR;
|
|
public double levelLower;
|
|
public double levelUpper;
|
|
public double heatLower;
|
|
public double heatUpper;
|
|
|
|
@Override
|
|
public String getName() {
|
|
return "container.rbmkControlAuto";
|
|
}
|
|
|
|
@Override
|
|
public boolean hasPermission(EntityPlayer player) {
|
|
return Vec3.createVectorHelper(xCoord - player.posX, yCoord - player.posY, zCoord - player.posZ).lengthVector() < 20;
|
|
}
|
|
|
|
@Override
|
|
public void updateEntity() {
|
|
|
|
if(!worldObj.isRemote) {
|
|
|
|
double fauxLevel = 0;
|
|
|
|
double lowerBound = Math.min(this.heatLower, this.heatUpper);
|
|
double upperBound = Math.max(this.heatLower, this.heatUpper);
|
|
|
|
if(this.heat < lowerBound) {
|
|
fauxLevel = this.levelLower;
|
|
|
|
} else if(this.heat > upperBound) {
|
|
fauxLevel = this.levelUpper;
|
|
|
|
} else {
|
|
|
|
switch(this.function) {
|
|
case LINEAR:
|
|
// my brain hasn't been this challenged since my math finals in
|
|
// '19
|
|
fauxLevel = (this.heat - this.heatLower) * ((this.levelUpper - this.levelLower) / (this.heatUpper - this.heatLower)) + this.levelLower;
|
|
break;
|
|
|
|
case QUAD_UP:
|
|
// so this is how we roll, huh?
|
|
fauxLevel = Math.pow((this.heat - this.heatLower) / (this.heatUpper - this.heatLower), 2) * (this.levelUpper - this.levelLower) + this.levelLower;
|
|
break;
|
|
case QUAD_DOWN:
|
|
// sometimes my genius is almost frightening
|
|
fauxLevel = Math.pow((this.heat - this.heatUpper) / (this.heatLower - this.heatUpper), 2) * (this.levelLower - this.levelUpper) + this.levelUpper;
|
|
break;
|
|
}
|
|
}
|
|
|
|
this.targetLevel = fauxLevel * 0.01D;
|
|
this.targetLevel = MathHelper.clamp_double(this.targetLevel, 0D, 1D);
|
|
}
|
|
|
|
super.updateEntity();
|
|
}
|
|
|
|
@Override
|
|
public void readFromNBT(NBTTagCompound nbt) {
|
|
super.readFromNBT(nbt);
|
|
|
|
this.levelLower = nbt.getDouble("levelLower");
|
|
this.levelUpper = nbt.getDouble("levelUpper");
|
|
this.heatLower = nbt.getDouble("heatLower");
|
|
this.heatUpper = nbt.getDouble("heatUpper");
|
|
|
|
if(nbt.hasKey("function"))
|
|
this.function = RBMKFunction.values()[nbt.getInteger("function")];
|
|
else
|
|
this.function = null;
|
|
}
|
|
|
|
@Override
|
|
public void writeToNBT(NBTTagCompound nbt) {
|
|
super.writeToNBT(nbt);
|
|
|
|
nbt.setDouble("levelLower", levelLower);
|
|
nbt.setDouble("levelUpper", levelUpper);
|
|
nbt.setDouble("heatLower", heatLower);
|
|
nbt.setDouble("heatUpper", heatUpper);
|
|
|
|
if(function != null)
|
|
nbt.setInteger("function", function.ordinal());
|
|
}
|
|
|
|
@Override
|
|
public void receiveControl(NBTTagCompound data) {
|
|
|
|
if(data.hasKey("function")) {
|
|
int c = Math.abs(data.getInteger("function")) % RBMKColor.values().length;
|
|
this.function = RBMKFunction.values()[c];
|
|
|
|
} else {
|
|
|
|
this.levelLower = data.getDouble("levelLower");
|
|
this.levelUpper = data.getDouble("levelUpper");
|
|
this.heatLower = data.getDouble("heatLower");
|
|
this.heatUpper = data.getDouble("heatUpper");
|
|
}
|
|
|
|
this.markDirty();
|
|
}
|
|
|
|
public static enum RBMKFunction {
|
|
LINEAR,
|
|
QUAD_UP,
|
|
QUAD_DOWN
|
|
}
|
|
|
|
@Override
|
|
public ColumnType getConsoleType() {
|
|
return ColumnType.CONTROL_AUTO;
|
|
}
|
|
} |