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 de.ellpeck.actuallyadditions.mod.blocks.base.BlockBase;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.server.level.ServerLevel;
|
2024-03-03 01:20:53 +01:00
|
|
|
import net.minecraft.util.RandomSource;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.world.level.BlockGetter;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
import net.minecraft.world.level.block.BonemealableBlock;
|
|
|
|
import net.minecraft.world.level.block.RenderShape;
|
|
|
|
import net.minecraft.world.level.block.SoundType;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
2021-02-27 13:24:45 +01:00
|
|
|
import org.apache.commons.lang3.tuple.Triple;
|
|
|
|
|
2018-01-04 20:40:58 +01:00
|
|
|
public class BlockGreenhouseGlass extends BlockBase {
|
2021-02-27 13:24:45 +01:00
|
|
|
public BlockGreenhouseGlass() {
|
2024-03-02 21:23:08 +01:00
|
|
|
super(ActuallyBlocks.defaultPickProps(0.5F, 10.0F).sound(SoundType.GLASS).randomTicks());
|
2018-10-28 18:52:26 +01:00
|
|
|
}
|
|
|
|
|
2018-09-26 08:59:22 +02:00
|
|
|
|
2021-03-01 20:14:50 +01:00
|
|
|
// TODO: [port] figure this out
|
|
|
|
// @Override
|
|
|
|
// @Deprecated
|
|
|
|
// @OnlyIn(Dist.CLIENT)
|
|
|
|
// public boolean shouldSideBeRendered(BlockState state, IBlockAccess world, BlockPos pos, Direction side) {
|
|
|
|
// BlockState otherState = world.getBlockState(pos.offset(side));
|
|
|
|
// Block block = otherState.getBlock();
|
|
|
|
//
|
|
|
|
// return state != otherState || block != this && super.shouldSideBeRendered(state, world, pos, side);
|
|
|
|
// }
|
2018-09-26 08:59:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public RenderShape getRenderShape(BlockState state) {
|
|
|
|
return RenderShape.INVISIBLE;
|
2018-09-26 08:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-03-03 01:20:53 +01:00
|
|
|
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, RandomSource rand) {
|
2021-08-22 17:09:06 +02:00
|
|
|
if (world.isClientSide) {
|
2021-02-27 13:24:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-08-22 17:09:06 +02:00
|
|
|
if (world.canSeeSkyFromBelowWater(pos) && world.isDay()) {
|
2024-03-02 21:23:08 +01:00
|
|
|
Triple<BlockPos, BlockState, BonemealableBlock> trip = this.firstBlock(world, pos);
|
2018-09-26 08:59:22 +02:00
|
|
|
boolean once = false;
|
2021-02-27 13:24:45 +01:00
|
|
|
if (trip != null) {
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
BlockState growState = i == 0
|
|
|
|
? trip.getMiddle()
|
|
|
|
: world.getBlockState(trip.getLeft());
|
2021-08-22 17:09:06 +02:00
|
|
|
if (growState.getBlock() == trip.getRight() && trip.getRight().isValidBonemealTarget(world, trip.getLeft(), growState, false)) {
|
|
|
|
trip.getRight().performBonemeal(world, rand, trip.getLeft(), growState);
|
2021-02-27 13:24:45 +01:00
|
|
|
once = true;
|
|
|
|
}
|
2018-09-26 08:59:22 +02:00
|
|
|
}
|
|
|
|
}
|
2021-02-27 13:24:45 +01:00
|
|
|
if (once) {
|
2021-08-22 17:09:06 +02:00
|
|
|
world.levelEvent(2005, trip.getMiddle().isSolidRender(world, trip.getLeft())
|
|
|
|
? trip.getLeft().above()
|
2021-02-27 13:24:45 +01:00
|
|
|
: trip.getLeft(), 0);
|
|
|
|
}
|
2018-09-26 08:59:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public Triple<BlockPos, BlockState, BonemealableBlock> firstBlock(Level world, BlockPos glassPos) {
|
|
|
|
BlockPos.MutableBlockPos mut = new BlockPos(glassPos).mutable();
|
2018-09-26 08:59:22 +02:00
|
|
|
while (true) {
|
2021-08-22 17:09:06 +02:00
|
|
|
mut.set(mut.getX(), mut.getY() - 1, mut.getZ());
|
2021-02-27 13:24:45 +01:00
|
|
|
if (mut.getY() < 0) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-02-26 22:15:48 +01:00
|
|
|
BlockState state = world.getBlockState(mut);
|
2024-03-02 21:23:08 +01:00
|
|
|
if (state.isSolidRender(world, mut) || state.getBlock() instanceof BonemealableBlock || state.getBlock() == this) {
|
|
|
|
if (state.getBlock() instanceof BonemealableBlock) {
|
|
|
|
return Triple.of(mut.immutable(), state, (BonemealableBlock) state.getBlock());
|
2021-02-27 13:24:45 +01:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2018-09-26 08:59:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-01 20:14:50 +01:00
|
|
|
|
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
|
|
|
|
return VoxelShapes.GLASS_SHAPE;
|
2021-03-01 20:14:50 +01:00
|
|
|
}
|
2015-04-19 01:50:02 +02:00
|
|
|
}
|