2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-06-06 01:25:53 +02:00
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheMiscBlocks;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
2016-07-04 20:15:41 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
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-11-26 08:58:42 +01:00
|
|
|
import net.minecraftforge.energy.IEnergyStorage;
|
2015-06-06 01:25:53 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class TileEntityLavaFactoryController extends TileEntityBase implements 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;
|
2016-11-26 20:43:50 +01:00
|
|
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(300000, 2000, 0);
|
2015-10-03 10:16:18 +02:00
|
|
|
private int currentWorkTime;
|
2015-12-23 14:03:41 +01:00
|
|
|
private int oldEnergy;
|
2015-07-25 05:28:31 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public TileEntityLavaFactoryController() {
|
2016-05-06 23:23:29 +02:00
|
|
|
super("lavaFactory");
|
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
2016-07-02 15:01:46 +02:00
|
|
|
super.writeSyncableNBT(compound, type);
|
2016-02-01 17:49:55 +01:00
|
|
|
this.storage.writeToNBT(compound);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (type != NBTType.SAVE_BLOCK) {
|
2016-07-02 15:01:46 +02:00
|
|
|
compound.setInteger("WorkTime", this.currentWorkTime);
|
|
|
|
}
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
2016-07-02 15:01:46 +02:00
|
|
|
super.readSyncableNBT(compound, type);
|
2016-02-01 17:49:55 +01:00
|
|
|
this.storage.readFromNBT(compound);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (type != NBTType.SAVE_BLOCK) {
|
2016-07-02 15:01:46 +02:00
|
|
|
this.currentWorkTime = compound.getInteger("WorkTime");
|
|
|
|
}
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
2015-06-06 01:25:53 +02:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void updateEntity() {
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!this.world.isRemote) {
|
|
|
|
if (this.storage.getEnergyStored() >= ENERGY_USE && this.isMultiblock() == HAS_AIR) {
|
2015-06-06 01:25:53 +02:00
|
|
|
this.currentWorkTime++;
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.currentWorkTime >= 200) {
|
2015-06-06 01:25:53 +02:00
|
|
|
this.currentWorkTime = 0;
|
2016-11-26 21:32:27 +01:00
|
|
|
this.world.setBlockState(this.pos.up(), Blocks.LAVA.getDefaultState(), 2);
|
2016-11-23 18:10:55 +01:00
|
|
|
this.storage.extractEnergyInternal(ENERGY_USE, false);
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2015-10-02 16:48:01 +02:00
|
|
|
this.currentWorkTime = 0;
|
|
|
|
}
|
2015-12-23 14:03:41 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()) {
|
2015-12-23 14:03:41 +01:00
|
|
|
this.oldEnergy = this.storage.getEnergyStored();
|
|
|
|
}
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public int isMultiblock() {
|
2016-01-08 13:31:58 +01:00
|
|
|
BlockPos thisPos = this.pos;
|
2019-05-02 09:10:29 +02:00
|
|
|
BlockPos[] positions = new BlockPos[] { thisPos.add(1, 1, 0), thisPos.add(-1, 1, 0), thisPos.add(0, 1, 1), thisPos.add(0, 1, -1) };
|
2016-01-07 23:42:42 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (WorldUtil.hasBlocksInPlacesGiven(positions, InitBlocks.blockMisc, TheMiscBlocks.LAVA_FACTORY_CASE.ordinal(), this.world)) {
|
2016-07-04 20:15:41 +02:00
|
|
|
BlockPos pos = thisPos.up();
|
2016-11-26 21:32:27 +01:00
|
|
|
IBlockState state = this.world.getBlockState(pos);
|
2016-07-04 20:15:41 +02:00
|
|
|
Block block = state.getBlock();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (block == Blocks.LAVA || block == Blocks.FLOWING_LAVA) { return HAS_LAVA; }
|
|
|
|
if (block == null || this.world.isAirBlock(pos)) { return HAS_AIR; }
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|
|
|
|
return NOT_MULTI;
|
|
|
|
}
|
|
|
|
|
2015-12-13 00:54:25 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public CustomEnergyStorage getEnergyStorage() {
|
2016-07-21 13:22:55 +02:00
|
|
|
return this.storage;
|
2015-12-13 00:54:25 +01:00
|
|
|
}
|
2016-07-02 18:39:47 +02:00
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean needsHoldShift() {
|
2016-07-02 18:39:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-11-26 08:58:42 +01:00
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
|
2016-11-26 08:58:42 +01:00
|
|
|
return this.storage;
|
|
|
|
}
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|