diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockGreenhouseGlass.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockGreenhouseGlass.java index 5c2f42cfb..1feae64bb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockGreenhouseGlass.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockGreenhouseGlass.java @@ -10,15 +10,18 @@ package de.ellpeck.actuallyadditions.mod.blocks; -import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; -import de.ellpeck.actuallyadditions.mod.tile.TileEntityGreenhouseGlass; +import java.util.Random; + +import org.apache.commons.lang3.tuple.Triple; + +import de.ellpeck.actuallyadditions.mod.blocks.base.BlockBase; import net.minecraft.block.Block; +import net.minecraft.block.IGrowable; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; @@ -27,50 +30,73 @@ import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class BlockGreenhouseGlass extends BlockContainerBase{ +public class BlockGreenhouseGlass extends BlockBase { - public BlockGreenhouseGlass(String name){ - super(Material.ROCK, name); - this.setHarvestLevel("pickaxe", 0); - this.setHardness(0.5F); - this.setResistance(10.0F); - this.setSoundType(SoundType.STONE); - } + public BlockGreenhouseGlass(String name) { + super(Material.GLASS, name); + this.setHarvestLevel("pickaxe", 0); + this.setHardness(0.5F); + this.setResistance(10.0F); + this.setSoundType(SoundType.GLASS); + this.setTickRandomly(true); + } - @Override - public boolean isFullCube(IBlockState state){ - return false; - } + @Override + public boolean isFullCube(IBlockState state) { + return true; + } + + @Override + public boolean isOpaqueCube(IBlockState state) { + return false; + } - @Override - @Deprecated - @SideOnly(Side.CLIENT) - public boolean shouldSideBeRendered(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side){ - IBlockState otherState = world.getBlockState(pos.offset(side)); - Block block = otherState.getBlock(); + @Override + @Deprecated + @SideOnly(Side.CLIENT) + public boolean shouldSideBeRendered(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) { + IBlockState otherState = world.getBlockState(pos.offset(side)); + Block block = otherState.getBlock(); - return state != otherState || block != this && super.shouldSideBeRendered(state, world, pos, side); + return state != otherState || block != this && super.shouldSideBeRendered(state, world, pos, side); - } + } - @Override - public boolean isOpaqueCube(IBlockState state){ - return false; - } + @Override + @SideOnly(Side.CLIENT) + public BlockRenderLayer getBlockLayer() { + return BlockRenderLayer.CUTOUT; + } - @Override - @SideOnly(Side.CLIENT) - public BlockRenderLayer getBlockLayer(){ - return BlockRenderLayer.CUTOUT; - } + @Override + public EnumRarity getRarity(ItemStack stack) { + return EnumRarity.EPIC; + } - @Override - public EnumRarity getRarity(ItemStack stack){ - return EnumRarity.EPIC; - } + @Override + public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) { + if (world.isRemote) return; - @Override - public TileEntity createNewTileEntity(World world, int par2){ - return new TileEntityGreenhouseGlass(); - } + if (rand.nextInt(2) == 0 && world.canBlockSeeSky(pos) && world.isDaytime()) { + + Triple trip = firstSolidBlock(world, pos); + + if (trip != null && trip.getRight().canGrow(world, trip.getLeft(), trip.getMiddle(), false)) { + trip.getRight().grow(world, rand, trip.getLeft(), trip.getMiddle()); + world.playEvent(2005, trip.getMiddle().isOpaqueCube() ? trip.getLeft().up() : trip.getLeft(), 0); + } + } + } + + public static Triple firstSolidBlock(World world, BlockPos glassPos) { + BlockPos.MutableBlockPos mut = new BlockPos.MutableBlockPos(glassPos); + while (true) { + mut.setPos(mut.getX(), mut.getY() - 1, mut.getZ()); + IBlockState state = world.getBlockState(mut); + if (!state.getBlock().isAir(state, world, mut)) { + if (state.getBlock() instanceof IGrowable) return Triple.of(mut.toImmutable(), state, (IGrowable) state.getBlock()); + else return null; + } + } + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java index 89ecb26aa..158a7bfa1 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java @@ -66,7 +66,6 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{ register(TileEntityFurnaceSolar.class); register(TileEntityHeatCollector.class); register(TileEntityItemRepairer.class); - register(TileEntityGreenhouseGlass.class); register(TileEntityBreaker.class); register(TileEntityDropper.class); register(TileEntityInputterAdvanced.class); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGreenhouseGlass.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGreenhouseGlass.java deleted file mode 100644 index 13c0402a1..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGreenhouseGlass.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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 - * - * © 2015-2017 Ellpeck - */ - -package de.ellpeck.actuallyadditions.mod.tile; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockGrass; -import net.minecraft.block.IGrowable; -import net.minecraft.block.state.IBlockState; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.common.IPlantable; - -public class TileEntityGreenhouseGlass extends TileEntityBase{ - - private int timeUntilNextFert; - - public TileEntityGreenhouseGlass(){ - super("greenhouseGlass"); - } - - @Override - public void writeSyncableNBT(NBTTagCompound compound, NBTType type){ - super.writeSyncableNBT(compound, type); - if(type != NBTType.SAVE_BLOCK){ - this.timeUntilNextFert = compound.getInteger("Time"); - } - } - - @Override - public void readSyncableNBT(NBTTagCompound compound, NBTType type){ - super.readSyncableNBT(compound, type); - if(type != NBTType.SAVE_BLOCK){ - compound.setInteger("Time", this.timeUntilNextFert); - } - } - - @Override - public void updateEntity(){ - super.updateEntity(); - if(!this.world.isRemote){ - if(this.world.canBlockSeeSky(this.getPos()) && this.world.isDaytime()){ - if(this.timeUntilNextFert > 0){ - this.timeUntilNextFert--; - if(this.timeUntilNextFert <= 0){ - BlockPos blockToFert = this.blockToFertilize(); - if(blockToFert != null){ - IBlockState state = this.world.getBlockState(blockToFert); - Block block = state.getBlock(); - int metaBefore = block.getMetaFromState(state); - block.updateTick(this.world, blockToFert, this.world.getBlockState(blockToFert), this.world.rand); - - IBlockState newState = this.world.getBlockState(blockToFert); - if(newState.getBlock().getMetaFromState(newState) != metaBefore){ - this.world.playEvent(2005, blockToFert, 0); - } - } - } - } - else{ - int time = 50; - this.timeUntilNextFert = time+this.world.rand.nextInt(time); - } - } - } - } - - public BlockPos blockToFertilize(){ - for(int i = this.pos.getY()-1; i > 0; i--){ - BlockPos offset = new BlockPos(this.pos.getX(), i, this.pos.getZ()); - Block block = this.world.getBlockState(offset).getBlock(); - if(block != null && !this.world.isAirBlock(offset)){ - if((block instanceof IGrowable || block instanceof IPlantable) && !(block instanceof BlockGrass)){ - return offset; - } - else{ - return null; - } - } - } - return null; - } -}