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
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-06-06 01:25:53 +02:00
|
|
|
|
|
|
|
import cofh.api.energy.EnergyStorage;
|
|
|
|
import cofh.api.energy.IEnergyReceiver;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheMiscBlocks;
|
2016-01-08 13:31:58 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
2015-06-06 01:25:53 +02:00
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-01-07 23:42:42 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-06-06 01:25:53 +02:00
|
|
|
|
2015-12-21 22:18:33 +01:00
|
|
|
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;
|
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-07-25 05:28:31 +02:00
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, boolean sync){
|
|
|
|
super.writeSyncableNBT(compound, sync);
|
|
|
|
this.storage.writeToNBT(compound);
|
|
|
|
compound.setInteger("WorkTime", this.currentWorkTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readSyncableNBT(NBTTagCompound compound, boolean sync){
|
|
|
|
super.readSyncableNBT(compound, sync);
|
|
|
|
this.storage.readFromNBT(compound);
|
|
|
|
this.currentWorkTime = compound.getInteger("WorkTime");
|
|
|
|
}
|
|
|
|
|
2015-06-06 01:25:53 +02:00
|
|
|
@Override
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public void updateEntity(){
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2016-05-02 17:46:53 +02:00
|
|
|
if(!this.worldObj.isRemote){
|
2015-11-28 19:02:01 +01:00
|
|
|
if(this.storage.getEnergyStored() >= ENERGY_USE && this.isMultiblock() == HAS_AIR){
|
2015-06-06 01:25:53 +02:00
|
|
|
this.currentWorkTime++;
|
2015-11-28 19:02:01 +01:00
|
|
|
if(this.currentWorkTime >= 200){
|
2015-06-06 01:25:53 +02:00
|
|
|
this.currentWorkTime = 0;
|
2016-05-02 17:46:53 +02:00
|
|
|
PosUtil.setBlock(PosUtil.offset(this.pos, 0, 1, 0), this.worldObj, Blocks.LAVA, 0, 2);
|
2015-11-28 19:02:01 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int isMultiblock(){
|
2016-01-08 13:31:58 +01:00
|
|
|
BlockPos thisPos = this.pos;
|
|
|
|
BlockPos[] positions = new BlockPos[]{
|
|
|
|
PosUtil.offset(thisPos, 1, 1, 0),
|
|
|
|
PosUtil.offset(thisPos, -1, 1, 0),
|
|
|
|
PosUtil.offset(thisPos, 0, 1, 1),
|
|
|
|
PosUtil.offset(thisPos, 0, 1, -1)
|
2016-01-07 23:42:42 +01:00
|
|
|
};
|
|
|
|
|
2016-05-02 17:46:53 +02:00
|
|
|
if(WorldUtil.hasBlocksInPlacesGiven(positions, InitBlocks.blockMisc, TheMiscBlocks.LAVA_FACTORY_CASE.ordinal(), this.worldObj)){
|
2016-01-08 13:31:58 +01:00
|
|
|
BlockPos pos = PosUtil.offset(thisPos, 0, 1, 0);
|
2016-05-02 17:46:53 +02:00
|
|
|
if(PosUtil.getBlock(pos, this.worldObj) == Blocks.LAVA || PosUtil.getBlock(pos, this.worldObj) == Blocks.FLOWING_LAVA){
|
2015-07-25 05:28:31 +02:00
|
|
|
return HAS_LAVA;
|
|
|
|
}
|
2016-05-02 17:46:53 +02:00
|
|
|
if(PosUtil.getBlock(pos, this.worldObj) == null || this.worldObj.isAirBlock(pos)){
|
2015-07-25 05:28:31 +02:00
|
|
|
return HAS_AIR;
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NOT_MULTI;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
public int receiveEnergy(EnumFacing from, int maxExtract, boolean simulate){
|
|
|
|
return from != EnumFacing.UP ? this.storage.receiveEnergy(maxExtract, simulate) : 0;
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
public int getEnergyStored(EnumFacing from){
|
|
|
|
return from != EnumFacing.UP ? this.storage.getEnergyStored() : 0;
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
public int getMaxEnergyStored(EnumFacing from){
|
|
|
|
return from != EnumFacing.UP ? this.storage.getMaxEnergyStored() : 0;
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
public boolean canConnectEnergy(EnumFacing from){
|
|
|
|
return from != EnumFacing.UP;
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|
2015-12-13 00:54:25 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEnergy(){
|
|
|
|
return this.storage.getEnergyStored();
|
|
|
|
}
|
|
|
|
|
2015-12-21 22:18:33 +01:00
|
|
|
@Override
|
2015-12-21 22:46:23 +01:00
|
|
|
public void setEnergy(int energy){
|
|
|
|
this.storage.setEnergyStored(energy);
|
2015-12-21 22:18:33 +01:00
|
|
|
}
|
|
|
|
|
2015-12-13 00:54:25 +01:00
|
|
|
@Override
|
2015-12-21 22:46:23 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getMaxEnergy(){
|
|
|
|
return this.storage.getMaxEnergyStored();
|
2015-12-13 00:54:25 +01:00
|
|
|
}
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|