mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
139 lines
3.0 KiB
Java
139 lines
3.0 KiB
Java
package com.hbm.tileentity.machine;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import com.hbm.interfaces.IConsumer;
|
|
import com.hbm.interfaces.ISource;
|
|
import com.hbm.lib.Library;
|
|
|
|
import cofh.api.energy.EnergyStorage;
|
|
import cofh.api.energy.IEnergyReceiver;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
public class TileEntityConverterRfHe extends TileEntity implements ISource, IEnergyReceiver {
|
|
|
|
public long power;
|
|
public final long maxPower = 1000000;
|
|
public List<IConsumer> list = new ArrayList();
|
|
public int age = 0;
|
|
public EnergyStorage storage = new EnergyStorage(4000000, 2500000, 2500000);
|
|
|
|
@Override
|
|
public void updateEntity() {
|
|
|
|
if (!worldObj.isRemote) {
|
|
|
|
long convert = Math.min(storage.getEnergyStored(), (maxPower - power) * 4);
|
|
|
|
storage.setEnergyStored((int) (storage.getEnergyStored() - convert));
|
|
power += convert / 4;
|
|
|
|
if(convert > 0)
|
|
this.markDirty();
|
|
}
|
|
|
|
age++;
|
|
if(age >= 20)
|
|
{
|
|
age = 0;
|
|
}
|
|
|
|
if(age == 9 || age == 19)
|
|
ffgeuaInit();
|
|
}
|
|
|
|
@Override
|
|
public boolean canConnectEnergy(ForgeDirection from) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
|
return storage.receiveEnergy(maxReceive, simulate);
|
|
}
|
|
|
|
@Override
|
|
public int getEnergyStored(ForgeDirection from) {
|
|
return storage.getEnergyStored();
|
|
}
|
|
|
|
@Override
|
|
public int getMaxEnergyStored(ForgeDirection from) {
|
|
return storage.getMaxEnergyStored();
|
|
}
|
|
|
|
@Override
|
|
public void ffgeua(int x, int y, int z, boolean newTact) {
|
|
|
|
Library.ffgeua(x, y, z, newTact, this, worldObj);
|
|
}
|
|
|
|
@Override
|
|
public void ffgeuaInit() {
|
|
ffgeua(this.xCoord, this.yCoord + 1, this.zCoord, getTact());
|
|
ffgeua(this.xCoord, this.yCoord - 1, this.zCoord, getTact());
|
|
ffgeua(this.xCoord - 1, this.yCoord, this.zCoord, getTact());
|
|
ffgeua(this.xCoord + 1, this.yCoord, this.zCoord, getTact());
|
|
ffgeua(this.xCoord, this.yCoord, this.zCoord - 1, getTact());
|
|
ffgeua(this.xCoord, this.yCoord, this.zCoord + 1, getTact());
|
|
}
|
|
|
|
@Override
|
|
public boolean getTact() {
|
|
if(age >= 0 && age < 10)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public long getPowerScaled(long i) {
|
|
return (power * i) / maxPower;
|
|
}
|
|
|
|
public int getFluxScaled(int i) {
|
|
return (storage.getEnergyStored() * i) / storage.getMaxEnergyStored();
|
|
}
|
|
|
|
@Override
|
|
public long getSPower() {
|
|
return power;
|
|
}
|
|
|
|
@Override
|
|
public void setSPower(long i) {
|
|
this.power = i;
|
|
}
|
|
|
|
@Override
|
|
public List<IConsumer> getList() {
|
|
return list;
|
|
}
|
|
|
|
@Override
|
|
public void clearList() {
|
|
this.list.clear();
|
|
}
|
|
|
|
@Override
|
|
public void readFromNBT(NBTTagCompound nbt) {
|
|
super.readFromNBT(nbt);
|
|
|
|
this.power = nbt.getLong("power");
|
|
storage.readFromNBT(nbt);
|
|
}
|
|
|
|
@Override
|
|
public void writeToNBT(NBTTagCompound nbt) {
|
|
super.writeToNBT(nbt);
|
|
|
|
nbt.setLong("power", power);
|
|
storage.writeToNBT(nbt);
|
|
}
|
|
|
|
}
|