2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("TileEntityGreenhouseGlass.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-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-04-19 01:50:02 +02:00
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockGrass;
|
|
|
|
import net.minecraft.block.IGrowable;
|
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-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2015-07-25 11:06:10 +02:00
|
|
|
import net.minecraftforge.common.IPlantable;
|
2015-04-19 01:50:02 +02:00
|
|
|
|
|
|
|
public class TileEntityGreenhouseGlass extends TileEntityBase{
|
|
|
|
|
|
|
|
private int timeUntilNextFert;
|
|
|
|
|
2016-05-06 23:23:29 +02:00
|
|
|
public TileEntityGreenhouseGlass(){
|
|
|
|
super("greenhouseGlass");
|
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
2016-07-02 15:01:46 +02:00
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.writeSyncableNBT(compound, type);
|
|
|
|
if(type != NBTType.SAVE_BLOCK){
|
|
|
|
this.timeUntilNextFert = compound.getInteger("Time");
|
|
|
|
}
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-02 15:01:46 +02:00
|
|
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.readSyncableNBT(compound, type);
|
|
|
|
if(type != NBTType.SAVE_BLOCK){
|
|
|
|
compound.setInteger("Time", this.timeUntilNextFert);
|
|
|
|
}
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
2015-04-19 01:50:02 +02:00
|
|
|
@Override
|
|
|
|
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){
|
|
|
|
if(this.worldObj.canBlockSeeSky(this.getPos()) && this.worldObj.isDaytime()){
|
2015-11-29 00:38:22 +01:00
|
|
|
if(this.timeUntilNextFert > 0){
|
|
|
|
this.timeUntilNextFert--;
|
2016-05-02 17:46:53 +02:00
|
|
|
if(this.timeUntilNextFert <= 0){
|
2016-01-08 13:31:58 +01:00
|
|
|
BlockPos blockToFert = this.blockToFertilize();
|
2015-12-05 12:12:12 +01:00
|
|
|
if(blockToFert != null){
|
2016-07-04 20:15:41 +02:00
|
|
|
IBlockState state = this.worldObj.getBlockState(blockToFert);
|
|
|
|
Block block = state.getBlock();
|
|
|
|
int metaBefore = block.getMetaFromState(state);
|
2016-11-02 19:36:32 +01:00
|
|
|
block.updateTick(this.worldObj, blockToFert, this.worldObj.getBlockState(blockToFert), this.worldObj.rand);
|
2015-07-25 11:06:10 +02:00
|
|
|
|
2016-07-04 20:15:41 +02:00
|
|
|
IBlockState newState = this.worldObj.getBlockState(blockToFert);
|
|
|
|
if(newState.getBlock().getMetaFromState(newState) != metaBefore){
|
2016-06-03 21:05:49 +02:00
|
|
|
this.worldObj.playEvent(2005, blockToFert, 0);
|
2015-12-04 23:51:38 +01:00
|
|
|
}
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
|
|
|
}
|
2015-11-29 00:38:22 +01:00
|
|
|
}
|
|
|
|
else{
|
2016-08-10 04:50:42 +02:00
|
|
|
int time = 100;
|
2016-11-02 19:36:32 +01:00
|
|
|
this.timeUntilNextFert = time+this.worldObj.rand.nextInt(time);
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-08 13:31:58 +01:00
|
|
|
public BlockPos blockToFertilize(){
|
2016-05-16 22:52:27 +02:00
|
|
|
for(int i = this.pos.getY()-1; i > 0; i--){
|
|
|
|
BlockPos offset = new BlockPos(this.pos.getX(), i, this.pos.getZ());
|
2016-07-06 21:56:15 +02:00
|
|
|
Block block = this.worldObj.getBlockState(offset).getBlock();
|
|
|
|
if(block != null && !this.worldObj.isAirBlock(offset)){
|
2015-07-25 11:06:10 +02:00
|
|
|
if((block instanceof IGrowable || block instanceof IPlantable) && !(block instanceof BlockGrass)){
|
2016-01-07 23:42:42 +01:00
|
|
|
return offset;
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
2015-10-02 16:48:01 +02:00
|
|
|
else{
|
|
|
|
return null;
|
|
|
|
}
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|