2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-03-31 20:37:55 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.block.Block;
|
2017-07-30 01:03:45 +02:00
|
|
|
import net.minecraft.block.BlockMagma;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.block.material.Material;
|
2016-07-04 20:15:41 +02:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-10-18 15:28:06 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-12-18 17:28:29 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-01-07 21:41:28 +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-03-31 20:37:55 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class TileEntityHeatCollector extends TileEntityBase implements ISharingEnergyProvider, IEnergyDisplay {
|
2015-03-31 20:37:55 +02:00
|
|
|
|
2015-11-28 19:02:01 +01:00
|
|
|
public static final int ENERGY_PRODUCE = 40;
|
|
|
|
public static final int BLOCKS_NEEDED = 4;
|
2016-11-26 20:43:50 +01:00
|
|
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(30000, 0, 80);
|
2015-12-21 22:18:33 +01:00
|
|
|
private int oldEnergy;
|
2016-11-28 13:17:20 +01:00
|
|
|
private int disappearTime;
|
2015-11-28 19:02:01 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public TileEntityHeatCollector() {
|
2016-05-06 23:23:29 +02:00
|
|
|
super("heatCollector");
|
|
|
|
}
|
|
|
|
|
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-11-28 13:17:20 +01:00
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
this.storage.writeToNBT(compound);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (type == NBTType.SAVE_TILE) {
|
2016-11-28 13:17:20 +01:00
|
|
|
compound.setInteger("DisappearTime", this.disappearTime);
|
|
|
|
}
|
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-11-28 13:17:20 +01:00
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
this.storage.readFromNBT(compound);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (type == NBTType.SAVE_TILE) {
|
2016-11-28 13:17:20 +01:00
|
|
|
this.disappearTime = compound.getInteger("DisappearTime");
|
|
|
|
}
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +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) {
|
2019-02-27 19:53:05 +01:00
|
|
|
ArrayList<Integer> blocksAround = new ArrayList<>();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (ENERGY_PRODUCE <= this.storage.getMaxEnergyStored() - this.storage.getEnergyStored()) {
|
|
|
|
for (int i = 1; i <= 5; i++) {
|
2016-07-04 20:15:41 +02:00
|
|
|
BlockPos coords = this.pos.offset(WorldUtil.getDirectionBySidesInOrder(i));
|
2016-11-26 21:32:27 +01:00
|
|
|
IBlockState state = this.world.getBlockState(coords);
|
2016-07-04 20:15:41 +02:00
|
|
|
Block block = state.getBlock();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (block != null && this.world.getBlockState(coords).getMaterial() == Material.LAVA && block.getMetaFromState(state) == 0 || this.world.getBlockState(coords).getBlock() instanceof BlockMagma) {
|
2016-04-20 21:39:03 +02:00
|
|
|
blocksAround.add(i);
|
2015-03-31 20:37:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (blocksAround.size() >= BLOCKS_NEEDED) {
|
2016-11-23 18:10:55 +01:00
|
|
|
this.storage.receiveEnergyInternal(ENERGY_PRODUCE, false);
|
2015-05-20 22:39:43 +02:00
|
|
|
this.markDirty();
|
2015-03-31 20:37:55 +02:00
|
|
|
|
2016-11-28 13:17:20 +01:00
|
|
|
this.disappearTime++;
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.disappearTime >= 1000) {
|
2016-11-28 13:17:20 +01:00
|
|
|
this.disappearTime = 0;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.world.rand.nextInt(200) == 0) {
|
2016-11-28 13:17:20 +01:00
|
|
|
int randomSide = blocksAround.get(this.world.rand.nextInt(blocksAround.size()));
|
|
|
|
this.world.setBlockToAir(this.pos.offset(WorldUtil.getDirectionBySidesInOrder(randomSide)));
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-31 17:14:56 +01:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()) {
|
2015-12-21 22:18:33 +01:00
|
|
|
this.oldEnergy = this.storage.getEnergyStored();
|
|
|
|
}
|
2015-03-31 20:37:55 +02:00
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
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-08-02 13:08:22 +02: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-08-31 20:16:36 +02:00
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getEnergyToSplitShare() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return this.storage.getEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean doesShareEnergy() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public EnumFacing[] getEnergyShareSides() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return EnumFacing.values();
|
|
|
|
}
|
2016-11-26 08:58:42 +01:00
|
|
|
|
2016-12-18 17:28:29 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean canShareTo(TileEntity tile) {
|
2016-12-18 17:28:29 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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-03-31 20:37:55 +02:00
|
|
|
}
|