From a926debe1482051f49fa59e298981a7dcbe1623f Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Thu, 17 Dec 2020 12:44:43 +0300 Subject: [PATCH] Fixes --- .../betterend/blocks/BlockSilkMothNest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/main/java/ru/betterend/blocks/BlockSilkMothNest.java b/src/main/java/ru/betterend/blocks/BlockSilkMothNest.java index a41fd6fb..1c99e9cb 100644 --- a/src/main/java/ru/betterend/blocks/BlockSilkMothNest.java +++ b/src/main/java/ru/betterend/blocks/BlockSilkMothNest.java @@ -1,23 +1,36 @@ package ru.betterend.blocks; +import java.util.Collections; +import java.util.List; + import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; import net.minecraft.block.Material; import net.minecraft.block.ShapeContext; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemPlacementContext; +import net.minecraft.item.ItemStack; +import net.minecraft.loot.context.LootContext; import net.minecraft.sound.BlockSoundGroup; import net.minecraft.state.StateManager; import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.DirectionProperty; import net.minecraft.state.property.Properties; +import net.minecraft.tag.BlockTags; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; +import ru.betterend.util.BlocksHelper; public class BlockSilkMothNest extends BlockBase implements IRenderTypeable { public static final BooleanProperty ACTIVE = BlockProperties.ACTIVE; @@ -50,4 +63,44 @@ public class BlockSilkMothNest extends BlockBase implements IRenderTypeable { Direction dir = ctx.getPlayerFacing().getOpposite(); return this.getDefaultState().with(FACING, dir); } + + @Override + public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { + if (!state.get(ACTIVE)) { + if (sideCoversSmallSquare(world, pos.up(), Direction.DOWN) || world.getBlockState(pos.up()).isIn(BlockTags.LEAVES)) { + return state; + } + else { + return Blocks.AIR.getDefaultState(); + } + } + return state; + } + + @Override + public BlockState rotate(BlockState state, BlockRotation rotation) { + return BlocksHelper.rotateHorizontal(state, rotation, FACING); + } + + @Override + public BlockState mirror(BlockState state, BlockMirror mirror) { + return BlocksHelper.mirrorHorizontal(state, mirror, FACING); + } + + @Override + public List getDroppedStacks(BlockState state, LootContext.Builder builder) { + return state.get(ACTIVE) ? Collections.singletonList(new ItemStack(this)) : Collections.emptyList(); + } + + @Override + public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) { + if (!state.get(ACTIVE) && player.isCreative()) { + BlocksHelper.setWithUpdate(world, pos.down(), Blocks.AIR); + } + BlockState up = world.getBlockState(pos.up()); + if (up.isOf(this) && !up.get(ACTIVE)) { + BlocksHelper.setWithUpdate(world, pos.up(), Blocks.AIR); + } + super.onBreak(world, pos, state, player); + } }