ActuallyAdditions/src/main/java/ellpeck/actuallyadditions/tile/TileEntityLavaFactoryController.java

121 lines
4.3 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
* This file ("TileEntityLavaFactoryController.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2015-11-02 20:55:19 +01:00
* © 2015 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2015-06-06 01:25:53 +02:00
package ellpeck.actuallyadditions.tile;
import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyReceiver;
2015-12-21 22:22:02 +01:00
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2015-06-18 13:14:57 +02:00
import ellpeck.actuallyadditions.blocks.InitBlocks;
2015-06-06 01:25:53 +02:00
import ellpeck.actuallyadditions.blocks.metalists.TheMiscBlocks;
import ellpeck.actuallyadditions.util.WorldUtil;
2015-06-06 01:25:53 +02:00
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityLavaFactoryController extends TileEntityBase implements IEnergyReceiver, IEnergySaver, IEnergyDisplay{
2015-06-06 01:25:53 +02:00
2015-10-03 10:16:18 +02:00
public static final int NOT_MULTI = 0;
public static final int HAS_LAVA = 1;
public static final int HAS_AIR = 2;
2015-12-01 19:48:09 +01:00
public static final int ENERGY_USE = 150000;
//The Positions the Case Blocks should be in for the Factory to work
private static final int[][] CASE_POSITIONS = {{-1, 1, 0}, {1, 1, 0}, {0, 1, -1}, {0, 1, 1}};
2015-10-03 10:16:18 +02:00
public EnergyStorage storage = new EnergyStorage(3000000);
private int currentWorkTime;
2015-12-23 14:03:41 +01:00
private int oldEnergy;
2015-06-06 01:25:53 +02:00
@Override
@SuppressWarnings("unchecked")
public void updateEntity(){
super.updateEntity();
2015-06-06 01:25:53 +02:00
if(!worldObj.isRemote){
if(this.storage.getEnergyStored() >= ENERGY_USE && this.isMultiblock() == HAS_AIR){
2015-06-06 01:25:53 +02:00
this.currentWorkTime++;
if(this.currentWorkTime >= 200){
2015-06-06 01:25:53 +02:00
this.currentWorkTime = 0;
worldObj.setBlock(xCoord, yCoord+1, zCoord, Blocks.lava);
this.storage.extractEnergy(ENERGY_USE, false);
2015-06-06 01:25:53 +02:00
}
}
2015-10-02 16:48:01 +02:00
else{
this.currentWorkTime = 0;
}
2015-12-23 14:03:41 +01:00
if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
this.oldEnergy = this.storage.getEnergyStored();
}
2015-06-06 01:25:53 +02:00
}
}
2015-12-01 19:48:09 +01:00
@Override
public void writeSyncableNBT(NBTTagCompound compound, boolean sync){
super.writeSyncableNBT(compound, sync);
2015-12-01 19:48:09 +01:00
this.storage.writeToNBT(compound);
compound.setInteger("WorkTime", this.currentWorkTime);
}
@Override
public void readSyncableNBT(NBTTagCompound compound, boolean sync){
super.readSyncableNBT(compound, sync);
2015-12-01 19:48:09 +01:00
this.storage.readFromNBT(compound);
this.currentWorkTime = compound.getInteger("WorkTime");
}
2015-06-06 01:25:53 +02:00
public int isMultiblock(){
if(WorldUtil.hasBlocksInPlacesGiven(CASE_POSITIONS, InitBlocks.blockMisc, TheMiscBlocks.LAVA_FACTORY_CASE.ordinal(), worldObj, xCoord, yCoord, zCoord)){
if(worldObj.getBlock(xCoord, yCoord+1, zCoord) == Blocks.lava || worldObj.getBlock(xCoord, yCoord+1, zCoord) == Blocks.flowing_lava){
return HAS_LAVA;
}
if(worldObj.getBlock(xCoord, yCoord+1, zCoord) == null || worldObj.isAirBlock(xCoord, yCoord+1, zCoord)){
return HAS_AIR;
2015-06-06 01:25:53 +02:00
}
}
return NOT_MULTI;
}
@Override
public int receiveEnergy(ForgeDirection from, int maxExtract, boolean simulate){
return from != ForgeDirection.UP ? this.storage.receiveEnergy(maxExtract, simulate) : 0;
}
@Override
public int getEnergyStored(ForgeDirection from){
return from != ForgeDirection.UP ? this.storage.getEnergyStored() : 0;
}
@Override
public int getMaxEnergyStored(ForgeDirection from){
return from != ForgeDirection.UP ? this.storage.getMaxEnergyStored() : 0;
}
@Override
public boolean canConnectEnergy(ForgeDirection from){
return from != ForgeDirection.UP;
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
2015-12-21 22:46:23 +01:00
public void setEnergy(int energy){
this.storage.setEnergyStored(energy);
}
@Override
2015-12-21 22:46:23 +01:00
@SideOnly(Side.CLIENT)
public int getMaxEnergy(){
return this.storage.getMaxEnergyStored();
}
2015-06-06 01:25:53 +02:00
}