This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
EnergonRelics/src/main/java/com/thebrokenrail/energonrelics/block/BlockBreakerBlock.java

51 lines
2.0 KiB
Java

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<Block, BlockState> 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<BlockEntityType<BlockEntity>, BlockEntity> getFactory() {
return BlockBreakerBlockEntity::new;
}
}