2015-04-19 01:50:02 +02:00
|
|
|
package ellpeck.actuallyadditions.tile;
|
|
|
|
|
2015-04-24 19:22:03 +02:00
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
2015-07-07 11:51:05 +02:00
|
|
|
import ellpeck.actuallyadditions.util.WorldPos;
|
2015-04-19 01:50:02 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockGrass;
|
|
|
|
import net.minecraft.block.IGrowable;
|
2015-07-25 11:06:10 +02:00
|
|
|
import net.minecraftforge.common.IPlantable;
|
2015-04-19 01:50:02 +02:00
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
public class TileEntityGreenhouseGlass extends TileEntityBase{
|
|
|
|
|
2015-04-24 19:22:03 +02:00
|
|
|
private int timeUntilNextFertToSet = ConfigIntValues.GLASS_TIME_NEEDED.getValue();
|
2015-04-19 01:50:02 +02:00
|
|
|
|
|
|
|
private int timeUntilNextFert;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
|
|
|
if(!worldObj.isRemote){
|
|
|
|
if(worldObj.canBlockSeeTheSky(xCoord, yCoord, zCoord) && worldObj.isDaytime()){
|
2015-07-07 11:51:05 +02:00
|
|
|
WorldPos blockToFert = this.blockToFertilize();
|
2015-04-19 01:50:02 +02:00
|
|
|
if(blockToFert != null){
|
|
|
|
if(this.timeUntilNextFert > 0){
|
|
|
|
this.timeUntilNextFert--;
|
|
|
|
if(timeUntilNextFert <= 0){
|
2015-07-25 11:06:10 +02:00
|
|
|
int metaBefore = blockToFert.getMetadata();
|
2015-07-07 11:51:05 +02:00
|
|
|
worldObj.getBlock(blockToFert.getX(), blockToFert.getY(), blockToFert.getZ()).updateTick(worldObj, blockToFert.getX(), blockToFert.getY(), blockToFert.getZ(), worldObj.rand);
|
2015-07-25 11:06:10 +02:00
|
|
|
|
|
|
|
if(blockToFert.getMetadata() != metaBefore){
|
|
|
|
worldObj.playAuxSFX(2005, blockToFert.getX(), blockToFert.getY(), blockToFert.getZ(), 0);
|
|
|
|
}
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
|
|
|
}
|
2015-06-06 01:25:53 +02:00
|
|
|
else this.timeUntilNextFert = this.timeUntilNextFertToSet+new Random().nextInt(this.timeUntilNextFertToSet);
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:51:05 +02:00
|
|
|
public WorldPos blockToFertilize(){
|
2015-04-19 01:50:02 +02:00
|
|
|
for(int i = yCoord-1; i > 0; i--){
|
|
|
|
Block block = worldObj.getBlock(xCoord, i, zCoord);
|
2015-06-18 13:14:57 +02:00
|
|
|
if(block != null && !(worldObj.isAirBlock(xCoord, i, zCoord))){
|
2015-07-25 11:06:10 +02:00
|
|
|
if((block instanceof IGrowable || block instanceof IPlantable) && !(block instanceof BlockGrass)){
|
2015-07-07 11:56:38 +02:00
|
|
|
return new WorldPos(worldObj, xCoord, i, zCoord);
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
|
|
|
else return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|