mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-05 16:39:10 +01:00
f602eccca0
Don't need it.
81 lines
2.9 KiB
Java
81 lines
2.9 KiB
Java
/*
|
|
* 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://ellpeck.de/actaddlicense/
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
*
|
|
* © 2016 Ellpeck
|
|
*/
|
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
|
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
|
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockGrass;
|
|
import net.minecraft.block.IGrowable;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.util.BlockPos;
|
|
import net.minecraftforge.common.IPlantable;
|
|
|
|
public class TileEntityGreenhouseGlass extends TileEntityBase{
|
|
|
|
private int timeUntilNextFert;
|
|
|
|
@Override
|
|
public void updateEntity(){
|
|
super.updateEntity();
|
|
if(!worldObj.isRemote){
|
|
if(worldObj.canBlockSeeSky(this.getPos()) && worldObj.isDaytime()){
|
|
if(this.timeUntilNextFert > 0){
|
|
this.timeUntilNextFert--;
|
|
if(timeUntilNextFert <= 0){
|
|
BlockPos blockToFert = this.blockToFertilize();
|
|
if(blockToFert != null){
|
|
int metaBefore = PosUtil.getMetadata(blockToFert, worldObj);
|
|
PosUtil.getBlock(blockToFert, worldObj).updateTick(worldObj, blockToFert, worldObj.getBlockState(blockToFert), Util.RANDOM);
|
|
|
|
if(PosUtil.getMetadata(blockToFert, worldObj) != metaBefore){
|
|
worldObj.playAuxSFX(2005, blockToFert, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
int time = 300;
|
|
this.timeUntilNextFert = time+Util.RANDOM.nextInt(time);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public BlockPos blockToFertilize(){
|
|
for(int i = -1; i > 0; i--){
|
|
BlockPos offset = PosUtil.offset(this.pos, 0, i, 0);
|
|
Block block = PosUtil.getBlock(pos, worldObj);
|
|
if(block != null && !(worldObj.isAirBlock(offset))){
|
|
if((block instanceof IGrowable || block instanceof IPlantable) && !(block instanceof BlockGrass)){
|
|
return offset;
|
|
}
|
|
else{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public void writeSyncableNBT(NBTTagCompound compound, boolean isForSync){
|
|
super.writeSyncableNBT(compound, isForSync);
|
|
this.timeUntilNextFert = compound.getInteger("Time");
|
|
}
|
|
|
|
@Override
|
|
public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){
|
|
super.readSyncableNBT(compound, isForSync);
|
|
compound.setInteger("Time", this.timeUntilNextFert);
|
|
}
|
|
}
|