2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("TileEntityHeatCollector.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-03-31 20:37:55 +02:00
|
|
|
package ellpeck.actuallyadditions.tile;
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
import cofh.api.energy.EnergyStorage;
|
|
|
|
import cofh.api.energy.IEnergyProvider;
|
2015-11-22 18:58:23 +01:00
|
|
|
import ellpeck.actuallyadditions.util.Util;
|
2015-07-07 11:51:05 +02:00
|
|
|
import ellpeck.actuallyadditions.util.WorldPos;
|
2015-05-20 22:39:43 +02:00
|
|
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
2015-10-18 15:28:06 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2015-03-31 20:37:55 +02:00
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
public class TileEntityHeatCollector extends TileEntityBase implements IEnergyProvider{
|
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;
|
2015-12-01 19:48:09 +01:00
|
|
|
public EnergyStorage storage = new EnergyStorage(30000);
|
2015-11-28 19:02:01 +01:00
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
2015-03-31 20:37:55 +02:00
|
|
|
public void updateEntity(){
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2015-03-31 20:37:55 +02:00
|
|
|
if(!worldObj.isRemote){
|
|
|
|
ArrayList<Integer> blocksAround = new ArrayList<Integer>();
|
2015-11-28 19:02:01 +01:00
|
|
|
if(ENERGY_PRODUCE <= this.getMaxEnergyStored(ForgeDirection.UNKNOWN)-this.getEnergyStored(ForgeDirection.UNKNOWN)){
|
2015-05-20 22:39:43 +02:00
|
|
|
for(int i = 1; i <= 5; i++){
|
2015-10-05 16:53:28 +02:00
|
|
|
WorldPos coords = WorldUtil.getCoordsFromSide(WorldUtil.getDirectionBySidesInOrder(i), worldObj, xCoord, yCoord, zCoord, 0);
|
2015-05-20 22:39:43 +02:00
|
|
|
if(coords != null){
|
2015-07-07 11:51:05 +02:00
|
|
|
Block block = worldObj.getBlock(coords.getX(), coords.getY(), coords.getZ());
|
|
|
|
if(block != null && block.getMaterial() == Material.lava && worldObj.getBlockMetadata(coords.getX(), coords.getY(), coords.getZ()) == 0){
|
2015-05-20 22:39:43 +02:00
|
|
|
blocksAround.add(i);
|
|
|
|
}
|
2015-03-31 20:37:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-28 19:02:01 +01:00
|
|
|
if(blocksAround.size() >= BLOCKS_NEEDED){
|
|
|
|
this.storage.receiveEnergy(ENERGY_PRODUCE, false);
|
2015-05-20 22:39:43 +02:00
|
|
|
this.markDirty();
|
2015-03-31 20:37:55 +02:00
|
|
|
|
2015-11-28 19:02:01 +01:00
|
|
|
if(Util.RANDOM.nextInt(10) == 0){
|
2015-11-22 18:58:23 +01:00
|
|
|
int randomSide = blocksAround.get(Util.RANDOM.nextInt(blocksAround.size()));
|
2015-07-27 08:40:24 +02:00
|
|
|
WorldUtil.breakBlockAtSide(WorldUtil.getDirectionBySidesInOrder(randomSide), worldObj, xCoord, yCoord, zCoord);
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-31 17:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(this.getEnergyStored(ForgeDirection.UNKNOWN) > 0){
|
|
|
|
WorldUtil.pushEnergy(worldObj, xCoord, yCoord, zCoord, ForgeDirection.UP, this.storage);
|
2015-03-31 20:37:55 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@Override
|
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, boolean isForSync){
|
|
|
|
this.storage.writeToNBT(compound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){
|
|
|
|
this.storage.readFromNBT(compound);
|
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
|
|
|
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate){
|
|
|
|
return this.storage.extractEnergy(maxExtract, simulate);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEnergyStored(ForgeDirection from){
|
|
|
|
return this.storage.getEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxEnergyStored(ForgeDirection from){
|
|
|
|
return this.storage.getMaxEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canConnectEnergy(ForgeDirection from){
|
|
|
|
return from == ForgeDirection.UP;
|
|
|
|
}
|
2015-03-31 20:37:55 +02:00
|
|
|
}
|