2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("BlockGreenhouseGlass.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
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.blocks;
|
2015-04-19 01:50:02 +02:00
|
|
|
|
2018-01-04 20:40:58 +01:00
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.tuple.Triple;
|
|
|
|
|
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockBase;
|
2016-01-09 02:36:43 +01:00
|
|
|
import net.minecraft.block.Block;
|
2018-01-04 20:40:58 +01:00
|
|
|
import net.minecraft.block.IGrowable;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.block.SoundType;
|
2015-04-19 01:50:02 +02:00
|
|
|
import net.minecraft.block.material.Material;
|
2016-01-09 02:36:43 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-04-19 01:50:02 +02:00
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.BlockRenderLayer;
|
2016-01-09 02:36:43 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-01-09 02:36:43 +01:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2015-04-19 01:50:02 +02:00
|
|
|
import net.minecraft.world.World;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-04-19 01:50:02 +02:00
|
|
|
|
2018-01-04 20:40:58 +01:00
|
|
|
public class BlockGreenhouseGlass extends BlockBase {
|
|
|
|
|
|
|
|
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 true;
|
|
|
|
}
|
2018-01-15 23:00:32 +01:00
|
|
|
|
2018-01-04 20:40:58 +01:00
|
|
|
@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();
|
|
|
|
|
|
|
|
return state != otherState || block != this && super.shouldSideBeRendered(state, world, pos, side);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public BlockRenderLayer getBlockLayer() {
|
|
|
|
return BlockRenderLayer.CUTOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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;
|
|
|
|
|
2018-01-04 20:51:19 +01:00
|
|
|
if (world.canBlockSeeSky(pos) && world.isDaytime()) {
|
|
|
|
Triple<BlockPos, IBlockState, IGrowable> trip = firstBlock(world, pos);
|
2018-01-04 20:40:58 +01:00
|
|
|
|
2018-01-04 20:51:19 +01:00
|
|
|
boolean once = false;
|
2018-01-15 23:00:32 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
if (trip != null && trip.getRight().canGrow(world, trip.getLeft(), trip.getMiddle(), false)) {
|
|
|
|
trip.getRight().grow(world, rand, trip.getLeft(), trip.getMiddle());
|
|
|
|
once = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (once) world.playEvent(2005, trip.getMiddle().isOpaqueCube() ? trip.getLeft().up() : trip.getLeft(), 0);
|
2018-01-04 20:40:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-04 20:51:19 +01:00
|
|
|
public static Triple<BlockPos, IBlockState, IGrowable> firstBlock(World world, BlockPos glassPos) {
|
2018-01-04 20:40:58 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|