From b64d606a160115f60c34e3004624ab6dde1a425c Mon Sep 17 00:00:00 2001 From: Niklas Widmann Date: Thu, 17 Oct 2024 19:51:04 +0200 Subject: [PATCH] add lit state to vigil candles --- .../content/block/VigilCandleBlock.java | 38 ++++++++++++++++++- .../java/galena/oreganized/index/OBlocks.java | 3 +- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/main/java/galena/oreganized/content/block/VigilCandleBlock.java b/src/main/java/galena/oreganized/content/block/VigilCandleBlock.java index a81a86c0..85d3ec25 100644 --- a/src/main/java/galena/oreganized/content/block/VigilCandleBlock.java +++ b/src/main/java/galena/oreganized/content/block/VigilCandleBlock.java @@ -2,13 +2,22 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.AbstractCandleBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.LanternBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; @@ -16,6 +25,7 @@ import java.util.Optional; +import static net.minecraft.world.level.block.CandleBlock.LIT; import static net.minecraft.world.level.block.CandleBlock.MAX_CANDLES; import static net.minecraft.world.level.block.CandleBlock.MIN_CANDLES; import static net.minecraft.world.level.block.state.properties.BlockStateProperties.CANDLES; @@ -54,6 +64,7 @@ public VigilCandleBlock(Properties properties) { super(properties); registerDefaultState(defaultBlockState() .setValue(HANGING, false) + .setValue(LIT, false) .setValue(WATERLOGGED, false) .setValue(CANDLES, MIN_CANDLES)); } @@ -61,7 +72,7 @@ public VigilCandleBlock(Properties properties) { @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { super.createBlockStateDefinition(builder); - builder.add(CANDLES); + builder.add(CANDLES, LIT); } public boolean canBeReplaced(BlockState state, BlockPlaceContext context) { @@ -99,4 +110,29 @@ public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) { } } + public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if (player.getAbilities().mayBuild && player.getItemInHand(hand).isEmpty() && state.getValue(LIT)) { + AbstractCandleBlock.extinguish(player, state, level, pos); + return InteractionResult.sidedSuccess(level.isClientSide); + } else { + return InteractionResult.PASS; + } + } + + public boolean placeLiquid(LevelAccessor level, BlockPos pos, BlockState state, FluidState fluid) { + if (!state.getValue(WATERLOGGED) && fluid.getType() == Fluids.WATER) { + BlockState waterlogged = state.setValue(WATERLOGGED, true); + if (state.getValue(LIT)) { + AbstractCandleBlock.extinguish(null, waterlogged, level, pos); + } else { + level.setBlock(pos, waterlogged, 3); + } + + level.scheduleTick(pos, fluid.getType(), fluid.getType().getTickDelay(level)); + return true; + } else { + return false; + } + } + } diff --git a/src/main/java/galena/oreganized/index/OBlocks.java b/src/main/java/galena/oreganized/index/OBlocks.java index 4c3f7c1c..5294fdde 100644 --- a/src/main/java/galena/oreganized/index/OBlocks.java +++ b/src/main/java/galena/oreganized/index/OBlocks.java @@ -26,6 +26,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.CandleBlock; import net.minecraft.world.level.block.DropExperienceBlock; import net.minecraft.world.level.block.IceBlock; import net.minecraft.world.level.block.LiquidBlock; @@ -202,7 +203,7 @@ private static BlockBehaviour.Properties leadDecoProperties() { new MoltenLeadBlock(OFluids.MOLTEN_LEAD, BlockBehaviour.Properties.copy(Blocks.LAVA).mapColor(MapColor.COLOR_PURPLE))); public static final RegistryObject MOLTEN_LEAD_CAULDRON = HELPER.createBlock("molten_lead_cauldron", () -> new MoltenLeadCauldronBlock(BlockBehaviour.Properties.copy(Blocks.LAVA_CAULDRON).randomTicks())); - private static final Supplier VIGIL_CANDLE_PROPERTIES = () -> BlockBehaviour.Properties.of().lightLevel(state -> 10).sound(SoundType.METAL).pushReaction(PushReaction.DESTROY); + private static final Supplier VIGIL_CANDLE_PROPERTIES = () -> BlockBehaviour.Properties.of().lightLevel(CandleBlock.LIGHT_EMISSION).sound(SoundType.METAL).pushReaction(PushReaction.DESTROY); public static final RegistryObject VIGIL_CANDLE = register("vigil_candle", () ->new VigilCandleBlock(VIGIL_CANDLE_PROPERTIES.get())); public static final Map> COLORED_VIGIL_CANDLES = registerColored("vigil_candle", color -> new VigilCandleBlock(VIGIL_CANDLE_PROPERTIES.get().mapColor(color)));