package com.hbm.tileentity.machine.rbmk; import com.hbm.interfaces.IControlReceiver; import com.hbm.tileentity.machine.rbmk.TileEntityRBMKControlManual.RBMKColor; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; 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; if(this.heat < heatLower) { fauxLevel = this.levelLower; } else if(this.heat > heatUpper) { 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.heatLower; break; //TODO: all this bullshit case QUAD_UP: //AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA //AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA //AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA //this.targetLevel = Math.pow((this.heat - this.heatLower) / 100, 2) * (this.levelUpper - this.levelLower) + this.levelLower; break; case QUAD_DOWN: break; } } this.targetLevel = fauxLevel * 0.01D; } 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 } }