package com.thebrokenrail.energonrelics.block; import com.thebrokenrail.energonrelics.block.entity.BlockBreakerBlockEntity; import com.thebrokenrail.energonrelics.api.block.energy.FacingEnergyBlock; 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.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.state.StateManager; import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.Properties; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.world.WorldAccess; import java.util.function.Function; public class BlockBreakerBlock extends FacingEnergyBlock { public static final BooleanProperty POWERED = Properties.POWERED; public BlockBreakerBlock() { super(FabricBlockSettings.copy(Blocks.POLISHED_BLACKSTONE_BRICKS).nonOpaque().lightLevel(state -> state.get(POWERED) ? 7 : 0)); setDefaultState(getDefaultState().with(POWERED, false)); } @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder); builder.add(POWERED); } @SuppressWarnings("deprecation") @Override public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) { if (state.get(FACING) == direction) { BlockEntity entity = world.getBlockEntity(pos); if (entity instanceof BlockBreakerBlockEntity) { ((BlockBreakerBlockEntity) entity).resetProgress(); } } return super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom); } @Override protected Function, BlockEntity> getFactory() { return BlockBreakerBlockEntity::new; } }