mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
bug fixes part 2
(both me and radium did testing)
This commit is contained in:
parent
e3cf157501
commit
94c97bc87a
@ -9,6 +9,8 @@ import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import java.nio.BufferOverflowException;
|
||||
|
||||
public class BufPacket implements IMessage {
|
||||
|
||||
int x;
|
||||
@ -16,7 +18,7 @@ public class BufPacket implements IMessage {
|
||||
int z;
|
||||
IBufPacketReceiver rec;
|
||||
ByteBuf buf;
|
||||
|
||||
|
||||
public BufPacket() { }
|
||||
|
||||
public BufPacket(int x, int y, int z, IBufPacketReceiver rec) {
|
||||
@ -43,19 +45,19 @@ public class BufPacket implements IMessage {
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<BufPacket, IMessage> {
|
||||
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(BufPacket m, MessageContext ctx) {
|
||||
|
||||
|
||||
if(Minecraft.getMinecraft().theWorld == null)
|
||||
return null;
|
||||
|
||||
|
||||
TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(m.x, m.y, m.z);
|
||||
|
||||
if(te instanceof IBufPacketReceiver) {
|
||||
|
||||
if (te instanceof IBufPacketReceiver) {
|
||||
((IBufPacketReceiver) te).deserialize(m.buf);
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,18 +32,18 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
|
||||
public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IBufPacketReceiver, IFluidStandardReceiver, IFluidCopiable {
|
||||
|
||||
|
||||
public static final HashSet<FluidType> acceptedFuels = new HashSet();
|
||||
|
||||
|
||||
static {
|
||||
acceptedFuels.add(Fluids.WOODOIL);
|
||||
acceptedFuels.add(Fluids.ETHANOL);
|
||||
acceptedFuels.add(Fluids.FISHOIL);
|
||||
acceptedFuels.add(Fluids.HEAVYOIL);
|
||||
}
|
||||
|
||||
|
||||
public FluidTank tank;
|
||||
|
||||
|
||||
public boolean isOn;
|
||||
public float syncYaw;
|
||||
public float rotationYaw;
|
||||
@ -51,24 +51,24 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
public float syncPitch;
|
||||
public float rotationPitch;
|
||||
public float prevRotationPitch;
|
||||
|
||||
|
||||
// 0: searching, 1: extending, 2: retracting
|
||||
private int state = 0;
|
||||
|
||||
|
||||
private int turnProgress;
|
||||
|
||||
|
||||
public float spin;
|
||||
public float lastSpin;
|
||||
|
||||
|
||||
public TileEntityMachineAutosaw() {
|
||||
this.tank = new FluidTank(Fluids.WOODOIL, 100);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 20 == 0) {
|
||||
if(tank.getFill() > 0) {
|
||||
tank.setFill(tank.getFill() - 1);
|
||||
@ -76,7 +76,7 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
} else {
|
||||
this.isOn = false;
|
||||
}
|
||||
|
||||
|
||||
this.subscribeToAllAround(tank.getTankType(), this);
|
||||
}
|
||||
|
||||
@ -90,13 +90,13 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
lowerArm.rotateAroundY(-(float) Math.toRadians(rotationYaw));
|
||||
Vec3 armTip = Vec3.createVectorHelper(0, 0, -2);
|
||||
armTip.rotateAroundY(-(float) Math.toRadians(rotationYaw));
|
||||
|
||||
|
||||
double cX = pivot.xCoord + upperArm.xCoord + lowerArm.xCoord + armTip.xCoord;
|
||||
double cY = pivot.yCoord;
|
||||
double cZ = pivot.zCoord + upperArm.zCoord + lowerArm.zCoord + armTip.zCoord;
|
||||
|
||||
|
||||
List<EntityLivingBase> affected = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(cX - 1, cY - 0.25, cZ - 1, cX + 1, cY + 0.25, cZ + 1));
|
||||
|
||||
|
||||
for(EntityLivingBase e : affected) {
|
||||
if(e.isEntityAlive() && e.attackEntityFrom(ModDamageSource.turbofan, 100)) {
|
||||
worldObj.playSoundEffect(e.posX, e.posY, e.posZ, "mob.zombie.woodbreak", 2.0F, 0.95F + worldObj.rand.nextFloat() * 0.2F);
|
||||
@ -110,34 +110,34 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, e.posX, e.posY + e.height * 0.5, e.posZ), new TargetPoint(e.dimension, e.posX, e.posY, e.posZ, 50));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(state == 0) {
|
||||
|
||||
|
||||
this.rotationYaw += 1;
|
||||
|
||||
|
||||
if(this.rotationYaw >= 360) {
|
||||
this.rotationYaw -= 360;
|
||||
}
|
||||
|
||||
|
||||
Vec3 grace = Vec3.createVectorHelper(0, 0, -3.5);
|
||||
grace.rotateAroundY(-(float) Math.toRadians(rotationYaw));
|
||||
grace.xCoord += pivot.xCoord;
|
||||
grace.yCoord += pivot.yCoord;
|
||||
grace.zCoord += pivot.zCoord;
|
||||
|
||||
|
||||
Vec3 detector = Vec3.createVectorHelper(0, 0, -9);
|
||||
detector.rotateAroundY(-(float) Math.toRadians(rotationYaw));
|
||||
detector.xCoord += pivot.xCoord;
|
||||
detector.yCoord += pivot.yCoord;
|
||||
detector.zCoord += pivot.zCoord;
|
||||
MovingObjectPosition pos = worldObj.func_147447_a(grace, detector, false, false, false);
|
||||
|
||||
|
||||
if(pos != null && pos.typeOfHit == pos.typeOfHit.BLOCK) {
|
||||
|
||||
|
||||
Block b = worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ);
|
||||
|
||||
|
||||
if(b.getMaterial() == Material.wood || b.getMaterial() == Material.leaves || b.getMaterial() == Material.plants) {
|
||||
|
||||
|
||||
int meta = worldObj.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ);
|
||||
if(!shouldIgnore(b, meta)) {
|
||||
state = 1;
|
||||
@ -156,7 +156,7 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
this.tryInteract(hitX1, hitY, hitZ0);
|
||||
this.tryInteract(hitX0, hitY, hitZ1);
|
||||
this.tryInteract(hitX1, hitY, hitZ1);
|
||||
|
||||
|
||||
if(state == 1) {
|
||||
this.rotationPitch += 2;
|
||||
|
||||
@ -165,31 +165,31 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
state = 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(state == 2) {
|
||||
this.rotationPitch -= 2;
|
||||
|
||||
|
||||
if(this.rotationPitch <= 0) {
|
||||
this.rotationPitch = 0;
|
||||
state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sendStandard(100);
|
||||
} else {
|
||||
|
||||
|
||||
this.lastSpin = this.spin;
|
||||
|
||||
|
||||
if(isOn) {
|
||||
this.spin += 15F;
|
||||
|
||||
|
||||
Vec3 vec = Vec3.createVectorHelper(0.625, 0, 1.625);
|
||||
vec.rotateAroundY(-(float) Math.toRadians(rotationYaw));
|
||||
|
||||
|
||||
worldObj.spawnParticle("smoke", xCoord + 0.5 + vec.xCoord, yCoord + 2.0625, zCoord + 0.5 + vec.zCoord, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
if(this.spin >= 360F) {
|
||||
this.spin -= 360F;
|
||||
this.lastSpin -= 360F;
|
||||
@ -197,7 +197,7 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
|
||||
this.prevRotationYaw = this.rotationYaw;
|
||||
this.prevRotationPitch = this.rotationPitch;
|
||||
|
||||
|
||||
if(this.turnProgress > 0) {
|
||||
double d0 = MathHelper.wrapAngleTo180_double(this.syncYaw - (double) this.rotationYaw);
|
||||
double d1 = MathHelper.wrapAngleTo180_double(this.syncPitch - (double) this.rotationPitch);
|
||||
@ -210,30 +210,30 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Anything additionally that the detector nor the blades should pick up on, like non-mature willows */
|
||||
public static boolean shouldIgnore(Block b, int meta) {
|
||||
if(b == ModBlocks.plant_tall) {
|
||||
return meta == EnumTallFlower.CD2.ordinal() + 8 || meta == EnumTallFlower.CD3.ordinal() + 8;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected void tryInteract(int x, int y, int z) {
|
||||
|
||||
|
||||
Block b = worldObj.getBlock(x, y, z);
|
||||
int meta = worldObj.getBlockMetadata(x, y, z);
|
||||
|
||||
|
||||
if(shouldIgnore(b, meta)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(b.getMaterial() == Material.leaves || b.getMaterial() == Material.plants) {
|
||||
worldObj.func_147480_a(x, y, z, true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(b.getMaterial() == Material.wood) {
|
||||
fellTree(x, y, z);
|
||||
if(state == 1) {
|
||||
@ -241,22 +241,22 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void fellTree(int x, int y, int z) {
|
||||
|
||||
|
||||
if(worldObj.getBlock(x, y - 1, z).getMaterial() == Material.wood) {
|
||||
y--;
|
||||
if(worldObj.getBlock(x, y - 2, z).getMaterial() == Material.wood) {
|
||||
y--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int meta = -1;
|
||||
|
||||
|
||||
for(int i = y; i < y + 10; i++) {
|
||||
|
||||
|
||||
int[][] dir = new int[][] {{0, 0}, {1, 0}, {-1, 0}, {0, 1}, {0, -1}};
|
||||
|
||||
|
||||
for(int[] d : dir) {
|
||||
Block b = worldObj.getBlock(x + d[0], i, z + d[1]);
|
||||
|
||||
@ -268,7 +268,7 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(meta >= 0) {
|
||||
if(Blocks.sapling.canPlaceBlockAt(worldObj, x, y, z)) {
|
||||
worldObj.setBlock(x, y, z, Blocks.sapling, meta, 3);
|
||||
@ -279,8 +279,8 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
buf.writeBoolean(this.isOn);
|
||||
buf.writeFloat(this.syncYaw);
|
||||
buf.writeFloat(this.syncPitch);
|
||||
buf.writeFloat(this.rotationYaw);
|
||||
buf.writeFloat(this.rotationPitch);
|
||||
this.tank.serialize(buf);
|
||||
}
|
||||
|
||||
@ -292,7 +292,7 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
this.turnProgress = 3; //use 3-ply for extra smoothness
|
||||
this.tank.deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
@ -302,7 +302,7 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
this.state = nbt.getInteger("state");
|
||||
this.tank.readFromNBT(nbt, "t");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
@ -322,12 +322,12 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
public FluidTank[] getReceivingTanks() {
|
||||
return new FluidTank[] {tank};
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 12,
|
||||
@ -338,10 +338,10 @@ public class TileEntityMachineAutosaw extends TileEntityLoadedBase implements IB
|
||||
zCoord + 13
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
|
||||
@ -34,19 +34,19 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineCombustionEngine extends TileEntityMachinePolluting implements IEnergyProviderMK2, IFluidStandardTransceiver, IControlReceiver, IGUIProvider, IFluidCopiable {
|
||||
|
||||
|
||||
public boolean isOn = false;
|
||||
public static long maxPower = 2_500_000;
|
||||
public long power;
|
||||
private int playersUsing = 0;
|
||||
public int setting = 0;
|
||||
public boolean wasOn = false;
|
||||
|
||||
|
||||
public float doorAngle = 0;
|
||||
public float prevDoorAngle = 0;
|
||||
|
||||
|
||||
private AudioWrapper audio;
|
||||
|
||||
|
||||
public FluidTank tank;
|
||||
public int tenth = 0;
|
||||
|
||||
@ -62,26 +62,26 @@ public class TileEntityMachineCombustionEngine extends TileEntityMachinePollutin
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
this.tank.loadTank(0, 1, slots);
|
||||
if(this.tank.setType(4, slots)) {
|
||||
this.tenth = 0;
|
||||
}
|
||||
|
||||
|
||||
wasOn = false;
|
||||
|
||||
int fill = tank.getFill() * 10 + tenth;
|
||||
if(isOn && setting > 0 && slots[2] != null && slots[2].getItem() == ModItems.piston_set && fill > 0 && tank.getTankType().hasTrait(FT_Combustible.class)) {
|
||||
EnumPistonType piston = EnumUtil.grabEnumSafely(EnumPistonType.class, slots[2].getItemDamage());
|
||||
FT_Combustible trait = tank.getTankType().getTrait(FT_Combustible.class);
|
||||
|
||||
|
||||
double eff = piston.eff[trait.getGrade().ordinal()];
|
||||
|
||||
|
||||
if(eff > 0) {
|
||||
int speed = setting * 2;
|
||||
|
||||
|
||||
int toBurn = Math.min(fill, speed);
|
||||
this.power += toBurn * (trait.getCombustionEnergy() / 10_000D) * eff;
|
||||
fill -= toBurn;
|
||||
@ -89,46 +89,46 @@ public class TileEntityMachineCombustionEngine extends TileEntityMachinePollutin
|
||||
if(worldObj.getTotalWorldTime() % 5 == 0 && toBurn > 0) {
|
||||
super.pollute(tank.getTankType(), FluidReleaseType.BURN, toBurn * 0.5F);
|
||||
}
|
||||
|
||||
|
||||
if(toBurn > 0) {
|
||||
wasOn = true;
|
||||
}
|
||||
|
||||
|
||||
tank.setFill(fill / 10);
|
||||
tenth = fill % 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setLong("power", Math.min(power, maxPower));
|
||||
|
||||
|
||||
this.power = Library.chargeItemsFromTE(slots, 3, power, power);
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
this.tryProvide(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
this.sendSmoke(pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
|
||||
|
||||
if(power > maxPower)
|
||||
power = maxPower;
|
||||
|
||||
this.networkPackNT(50);
|
||||
|
||||
|
||||
} else {
|
||||
this.prevDoorAngle = this.doorAngle;
|
||||
float swingSpeed = (doorAngle / 10F) + 3;
|
||||
|
||||
|
||||
if(this.playersUsing > 0) {
|
||||
this.doorAngle += swingSpeed;
|
||||
} else {
|
||||
this.doorAngle -= swingSpeed;
|
||||
}
|
||||
|
||||
|
||||
this.doorAngle = MathHelper.clamp_float(this.doorAngle, 0F, 135F);
|
||||
|
||||
if(wasOn) {
|
||||
|
||||
|
||||
if(audio == null) {
|
||||
audio = createAudioLoop();
|
||||
audio.startSound();
|
||||
@ -138,9 +138,9 @@ public class TileEntityMachineCombustionEngine extends TileEntityMachinePollutin
|
||||
|
||||
audio.keepAlive();
|
||||
audio.updateVolume(this.getVolume(1F));
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if(audio != null) {
|
||||
audio.stopSound();
|
||||
audio = null;
|
||||
@ -148,11 +148,11 @@ public class TileEntityMachineCombustionEngine extends TileEntityMachinePollutin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private DirPos[] getConPos() {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
return new DirPos[] {
|
||||
new DirPos(xCoord + dir.offsetX * 1 + rot.offsetX, yCoord, zCoord + dir.offsetZ * 1 + rot.offsetZ, dir),
|
||||
new DirPos(xCoord + dir.offsetX * 1 - rot.offsetX, yCoord, zCoord + dir.offsetZ * 1 - rot.offsetZ, dir),
|
||||
@ -160,7 +160,7 @@ public class TileEntityMachineCombustionEngine extends TileEntityMachinePollutin
|
||||
new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ, dir.getOpposite())
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AudioWrapper createAudioLoop() {
|
||||
return MainRegistry.proxy.getLoopedSound("hbm:block.igeneratorOperate", xCoord, yCoord, zCoord, 1.0F, 10F, 1.0F, 20);
|
||||
@ -200,6 +200,7 @@ public class TileEntityMachineCombustionEngine extends TileEntityMachinePollutin
|
||||
super.serialize(buf);
|
||||
buf.writeInt(this.playersUsing);
|
||||
buf.writeInt(this.setting);
|
||||
buf.writeLong(this.power);
|
||||
buf.writeBoolean(this.isOn);
|
||||
buf.writeBoolean(this.wasOn);
|
||||
tank.serialize(buf);
|
||||
@ -210,6 +211,7 @@ public class TileEntityMachineCombustionEngine extends TileEntityMachinePollutin
|
||||
super.deserialize(buf);
|
||||
this.playersUsing = buf.readInt();
|
||||
this.setting = buf.readInt();
|
||||
this.power = buf.readLong();
|
||||
this.isOn = buf.readBoolean();
|
||||
this.wasOn = buf.readBoolean();
|
||||
tank.deserialize(buf);
|
||||
@ -234,12 +236,12 @@ public class TileEntityMachineCombustionEngine extends TileEntityMachinePollutin
|
||||
tank.writeToNBT(nbt, "tank");
|
||||
nbt.setInteger("tenth", tenth);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
if(!worldObj.isRemote) this.playersUsing++;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
if(!worldObj.isRemote) this.playersUsing--;
|
||||
@ -285,12 +287,12 @@ public class TileEntityMachineCombustionEngine extends TileEntityMachinePollutin
|
||||
public FluidTank[] getSendingTanks() {
|
||||
return this.getSmokeTanks();
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 3,
|
||||
@ -301,10 +303,10 @@ public class TileEntityMachineCombustionEngine extends TileEntityMachinePollutin
|
||||
zCoord + 4
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -320,7 +322,7 @@ public class TileEntityMachineCombustionEngine extends TileEntityMachinePollutin
|
||||
public void receiveControl(NBTTagCompound data) {
|
||||
if(data.hasKey("turnOn")) this.isOn = !this.isOn;
|
||||
if(data.hasKey("setting")) this.setting = data.getInteger("setting");
|
||||
|
||||
|
||||
this.markChanged();
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineMiningLaser extends TileEntityMachineBase implements IEnergyReceiverMK2, IMiningDrill, IFluidStandardSender, IGUIProvider, IUpgradeInfoProvider {
|
||||
|
||||
|
||||
public long power;
|
||||
public int age = 0;
|
||||
public static final long maxPower = 100000000;
|
||||
@ -70,7 +70,7 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
double breakProgress;
|
||||
|
||||
public TileEntityMachineMiningLaser() {
|
||||
|
||||
|
||||
//slot 0: battery
|
||||
//slots 1 - 8: upgrades
|
||||
//slots 9 - 29: output
|
||||
@ -87,31 +87,31 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
this.updateConnections();
|
||||
|
||||
this.sendFluid(tank, worldObj, xCoord + 2, yCoord, zCoord, Library.POS_X);
|
||||
this.sendFluid(tank, worldObj, xCoord - 2, yCoord, zCoord, Library.NEG_X);
|
||||
this.sendFluid(tank, worldObj, xCoord, yCoord + 2, zCoord, Library.POS_Z);
|
||||
this.sendFluid(tank, worldObj, xCoord, yCoord - 2, zCoord, Library.NEG_Z);
|
||||
|
||||
|
||||
power = Library.chargeTEFromItems(slots, 0, power, maxPower);
|
||||
|
||||
|
||||
//reset progress if the position changes
|
||||
if(lastTargetX != targetX ||
|
||||
lastTargetY != targetY ||
|
||||
lastTargetZ != targetZ)
|
||||
breakProgress = 0;
|
||||
|
||||
|
||||
//set last positions for interpolation and the like
|
||||
lastTargetX = targetX;
|
||||
lastTargetY = targetY;
|
||||
lastTargetZ = targetZ;
|
||||
|
||||
|
||||
if(isOn) {
|
||||
|
||||
|
||||
UpgradeManager.eval(slots, 1, 8);
|
||||
int cycles = 1 + UpgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
int speed = 1 + Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 12);
|
||||
@ -120,35 +120,35 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
int consumption = this.consumption
|
||||
- (this.consumption * Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 12) / 16)
|
||||
+ (this.consumption * Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 12) / 16);
|
||||
|
||||
|
||||
for(int i = 0; i < cycles; i++) {
|
||||
|
||||
|
||||
if(power < consumption) {
|
||||
beam = false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
power -= consumption;
|
||||
|
||||
|
||||
if(targetY <= 0)
|
||||
targetY = yCoord - 2;
|
||||
|
||||
|
||||
scan(range);
|
||||
|
||||
|
||||
|
||||
|
||||
Block block = worldObj.getBlock(targetX, targetY, targetZ);
|
||||
|
||||
|
||||
if(block.getMaterial().isLiquid()) {
|
||||
worldObj.setBlockToAir(targetX, targetY, targetZ);
|
||||
buildDam();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if(beam && canBreak(block, targetX, targetY, targetZ)) {
|
||||
|
||||
|
||||
breakProgress += getBreakSpeed(speed);
|
||||
clientBreakProgress = Math.min(breakProgress, 1);
|
||||
|
||||
|
||||
if(breakProgress < 1) {
|
||||
worldObj.destroyBlockInWorldPartially(-1, targetX, targetY, targetZ, (int) Math.floor(breakProgress * 10));
|
||||
} else {
|
||||
@ -166,17 +166,18 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
this.tryFillContainer(xCoord - 2, yCoord, zCoord);
|
||||
this.tryFillContainer(xCoord, yCoord, zCoord + 2);
|
||||
this.tryFillContainer(xCoord, yCoord, zCoord - 2);
|
||||
|
||||
|
||||
this.networkPackNT(250);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateConnections() {
|
||||
this.trySubscribe(worldObj, xCoord, yCoord + 2, zCoord, ForgeDirection.UP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
super.serialize(buf);
|
||||
buf.writeLong(this.power);
|
||||
buf.writeInt(this.lastTargetX);
|
||||
buf.writeInt(this.lastTargetY);
|
||||
@ -213,76 +214,76 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
if(worldObj.getBlock(targetX, targetY, targetZ + 1).getMaterial().isLiquid()) worldObj.setBlock(targetX, targetY, targetZ + 1, ModBlocks.barricade);
|
||||
if(worldObj.getBlock(targetX, targetY, targetZ - 1).getMaterial().isLiquid()) worldObj.setBlock(targetX, targetY, targetZ - 1, ModBlocks.barricade);
|
||||
}
|
||||
|
||||
|
||||
private void tryFillContainer(int x, int y, int z) {
|
||||
|
||||
|
||||
Block b = worldObj.getBlock(x, y, z);
|
||||
if(b != Blocks.chest && b != Blocks.trapped_chest && b != ModBlocks.crate_iron && b != ModBlocks.crate_desh &&
|
||||
b != ModBlocks.crate_steel && b != ModBlocks.safe && b != Blocks.hopper)
|
||||
return;
|
||||
|
||||
|
||||
IInventory inventory = (IInventory)worldObj.getTileEntity(x, y, z);
|
||||
if(inventory == null)
|
||||
return;
|
||||
|
||||
|
||||
for(int i = 9; i <= 29; i++) {
|
||||
|
||||
|
||||
if(slots[i] != null) {
|
||||
int prev = slots[i].stackSize;
|
||||
slots[i] = InventoryUtil.tryAddItemToInventory(inventory, 0, inventory.getSizeInventory() - 1, slots[i]);
|
||||
|
||||
|
||||
if(slots[i] == null || slots[i].stackSize < prev)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void breakBlock(int fortune) {
|
||||
|
||||
|
||||
Block b = worldObj.getBlock(targetX, targetY, targetZ);
|
||||
int meta = worldObj.getBlockMetadata(targetX, targetY, targetZ);
|
||||
boolean normal = true;
|
||||
boolean doesBreak = true;
|
||||
|
||||
|
||||
if(b == Blocks.lit_redstone_ore)
|
||||
b = Blocks.redstone_ore;
|
||||
|
||||
|
||||
ItemStack stack = new ItemStack(b, 1, meta);
|
||||
|
||||
|
||||
if(stack != null && stack.getItem() != null) {
|
||||
if(hasCrystallizer()) {
|
||||
|
||||
CrystallizerRecipe result = CrystallizerRecipes.getOutput(stack, Fluids.PEROXIDE);
|
||||
if(result == null) result = CrystallizerRecipes.getOutput(stack, Fluids.SULFURIC_ACID);
|
||||
|
||||
|
||||
if(result != null) {
|
||||
worldObj.spawnEntityInWorld(new EntityItem(worldObj, targetX + 0.5, targetY + 0.5, targetZ + 0.5, result.output.copy()));
|
||||
normal = false;
|
||||
}
|
||||
|
||||
|
||||
} else if(hasCentrifuge()) {
|
||||
|
||||
|
||||
ItemStack[] result = CentrifugeRecipes.getOutput(stack);
|
||||
if(result != null) {
|
||||
for(ItemStack sta : result) {
|
||||
|
||||
|
||||
if(sta != null) {
|
||||
worldObj.spawnEntityInWorld(new EntityItem(worldObj, targetX + 0.5, targetY + 0.5, targetZ + 0.5, sta.copy()));
|
||||
normal = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else if(hasShredder()) {
|
||||
|
||||
|
||||
ItemStack result = ShredderRecipes.getShredderResult(stack);
|
||||
if(result != null && result.getItem() != ModItems.scrap) {
|
||||
worldObj.spawnEntityInWorld(new EntityItem(worldObj, targetX + 0.5, targetY + 0.5, targetZ + 0.5, result.copy()));
|
||||
normal = false;
|
||||
}
|
||||
|
||||
|
||||
} else if(hasSmelter()) {
|
||||
|
||||
|
||||
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(stack);
|
||||
if(result != null) {
|
||||
worldObj.spawnEntityInWorld(new EntityItem(worldObj, targetX + 0.5, targetY + 0.5, targetZ + 0.5, result.copy()));
|
||||
@ -290,32 +291,32 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(normal && b instanceof IDrillInteraction) {
|
||||
IDrillInteraction in = (IDrillInteraction) b;
|
||||
ItemStack drop = in.extractResource(worldObj, targetX, targetY, targetZ, meta, this);
|
||||
|
||||
|
||||
if(drop != null) {
|
||||
worldObj.spawnEntityInWorld(new EntityItem(worldObj, targetX + 0.5, targetY + 0.5, targetZ + 0.5, drop.copy()));
|
||||
}
|
||||
|
||||
|
||||
doesBreak = in.canBreak(worldObj, targetX, targetY, targetZ, meta, this);
|
||||
}
|
||||
|
||||
|
||||
if(doesBreak) {
|
||||
if(normal) b.dropBlockAsItem(worldObj, targetX, targetY, targetZ, meta, fortune);
|
||||
worldObj.func_147480_a(targetX, targetY, targetZ, false);
|
||||
}
|
||||
|
||||
|
||||
suckDrops();
|
||||
|
||||
if(doesScream()) {
|
||||
worldObj.playSoundEffect(targetX + 0.5, targetY + 0.5, targetZ + 0.5, "hbm:block.screm", 2000.0F, 1.0F);
|
||||
}
|
||||
|
||||
|
||||
breakProgress = 0;
|
||||
}
|
||||
|
||||
|
||||
private static final Set<Item> bad = Sets.newHashSet(new Item[] {
|
||||
Item.getItemFromBlock(Blocks.dirt),
|
||||
Item.getItemFromBlock(Blocks.stone),
|
||||
@ -329,14 +330,14 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
Items.snowball,
|
||||
Items.wheat_seeds
|
||||
});
|
||||
|
||||
|
||||
//hahahahahahahaha he said "suck"
|
||||
private void suckDrops() {
|
||||
|
||||
|
||||
int rangeHor = 3;
|
||||
int rangeVer = 1;
|
||||
boolean nullifier = hasNullifier();
|
||||
|
||||
|
||||
List<EntityItem> items = worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(
|
||||
targetX + 0.5 - rangeHor,
|
||||
targetY + 0.5 - rangeVer,
|
||||
@ -345,36 +346,36 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
targetY + 0.5 + rangeVer,
|
||||
targetZ + 0.5 + rangeHor
|
||||
));
|
||||
|
||||
|
||||
for(EntityItem item : items) {
|
||||
|
||||
|
||||
if(item.isDead) continue;
|
||||
|
||||
|
||||
if(nullifier && bad.contains(item.getEntityItem().getItem())) {
|
||||
item.setDead();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if(item.getEntityItem().getItem() == Item.getItemFromBlock(ModBlocks.ore_oil)) {
|
||||
|
||||
|
||||
tank.setTankType(Fluids.OIL); //just to be sure
|
||||
|
||||
|
||||
tank.setFill(tank.getFill() + 500);
|
||||
if(tank.getFill() > tank.getMaxFill())
|
||||
tank.setFill(tank.getMaxFill());
|
||||
|
||||
|
||||
item.setDead();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
ItemStack stack = InventoryUtil.tryAddItemToInventory(slots, 9, 29, item.getEntityItem().copy());
|
||||
|
||||
|
||||
if(stack == null)
|
||||
item.setDead();
|
||||
else
|
||||
item.setEntityItemStack(stack.copy()); //copy is not necessary but i'm paranoid due to the kerfuffle of the old drill
|
||||
}
|
||||
|
||||
|
||||
List<EntityLivingBase> mobs = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(
|
||||
targetX + 0.5 - 1,
|
||||
targetY + 0.5 - 1,
|
||||
@ -383,31 +384,31 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
targetY + 0.5 + 1,
|
||||
targetZ + 0.5 + 1
|
||||
));
|
||||
|
||||
|
||||
for(EntityLivingBase mob : mobs) {
|
||||
mob.setFire(5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public double getBreakSpeed(int speed) {
|
||||
|
||||
|
||||
float hardness = worldObj.getBlock(targetX, targetY, targetZ).getBlockHardness(worldObj, targetX, targetY, targetZ) * 15 / speed;
|
||||
|
||||
|
||||
if(hardness == 0)
|
||||
return 1;
|
||||
|
||||
|
||||
return 1 / hardness;
|
||||
}
|
||||
|
||||
|
||||
public void scan(int range) {
|
||||
|
||||
|
||||
for(int x = -range; x <= range; x++) {
|
||||
for(int z = -range; z <= range; z++) {
|
||||
|
||||
|
||||
if(worldObj.getBlock(x + xCoord, targetY, z + zCoord).getMaterial().isLiquid()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if(canBreak(worldObj.getBlock(x + xCoord, targetY, z + zCoord), x + xCoord, targetY, z + zCoord)) {
|
||||
targetX = x + xCoord;
|
||||
targetZ = z + zCoord;
|
||||
@ -416,23 +417,23 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
beam = false;
|
||||
targetY--;
|
||||
}
|
||||
|
||||
|
||||
private boolean canBreak(Block block, int x, int y, int z) {
|
||||
return !block.isAir(worldObj, x, y, z) && block.getBlockHardness(worldObj, x, y, z) >= 0 && !block.getMaterial().isLiquid() && block != Blocks.bedrock;
|
||||
}
|
||||
|
||||
|
||||
public int getRange() {
|
||||
|
||||
|
||||
int range = 1;
|
||||
|
||||
|
||||
for(int i = 1; i < 9; i++) {
|
||||
|
||||
|
||||
if(slots[i] != null) {
|
||||
|
||||
|
||||
if(slots[i].getItem() == ModItems.upgrade_effect_1)
|
||||
range += 2;
|
||||
else if(slots[i].getItem() == ModItems.upgrade_effect_2)
|
||||
@ -441,100 +442,100 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
range += 6;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Math.min(range, 25);
|
||||
}
|
||||
|
||||
|
||||
public boolean hasNullifier() {
|
||||
|
||||
|
||||
for(int i = 1; i < 9; i++) {
|
||||
|
||||
|
||||
if(slots[i] != null) {
|
||||
|
||||
|
||||
if(slots[i].getItem() == ModItems.upgrade_nullifier)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasSmelter() {
|
||||
|
||||
|
||||
for(int i = 1; i < 9; i++) {
|
||||
|
||||
|
||||
if(slots[i] != null) {
|
||||
|
||||
|
||||
if(slots[i].getItem() == ModItems.upgrade_smelter)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasShredder() {
|
||||
|
||||
|
||||
for(int i = 1; i < 9; i++) {
|
||||
|
||||
|
||||
if(slots[i] != null) {
|
||||
|
||||
|
||||
if(slots[i].getItem() == ModItems.upgrade_shredder)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasCentrifuge() {
|
||||
|
||||
|
||||
for(int i = 1; i < 9; i++) {
|
||||
|
||||
|
||||
if(slots[i] != null) {
|
||||
|
||||
|
||||
if(slots[i].getItem() == ModItems.upgrade_centrifuge)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasCrystallizer() {
|
||||
|
||||
|
||||
for(int i = 1; i < 9; i++) {
|
||||
|
||||
|
||||
if(slots[i] != null) {
|
||||
|
||||
|
||||
if(slots[i].getItem() == ModItems.upgrade_crystallizer)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean doesScream() {
|
||||
|
||||
|
||||
for(int i = 1; i < 9; i++) {
|
||||
|
||||
|
||||
if(slots[i] != null) {
|
||||
|
||||
|
||||
if(slots[i].getItem() == ModItems.upgrade_screm)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public int getConsumption() {
|
||||
return this.consumption;
|
||||
}
|
||||
|
||||
|
||||
public int getWidth() {
|
||||
|
||||
|
||||
return 1 + getRange() * 2;
|
||||
}
|
||||
|
||||
@ -545,12 +546,12 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
public int getProgressScaled(int i) {
|
||||
return (int) (breakProgress * i);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return TileEntity.INFINITE_EXTENT_AABB;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared()
|
||||
@ -570,20 +571,20 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int slot) {
|
||||
|
||||
|
||||
int[] slots = new int[21];
|
||||
|
||||
|
||||
for(int i = 0; i < 21; i++) {
|
||||
slots[i] = i + 9;
|
||||
}
|
||||
|
||||
|
||||
return slots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack) {
|
||||
super.setInventorySlotContents(i, stack);
|
||||
|
||||
|
||||
if(stack != null && i >= 1 && i <= 8 && stack.getItem() instanceof ItemMachineUpgrade)
|
||||
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F);
|
||||
}
|
||||
@ -606,7 +607,7 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
|
||||
tank.readFromNBT(nbt, "oil");
|
||||
isOn = nbt.getBoolean("isOn");
|
||||
}
|
||||
@ -614,7 +615,7 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
|
||||
tank.writeToNBT(nbt, "oil");
|
||||
nbt.setBoolean("isOn", isOn);
|
||||
}
|
||||
|
||||
@ -44,30 +44,30 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
|
||||
public class TileEntityMachineTurbineGas extends TileEntityMachineBase implements IFluidStandardTransceiver, IEnergyProviderMK2, IControlReceiver, IGUIProvider, SimpleComponent, IInfoProviderEC, CompatHandler.OCComponent, IFluidCopiable {
|
||||
|
||||
|
||||
public long power;
|
||||
public static final long maxPower = 1000000L;
|
||||
|
||||
|
||||
public int rpm; //0-100, crescent moon gauge, used for calculating the amount of power generated, starts past 10%
|
||||
public int temp; //0-800, used for figuring out how much water to boil, starts boiling at 300°C
|
||||
public int rpmIdle = 10;
|
||||
public int tempIdle = 300;
|
||||
|
||||
|
||||
public int powerSliderPos; //goes from 0 to 60, 0 is idle, 60 is max power
|
||||
public int throttle; //the same thing, but goes from 0 to 100
|
||||
|
||||
|
||||
public boolean autoMode;
|
||||
public int state = 0; //0 is offline, -1 is startup, 1 is online
|
||||
|
||||
|
||||
public int counter = 0; //used to startup and shutdown
|
||||
public int instantPowerOutput;
|
||||
|
||||
|
||||
public FluidTank[] tanks;
|
||||
|
||||
|
||||
private AudioWrapper audio;
|
||||
|
||||
|
||||
public static HashMap<FluidType, Double> fuelMaxCons = new HashMap(); //fuel consumption per tick at max power
|
||||
|
||||
|
||||
static {
|
||||
fuelMaxCons.put(Fluids.GAS, 50D); // natgas doesn't burn well so it burns faster to compensate
|
||||
fuelMaxCons.put(Fluids.SYNGAS, 10D); // syngas just fucks
|
||||
@ -75,9 +75,9 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
fuelMaxCons.put(Fluids.REFORMGAS, 5D); // fuck it we ball
|
||||
// default to 5 if not in list
|
||||
}
|
||||
|
||||
|
||||
//TODO particles from heat exchanger maybe? maybe in a future
|
||||
|
||||
|
||||
public TileEntityMachineTurbineGas() {
|
||||
super(2);
|
||||
this.tanks = new FluidTank[4];
|
||||
@ -91,23 +91,23 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
throttle = powerSliderPos * 100 / 60;
|
||||
|
||||
|
||||
if(slots[1] != null && slots[1].getItem() instanceof IItemFluidIdentifier) {
|
||||
FluidType fluid = ((IItemFluidIdentifier) slots[1].getItem()).getType(worldObj, xCoord, yCoord, zCoord, slots[1]);
|
||||
if(fluid.hasTrait(FT_Combustible.class) && fluid.getTrait(FT_Combustible.class).getGrade() == FuelGrade.GAS) {
|
||||
tanks[0].setTankType(fluid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(autoMode) { //power production depending on power requirement
|
||||
|
||||
|
||||
//scales the slider proportionally to the power gauge
|
||||
int powerSliderTarget = 60 - (int) (60 * power / maxPower);
|
||||
|
||||
|
||||
if(powerSliderTarget > powerSliderPos) { //makes the auto slider slide instead of snapping into position
|
||||
powerSliderPos++;
|
||||
}
|
||||
@ -115,23 +115,23 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
powerSliderPos--;
|
||||
}
|
||||
}
|
||||
|
||||
switch(state) { //what to do when turbine offline, starting up and online
|
||||
|
||||
switch(state) { //what to do when turbine offline, starting up and online
|
||||
case 0:
|
||||
shutdown();
|
||||
shutdown();
|
||||
break;
|
||||
case -1:
|
||||
stopIfNotReady();
|
||||
startup();
|
||||
break;
|
||||
case 1:
|
||||
case 1:
|
||||
stopIfNotReady();
|
||||
run();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
@ -140,11 +140,11 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
//do net/battery deductions first...
|
||||
power = Library.chargeItemsFromTE(slots, 0, power, maxPower);
|
||||
this.tryProvide(worldObj, xCoord - dir.offsetZ * 5, yCoord + 1, zCoord + dir.offsetX * 5, rot); //sends out power
|
||||
|
||||
|
||||
//...and then cap it. Prevents potential future cases where power would be limited due to the fuel being too strong and the buffer too small.
|
||||
if(this.power > this.maxPower)
|
||||
this.power = this.maxPower;
|
||||
|
||||
|
||||
for(int i = 0; i < 2; i++) { //fuel and lube
|
||||
this.trySubscribe(tanks[i].getTankType(), worldObj, xCoord - dir.offsetX * 2 + rot.offsetX, yCoord, zCoord - dir.offsetZ * 2 + rot.offsetZ, dir.getOpposite());
|
||||
this.trySubscribe(tanks[i].getTankType(), worldObj, xCoord + dir.offsetX * 2 + rot.offsetX, yCoord, zCoord + dir.offsetZ * 2 + rot.offsetZ, dir);
|
||||
@ -154,29 +154,29 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
this.trySubscribe(tanks[2].getTankType(), worldObj, xCoord + dir.offsetX * 2 + rot.offsetX * -4, yCoord, zCoord + dir.offsetZ * 2 + rot.offsetZ * -4, dir);
|
||||
//steam
|
||||
this.sendFluid(tanks[3], worldObj, xCoord + dir.offsetZ * 6, yCoord + 1, zCoord - dir.offsetX * 6, rot.getOpposite());
|
||||
|
||||
|
||||
this.networkPackNT(150);
|
||||
|
||||
|
||||
} else { //client side, for sounds n shit
|
||||
|
||||
|
||||
if(rpm >= 10 && state != -1) { //if conditions are right, play the sound
|
||||
|
||||
|
||||
if(audio == null) { //if there is no sound playing, start it
|
||||
|
||||
|
||||
audio = MainRegistry.proxy.getLoopedSound("hbm:block.turbinegasRunning", xCoord, yCoord, zCoord, getVolume(1.0F), 20F, 2.0F);
|
||||
audio.startSound();
|
||||
|
||||
|
||||
} else if(!audio.isPlaying()) {
|
||||
audio.stopSound();
|
||||
audio = MainRegistry.proxy.getLoopedSound("hbm:block.turbinegasRunning", xCoord, yCoord, zCoord, getVolume(1.0F), 20F, 2.0F);
|
||||
audio.startSound();
|
||||
}
|
||||
|
||||
|
||||
audio.updatePitch((float) (0.55 + 0.1 * rpm / 10)); //dynamic pitch update based on rpm
|
||||
audio.updateVolume(getVolume(2F)); //yeah i need this
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if(audio != null) {
|
||||
audio.stopSound();
|
||||
audio = null;
|
||||
@ -216,8 +216,8 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
this.temp = buf.readInt();
|
||||
this.state = buf.readInt();
|
||||
this.autoMode = buf.readBoolean();
|
||||
this.powerSliderPos = buf.readInt();
|
||||
this.throttle = buf.readInt();
|
||||
this.powerSliderPos = buf.readInt();
|
||||
|
||||
if(state != 1)
|
||||
this.counter = buf.readInt();
|
||||
@ -229,9 +229,9 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
this.tanks[2].deserialize(buf);
|
||||
this.tanks[3].deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
private void stopIfNotReady() {
|
||||
|
||||
|
||||
if(tanks[0].getFill() == 0 || tanks[1].getFill() == 0) {
|
||||
state = 0;
|
||||
}
|
||||
@ -239,20 +239,20 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
state = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean hasAcceptableFuel() {
|
||||
|
||||
|
||||
if(tanks[0].getTankType().hasTrait(FT_Combustible.class)) {
|
||||
return tanks[0].getTankType().getTrait(FT_Combustible.class).getGrade() == FuelGrade.GAS;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void startup() {
|
||||
|
||||
|
||||
counter++;
|
||||
|
||||
|
||||
if(counter <= 20) //rpm gauge 0-100-0
|
||||
rpm = 5 * counter;
|
||||
else if (counter > 20 && counter <= 40)
|
||||
@ -261,43 +261,43 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
rpm = (int) (rpmIdle * (counter - 50) / 530); //slowly ramps up temp and RPM
|
||||
temp = (int) (tempIdle * (counter - 50) / 530);
|
||||
}
|
||||
|
||||
|
||||
if(counter == 50) {
|
||||
worldObj.playSoundEffect(xCoord, yCoord + 2, zCoord, "hbm:block.turbinegasStartup", getVolume(1.0F), 1.0F);
|
||||
}
|
||||
|
||||
|
||||
if(counter == 580) {
|
||||
state = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int rpmLast; //used to progressively slow down and cool the turbine without immediatly setting rpm and temp to 0
|
||||
int tempLast;
|
||||
|
||||
|
||||
private void shutdown() {
|
||||
|
||||
|
||||
autoMode = false;
|
||||
instantPowerOutput = 0;
|
||||
|
||||
|
||||
if(powerSliderPos > 0)
|
||||
powerSliderPos--;
|
||||
|
||||
|
||||
if(rpm <= 10 && counter > 0) {
|
||||
|
||||
|
||||
if(counter == 225) {
|
||||
|
||||
|
||||
worldObj.playSoundEffect(xCoord, yCoord + 2, zCoord, "hbm:block.turbinegasShutdown", getVolume(1.0F), 1.0F);
|
||||
|
||||
|
||||
rpmLast = rpm;
|
||||
tempLast = temp;
|
||||
}
|
||||
|
||||
|
||||
counter--;
|
||||
|
||||
|
||||
rpm = (int) (rpmLast * (counter) / 225);
|
||||
temp = (int) (tempLast * (counter) / 225);
|
||||
|
||||
|
||||
} else if(rpm > 11) { //quickly slows down the turbine to idle before shutdown
|
||||
counter = 42069; //absolutely necessary to avoid fuckeries on shutdown
|
||||
rpm--;
|
||||
@ -306,15 +306,15 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
rpm--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Dynamically calculates a (hopefully) sensible burn heat from the combustion energy, scales from 300°C - 800°C */
|
||||
protected int getFluidBurnTemp(FluidType type) {
|
||||
double dFuel = type.hasTrait(FT_Combustible.class) ? type.getTrait(FT_Combustible.class).getCombustionEnergy() : 0;
|
||||
return (int) Math.floor(800D - (Math.pow(Math.E, -dFuel / 100_000D)) * 300D);
|
||||
}
|
||||
|
||||
|
||||
private void run() {
|
||||
|
||||
|
||||
if((int) (throttle * 0.9) > rpm - rpmIdle) { //simulates the rotor's moment of inertia
|
||||
if(worldObj.getTotalWorldTime() % 5 == 0) {
|
||||
rpm++;
|
||||
@ -324,9 +324,9 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
rpm--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int maxTemp = getFluidBurnTemp(tanks[0].getTankType()); // fuelMaxTemp.get(tanks[0].getTankType())
|
||||
|
||||
|
||||
if(throttle * 5 * (maxTemp - tempIdle) / 500 > temp - tempIdle) { //simulates the heat exchanger's resistance to temperature variation
|
||||
if(worldObj.getTotalWorldTime() % 2 == 0) {
|
||||
temp++;
|
||||
@ -336,30 +336,30 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
temp--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double consumption = fuelMaxCons.containsKey(tanks[0].getTankType()) ? fuelMaxCons.get(tanks[0].getTankType()) : 5D;
|
||||
if(worldObj.getTotalWorldTime() % 20 == 0 && tanks[0].getTankType() != Fluids.OXYHYDROGEN) PollutionHandler.incrementPollution(worldObj, xCoord, yCoord, zCoord, PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND * 3);
|
||||
makePower(consumption, throttle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
double fuelToConsume; //used to consume 1 mb of fuel at a time when consumption is <1 mb/tick
|
||||
double waterToBoil;
|
||||
double waterPerTick = 0;
|
||||
|
||||
|
||||
private void makePower(double consMax, int throttle) {
|
||||
|
||||
|
||||
double idleConsumption = consMax * 0.05D;
|
||||
double consumption = idleConsumption + consMax * throttle / 100;
|
||||
|
||||
|
||||
fuelToConsume += consumption;
|
||||
|
||||
|
||||
tanks[0].setFill(tanks[0].getFill() - (int) Math.floor(fuelToConsume));
|
||||
fuelToConsume -= (int) Math.floor(fuelToConsume);
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 10 == 0) //lube consumption
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 10 == 0) //lube consumption
|
||||
tanks[1].setFill(tanks[1].getFill() - 1);
|
||||
|
||||
|
||||
if(tanks[0].getFill() < 0) { //avoids negative amounts of fluid
|
||||
tanks[0].setFill(0);
|
||||
state = 0;
|
||||
@ -368,16 +368,16 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
tanks[1].setFill(0);
|
||||
state = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
long energy = 0; //energy per mb of fuel
|
||||
|
||||
|
||||
if(tanks[0].getTankType().hasTrait(FT_Combustible.class)) {
|
||||
energy = tanks[0].getTankType().getTrait(FT_Combustible.class).getCombustionEnergy() / 1000L;
|
||||
}
|
||||
|
||||
|
||||
int rpmEff = rpm - rpmIdle; // RPM above idle level, 0-90
|
||||
|
||||
|
||||
//consMax*energy is equivalent to power production at 100%
|
||||
if(instantPowerOutput < (consMax * energy * rpmEff / 90)) { //this shit avoids power rising in steps of 2000 or so HE at a time, instead it does it smoothly
|
||||
instantPowerOutput += Math.random() * 0.005 * consMax * energy;
|
||||
@ -390,22 +390,22 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
instantPowerOutput = (int) (consMax * energy * rpmEff / 90);
|
||||
}
|
||||
this.power += instantPowerOutput;
|
||||
|
||||
|
||||
waterPerTick = (consMax * energy * (temp - tempIdle) / 220000); //it just works fuck you
|
||||
|
||||
|
||||
if(tanks[2].getFill() >= Math.ceil(waterPerTick)) { //checks if there's enough water to boil
|
||||
|
||||
|
||||
waterToBoil += waterPerTick;
|
||||
|
||||
|
||||
if(tanks[3].getFill() <= 160000 - waterToBoil * 10) { //checks if there's room for steam in the tank
|
||||
|
||||
|
||||
tanks[2].setFill(tanks[2].getFill() - (int) Math.floor(waterToBoil));
|
||||
tanks[3].setFill(tanks[3].getFill() + 10 * (int) Math.floor(waterToBoil));
|
||||
waterToBoil -= (int) Math.floor(waterToBoil);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
@ -424,11 +424,11 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
this.instantPowerOutput = nbt.getInteger("instPwr");
|
||||
this.counter = nbt.getInteger("counter");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
|
||||
tanks[0].writeToNBT(nbt, "gas");
|
||||
tanks[1].writeToNBT(nbt, "lube");
|
||||
tanks[2].writeToNBT(nbt, "water");
|
||||
@ -454,24 +454,24 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
|
||||
@Override
|
||||
public void receiveControl(NBTTagCompound data) {
|
||||
|
||||
|
||||
if(data.hasKey("slidPos"))
|
||||
powerSliderPos = data.getInteger("slidPos");
|
||||
|
||||
|
||||
if(data.hasKey("autoMode"))
|
||||
autoMode = data.getBoolean("autoMode");
|
||||
|
||||
|
||||
if(data.hasKey("state"))
|
||||
state = data.getInteger("state");
|
||||
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(EntityPlayer player) {
|
||||
return Vec3.createVectorHelper(xCoord - player.posX, yCoord - player.posY, zCoord - player.posZ).lengthVector() < 25;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
|
||||
@ -501,17 +501,17 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
public long getPower() {
|
||||
return this.power;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getMaxPower() {
|
||||
return this.maxPower;
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 5,
|
||||
@ -522,10 +522,10 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
zCoord + 6
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -551,7 +551,7 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
public FluidTank[] getSendingTanks() {
|
||||
return new FluidTank[] { tanks[3] };
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection dir) {
|
||||
return dir != ForgeDirection.DOWN;
|
||||
@ -716,4 +716,4 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
|
||||
data.setDouble(CompatEnergyControl.D_CONSUMPTION_MB, this.waterToBoil);
|
||||
data.setDouble(CompatEnergyControl.D_OUTPUT_MB, this.waterToBoil * 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -402,7 +402,7 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
|
||||
this.typeLoaded = buf.readInt();
|
||||
this.amountLoaded = buf.readInt();
|
||||
this.rodLevel = buf.readDouble();
|
||||
this.rodTarget = buf.readInt();
|
||||
this.rodTarget = buf.readDouble();
|
||||
this.coreHeatCapacity = buf.readLong();
|
||||
tanks[0].deserialize(buf);
|
||||
tanks[1].deserialize(buf);
|
||||
|
||||
@ -39,14 +39,14 @@ public class TileEntitySteamEngine extends TileEntityLoadedBase implements IEner
|
||||
|
||||
private int turnProgress;
|
||||
private float acceleration = 0F;
|
||||
|
||||
|
||||
/* CONFIGURABLE */
|
||||
private static int steamCap = 2_000;
|
||||
private static int ldsCap = 20;
|
||||
private static double efficiency = 0.85D;
|
||||
|
||||
|
||||
public TileEntitySteamEngine() {
|
||||
|
||||
|
||||
tanks = new FluidTank[2];
|
||||
tanks[0] = new FluidTank(Fluids.STEAM, steamCap);
|
||||
tanks[1] = new FluidTank(Fluids.SPENTSTEAM, ldsCap);
|
||||
@ -75,9 +75,9 @@ public class TileEntitySteamEngine extends TileEntityLoadedBase implements IEner
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
this.powerBuffer = 0;
|
||||
|
||||
tanks[0].setTankType(Fluids.STEAM);
|
||||
@ -87,29 +87,29 @@ public class TileEntitySteamEngine extends TileEntityLoadedBase implements IEner
|
||||
|
||||
FT_Coolable trait = tanks[0].getTankType().getTrait(FT_Coolable.class);
|
||||
double eff = trait.getEfficiency(CoolingType.TURBINE) * efficiency;
|
||||
|
||||
|
||||
int inputOps = tanks[0].getFill() / trait.amountReq;
|
||||
int outputOps = (tanks[1].getMaxFill() - tanks[1].getFill()) / trait.amountProduced;
|
||||
int ops = Math.min(inputOps, outputOps);
|
||||
tanks[0].setFill(tanks[0].getFill() - ops * trait.amountReq);
|
||||
tanks[1].setFill(tanks[1].getFill() + ops * trait.amountProduced);
|
||||
this.powerBuffer += (ops * trait.heatEnergy * eff);
|
||||
|
||||
|
||||
if(ops > 0) {
|
||||
this.acceleration += 0.1F;
|
||||
} else {
|
||||
this.acceleration -= 0.1F;
|
||||
}
|
||||
|
||||
|
||||
this.acceleration = MathHelper.clamp_float(this.acceleration, 0F, 40F);
|
||||
this.rotor += this.acceleration;
|
||||
|
||||
|
||||
if(this.rotor >= 360D) {
|
||||
this.rotor -= 360D;
|
||||
|
||||
|
||||
this.worldObj.playSoundEffect(xCoord, yCoord, zCoord, "hbm:block.steamEngineOperate", getVolume(1.0F), 0.5F + (acceleration / 80F));
|
||||
}
|
||||
|
||||
|
||||
buf.writeLong(this.powerBuffer);
|
||||
buf.writeFloat(this.rotor);
|
||||
tanks[1].serialize(buf);
|
||||
@ -119,11 +119,11 @@ public class TileEntitySteamEngine extends TileEntityLoadedBase implements IEner
|
||||
this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
this.sendFluid(tanks[1], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
|
||||
|
||||
sendStandard(150);
|
||||
} else {
|
||||
this.lastRotor = this.rotor;
|
||||
|
||||
|
||||
if(this.turnProgress > 0) {
|
||||
double d = MathHelper.wrapAngleTo180_double(this.syncRotor - (double) this.rotor);
|
||||
this.rotor = (float) ((double) this.rotor + d / (double) this.turnProgress);
|
||||
@ -133,11 +133,11 @@ public class TileEntitySteamEngine extends TileEntityLoadedBase implements IEner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected DirPos[] getConPos() {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
return new DirPos[] {
|
||||
new DirPos(xCoord + rot.offsetX * 2, yCoord + 1, zCoord + rot.offsetZ * 2, rot),
|
||||
new DirPos(xCoord + rot.offsetX * 2 + dir.offsetX, yCoord + 1, zCoord + rot.offsetZ * 2 + dir.offsetZ, rot),
|
||||
@ -154,7 +154,7 @@ public class TileEntitySteamEngine extends TileEntityLoadedBase implements IEner
|
||||
this.tanks[0].readFromNBT(nbt, "s");
|
||||
this.tanks[1].readFromNBT(nbt, "w");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
@ -164,12 +164,12 @@ public class TileEntitySteamEngine extends TileEntityLoadedBase implements IEner
|
||||
tanks[0].writeToNBT(nbt, "s");
|
||||
tanks[1].writeToNBT(nbt, "w");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return TileEntity.INFINITE_EXTENT_AABB;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -219,11 +219,11 @@ public class TileEntitySteamEngine extends TileEntityLoadedBase implements IEner
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
this.tanks[0].deserialize(buf);
|
||||
this.powerBuffer = buf.readLong();
|
||||
this.syncRotor = buf.readFloat();
|
||||
this.turnProgress = 3; //use 3-ply for extra smoothness
|
||||
this.tanks[0].deserialize(buf);
|
||||
this.tanks[1].deserialize(buf);
|
||||
this.turnProgress = 3; //use 3-ply for extra smoothness
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -20,9 +20,9 @@ import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineCatalyticCracker extends TileEntityLoadedBase implements IBufPacketReceiver, IFluidStandardTransceiver, IFluidCopiable {
|
||||
|
||||
|
||||
public FluidTank[] tanks;
|
||||
|
||||
|
||||
public TileEntityMachineCatalyticCracker() {
|
||||
tanks = new FluidTank[5];
|
||||
tanks[0] = new FluidTank(Fluids.BITUMEN, 4000);
|
||||
@ -31,10 +31,10 @@ public class TileEntityMachineCatalyticCracker extends TileEntityLoadedBase impl
|
||||
tanks[3] = new FluidTank(Fluids.PETROLEUM, 4000);
|
||||
tanks[4] = new FluidTank(Fluids.SPENTSTEAM, 800);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
this.worldObj.theProfiler.startSection("catalyticCracker_setup_tanks");
|
||||
@ -48,48 +48,48 @@ public class TileEntityMachineCatalyticCracker extends TileEntityLoadedBase impl
|
||||
|
||||
this.worldObj.theProfiler.endStartSection("catalyticCracker_send_fluid");
|
||||
if(worldObj.getTotalWorldTime() % 10 == 0) {
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
for(int i = 2; i <= 4; i++) {
|
||||
if(tanks[i].getFill() > 0) this.sendFluid(tanks[i], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
}
|
||||
|
||||
sendStandard(25);
|
||||
}
|
||||
this.worldObj.theProfiler.endSection();
|
||||
sendStandard(25);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
for(int i = 0; i < 5; i++)
|
||||
tanks[i].serialize(buf);
|
||||
for(FluidTank tank : tanks)
|
||||
tank.serialize(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
for(int i = 0; i < 5; i++)
|
||||
tanks[i].deserialize(buf);
|
||||
for(FluidTank tank : tanks)
|
||||
tank.deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
private void updateConnections() {
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
this.trySubscribe(tanks[1].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void crack() {
|
||||
|
||||
|
||||
Pair<FluidStack, FluidStack> quart = CrackingRecipes.getCracking(tanks[0].getTankType());
|
||||
|
||||
|
||||
if(quart != null) {
|
||||
|
||||
|
||||
int left = quart.getKey().fill;
|
||||
int right = quart.getValue().fill;
|
||||
|
||||
|
||||
for(int i = 0; i < 2; i++) {
|
||||
if(tanks[0].getFill() >= 100 && tanks[1].getFill() >= 200 && hasSpace(left, right)) {
|
||||
tanks[0].setFill(tanks[0].getFill() - 100);
|
||||
@ -101,15 +101,15 @@ public class TileEntityMachineCatalyticCracker extends TileEntityLoadedBase impl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean hasSpace(int left, int right) {
|
||||
return tanks[2].getFill() + left <= tanks[2].getMaxFill() && tanks[3].getFill() + right <= tanks[3].getMaxFill() && tanks[4].getFill() + 2 <= tanks[4].getMaxFill();
|
||||
}
|
||||
|
||||
|
||||
private void setupTanks() {
|
||||
|
||||
|
||||
Pair<FluidStack, FluidStack> quart = CrackingRecipes.getCracking(tanks[0].getTankType());
|
||||
|
||||
|
||||
if(quart != null) {
|
||||
tanks[1].setTankType(Fluids.STEAM);
|
||||
tanks[2].setTankType(quart.getKey().type);
|
||||
@ -123,7 +123,7 @@ public class TileEntityMachineCatalyticCracker extends TileEntityLoadedBase impl
|
||||
tanks[4].setTankType(Fluids.NONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
@ -131,7 +131,7 @@ public class TileEntityMachineCatalyticCracker extends TileEntityLoadedBase impl
|
||||
for(int i = 0; i < 5; i++)
|
||||
tanks[i].readFromNBT(nbt, "tank" + i);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
@ -139,12 +139,12 @@ public class TileEntityMachineCatalyticCracker extends TileEntityLoadedBase impl
|
||||
for(int i = 0; i < 5; i++)
|
||||
tanks[i].writeToNBT(nbt, "tank" + i);
|
||||
}
|
||||
|
||||
|
||||
protected DirPos[] getConPos() {
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
return new DirPos[] {
|
||||
new DirPos(xCoord + dir.offsetX * 4 + rot.offsetX * 1, yCoord, zCoord + dir.offsetZ * 4 + rot.offsetZ * 1, dir),
|
||||
new DirPos(xCoord + dir.offsetX * 4 - rot.offsetX * 2, yCoord, zCoord + dir.offsetZ * 4 - rot.offsetZ * 2, dir),
|
||||
@ -156,12 +156,12 @@ public class TileEntityMachineCatalyticCracker extends TileEntityLoadedBase impl
|
||||
new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX * 4, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ * 4, rot.getOpposite())
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 3,
|
||||
@ -172,10 +172,10 @@ public class TileEntityMachineCatalyticCracker extends TileEntityLoadedBase impl
|
||||
zCoord + 4
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user