Lamps require energy to work. Again. Closes #2227

This commit is contained in:
drcrazy 2020-09-25 00:54:48 +03:00
parent 22b0cdfe23
commit 7ba962196b
4 changed files with 30 additions and 21 deletions

View file

@ -50,7 +50,9 @@ import techreborn.blockentity.lighting.LampBlockEntity;
import org.jetbrains.annotations.Nullable;
public class BlockLamp extends BaseBlockEntityProvider {
import java.util.function.ToIntFunction;
public class LampBlock extends BaseBlockEntityProvider {
public static DirectionProperty FACING = Properties.FACING;
public static BooleanProperty ACTIVE;
@ -59,14 +61,18 @@ public class BlockLamp extends BaseBlockEntityProvider {
private final int cost;
private static final int brightness = 15;
public BlockLamp(int cost, double depth, double width) {
super(FabricBlockSettings.of(Material.REDSTONE_LAMP).strength(2f, 2f).lightLevel(brightness));
public LampBlock(int cost, double depth, double width) {
super(FabricBlockSettings.of(Material.REDSTONE_LAMP).strength(2f, 2f).lightLevel(createLightLevelFromBlockState()));
this.shape = genCuboidShapes(depth, width);
this.cost = cost;
this.setDefaultState(this.getStateManager().getDefaultState().with(FACING, Direction.NORTH).with(ACTIVE, false));
BlockWrenchEventHandler.wrenableBlocks.add(this);
}
private static ToIntFunction<BlockState> createLightLevelFromBlockState() {
return (blockState) -> isActive(blockState) ? brightness : 0;
}
private VoxelShape[] genCuboidShapes(double depth, double width) {
double culling = (16.0D - width) / 2;
return new VoxelShape[]{
@ -79,11 +85,6 @@ public class BlockLamp extends BaseBlockEntityProvider {
};
}
@Override
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, ShapeContext shapeContext) {
return shape[blockState.get(FACING).ordinal()];
}
public static boolean isActive(BlockState state) {
return state.contains(ACTIVE) && state.get(ACTIVE);
}
@ -131,11 +132,19 @@ public class BlockLamp extends BaseBlockEntityProvider {
return null;
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, ShapeContext shapeContext) {
return shape[blockState.get(FACING).ordinal()];
}
@SuppressWarnings("deprecation")
@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn, Hand hand, BlockHitResult hitResult) {
ItemStack stack = playerIn.getStackInHand(Hand.MAIN_HAND);