EnergonRelics/src/main/java/com/thebrokenrail/energonrelics/block/BlockBreakerBlock.java

51 lines
2.0 KiB
Java
Raw Normal View History

2020-07-22 18:07:29 +00:00
package com.thebrokenrail.energonrelics.block;
import com.thebrokenrail.energonrelics.block.entity.BlockBreakerBlockEntity;
2020-08-04 17:06:11 +00:00
import com.thebrokenrail.energonrelics.api.block.energy.FacingEnergyBlock;
2020-07-22 18:07:29 +00:00
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;
2020-07-26 23:05:59 +00:00
public class BlockBreakerBlock extends FacingEnergyBlock {
2020-07-22 18:07:29 +00:00
public static final BooleanProperty POWERED = Properties.POWERED;
public BlockBreakerBlock() {
2020-07-30 02:51:29 +00:00
super(FabricBlockSettings.copy(Blocks.POLISHED_BLACKSTONE_BRICKS).nonOpaque().lightLevel(state -> state.get(POWERED) ? 7 : 0));
2020-07-22 18:07:29 +00:00
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;
}
}