@Override public void onReceivePacket(int packetID, ByteArrayDataInput dataStream) throws IOException { super.onReceivePacket(packetID, dataStream); if (packetID == TilePacketType.DESCRIPTION.ordinal()) { this.isInversed = dataStream.readBoolean(); this.wattsReceived = dataStream.readDouble(); // this.processTime = dataStream.readInt(); } else if (packetID == TilePacketType.TOGGLE_MODE.ordinal()) { this.isInversed = !this.isInversed; } }
@Override public void updateEntity() { super.updateEntity(); if (!this.worldObj.isRemote) { if (!this.isDisabled() && this.isActive()) { if (this.isInversed && Settings.ENABLE_ELECTRICITY) { // Convert Fortron to Electricity double watts = Math.min(this.getFortronEnergy() * FORTRON_UE_RATIO, WATTAGE); ElectricityPack remainder = this.produce(watts); double electricItemGiven = 0; if (remainder.getWatts() > 0) { electricItemGiven = ElectricItemHelper.chargeItem( this.getStackInSlot(SLOT_BATTERY), remainder.getWatts(), this.getVoltage()); } this.requestFortron( (int) ((watts - (remainder.getWatts() - electricItemGiven)) / FORTRON_UE_RATIO), true); this.animation++; } else { // Convert Electricity to Fortron this.wattsReceived += ElectricItemHelper.dechargeItem( this.getStackInSlot(SLOT_BATTERY), WATTAGE, this.getVoltage()); if (this.wattsReceived >= TileEntityCoercionDeriver.WATTAGE || !Settings.ENABLE_ELECTRICITY) { int production = 3; if (this.isStackValidForSlot(SLOT_FUEL, this.getStackInSlot(SLOT_FUEL))) { production *= NORMAL_PRODUCTION; } this.fortronTank.fill( FortronHelper.getFortron(production + this.worldObj.rand.nextInt(production)), true); if (this.processTime == 0) { this.decrStackSize(SLOT_FUEL, 1); this.processTime = REQUIRED_TIME; if (this.getModuleCount(ModularForceFieldSystem.itemModuleSpeed) > 0) { this.processTime = this.processTime * this.getModuleCount(ModularForceFieldSystem.itemModuleSpeed) / 30; } } if (this.processTime > 0) { // We are processing this.processTime--; if (this.processTime < 1) { this.processTime = 0; } } else { this.processTime = 0; } this.wattsReceived -= WATTAGE; } } } } else if (this.isActive()) { this.animation++; } }
@Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setInteger("processTime", this.processTime); nbt.setBoolean("isInversed", this.isInversed); }
@Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); this.processTime = nbt.getInteger("processTime"); this.isInversed = nbt.getBoolean("isInversed"); }