2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("TileEntityGreenhouseGlass.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-12-30 22:02:15 +01:00
|
|
|
package de.ellpeck.actuallyadditions.tile;
|
2015-04-19 01:50:02 +02:00
|
|
|
|
2015-12-30 22:02:15 +01:00
|
|
|
import de.ellpeck.actuallyadditions.util.Position;
|
|
|
|
import de.ellpeck.actuallyadditions.util.Util;
|
2015-04-19 01:50:02 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockGrass;
|
|
|
|
import net.minecraft.block.IGrowable;
|
2015-10-18 15:28:06 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
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;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2015-04-19 01:50:02 +02:00
|
|
|
if(!worldObj.isRemote){
|
|
|
|
if(worldObj.canBlockSeeTheSky(xCoord, yCoord, zCoord) && worldObj.isDaytime()){
|
2015-11-29 00:38:22 +01:00
|
|
|
if(this.timeUntilNextFert > 0){
|
|
|
|
this.timeUntilNextFert--;
|
|
|
|
if(timeUntilNextFert <= 0){
|
2015-12-23 01:43:49 +01:00
|
|
|
Position blockToFert = this.blockToFertilize();
|
2015-12-05 12:12:12 +01:00
|
|
|
if(blockToFert != null){
|
2015-12-23 01:43:49 +01:00
|
|
|
int metaBefore = blockToFert.getMetadata(worldObj);
|
2015-12-04 23:51:38 +01:00
|
|
|
worldObj.getBlock(blockToFert.getX(), blockToFert.getY(), blockToFert.getZ()).updateTick(worldObj, blockToFert.getX(), blockToFert.getY(), blockToFert.getZ(), Util.RANDOM);
|
2015-07-25 11:06:10 +02:00
|
|
|
|
2015-12-23 01:43:49 +01:00
|
|
|
if(blockToFert.getMetadata(worldObj) != metaBefore){
|
2015-12-04 23:51:38 +01:00
|
|
|
worldObj.playAuxSFX(2005, blockToFert.getX(), blockToFert.getY(), blockToFert.getZ(), 0);
|
|
|
|
}
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
|
|
|
}
|
2015-11-29 00:38:22 +01:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
int time = 300;
|
|
|
|
this.timeUntilNextFert = time+Util.RANDOM.nextInt(time);
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-23 01:43:49 +01:00
|
|
|
public Position 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-12-23 01:43:49 +01:00
|
|
|
return new Position(xCoord, i, zCoord);
|
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;
|
|
|
|
}
|
|
|
|
|
2015-10-18 15:28:06 +02:00
|
|
|
@Override
|
2015-10-18 15:31:01 +02:00
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, boolean isForSync){
|
2015-12-21 22:18:33 +01:00
|
|
|
super.writeSyncableNBT(compound, isForSync);
|
2015-10-18 15:31:01 +02:00
|
|
|
this.timeUntilNextFert = compound.getInteger("Time");
|
2015-10-18 15:28:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-18 15:31:01 +02:00
|
|
|
public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){
|
2015-12-21 22:18:33 +01:00
|
|
|
super.readSyncableNBT(compound, isForSync);
|
2015-10-18 15:31:01 +02:00
|
|
|
compound.setInteger("Time", this.timeUntilNextFert);
|
2015-10-18 15:28:06 +02:00
|
|
|
}
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|