package com.thebrokenrail.energonrelics.block; import com.thebrokenrail.energonrelics.block.entity.BlockBreakerBlockEntity; import com.thebrokenrail.energonrelics.block.util.energy.FacingEnergyProviderBlock; 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 FacingEnergyProviderBlock { public static final BooleanProperty POWERED = Properties.POWERED; public BlockBreakerBlock() { super(FabricBlockSettings.copy(Blocks.BLACKSTONE).strength(2.0F, 6.0F).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; } }