Skip to content

Commit b64d606

Browse files
committed
add lit state to vigil candles
1 parent 4219bff commit b64d606

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/main/java/galena/oreganized/content/block/VigilCandleBlock.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,30 @@
22

33
import net.minecraft.core.BlockPos;
44
import net.minecraft.core.Direction;
5+
import net.minecraft.world.InteractionHand;
6+
import net.minecraft.world.InteractionResult;
7+
import net.minecraft.world.entity.player.Player;
58
import net.minecraft.world.item.context.BlockPlaceContext;
69
import net.minecraft.world.level.BlockGetter;
10+
import net.minecraft.world.level.Level;
11+
import net.minecraft.world.level.LevelAccessor;
712
import net.minecraft.world.level.LevelReader;
13+
import net.minecraft.world.level.block.AbstractCandleBlock;
814
import net.minecraft.world.level.block.Block;
915
import net.minecraft.world.level.block.LanternBlock;
1016
import net.minecraft.world.level.block.state.BlockState;
1117
import net.minecraft.world.level.block.state.StateDefinition;
18+
import net.minecraft.world.level.material.FluidState;
19+
import net.minecraft.world.level.material.Fluids;
20+
import net.minecraft.world.phys.BlockHitResult;
1221
import net.minecraft.world.phys.shapes.CollisionContext;
1322
import net.minecraft.world.phys.shapes.Shapes;
1423
import net.minecraft.world.phys.shapes.VoxelShape;
1524
import org.jetbrains.annotations.Nullable;
1625

1726
import java.util.Optional;
1827

28+
import static net.minecraft.world.level.block.CandleBlock.LIT;
1929
import static net.minecraft.world.level.block.CandleBlock.MAX_CANDLES;
2030
import static net.minecraft.world.level.block.CandleBlock.MIN_CANDLES;
2131
import static net.minecraft.world.level.block.state.properties.BlockStateProperties.CANDLES;
@@ -54,14 +64,15 @@ public VigilCandleBlock(Properties properties) {
5464
super(properties);
5565
registerDefaultState(defaultBlockState()
5666
.setValue(HANGING, false)
67+
.setValue(LIT, false)
5768
.setValue(WATERLOGGED, false)
5869
.setValue(CANDLES, MIN_CANDLES));
5970
}
6071

6172
@Override
6273
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
6374
super.createBlockStateDefinition(builder);
64-
builder.add(CANDLES);
75+
builder.add(CANDLES, LIT);
6576
}
6677

6778
public boolean canBeReplaced(BlockState state, BlockPlaceContext context) {
@@ -99,4 +110,29 @@ public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
99110
}
100111
}
101112

113+
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
114+
if (player.getAbilities().mayBuild && player.getItemInHand(hand).isEmpty() && state.getValue(LIT)) {
115+
AbstractCandleBlock.extinguish(player, state, level, pos);
116+
return InteractionResult.sidedSuccess(level.isClientSide);
117+
} else {
118+
return InteractionResult.PASS;
119+
}
120+
}
121+
122+
public boolean placeLiquid(LevelAccessor level, BlockPos pos, BlockState state, FluidState fluid) {
123+
if (!state.getValue(WATERLOGGED) && fluid.getType() == Fluids.WATER) {
124+
BlockState waterlogged = state.setValue(WATERLOGGED, true);
125+
if (state.getValue(LIT)) {
126+
AbstractCandleBlock.extinguish(null, waterlogged, level, pos);
127+
} else {
128+
level.setBlock(pos, waterlogged, 3);
129+
}
130+
131+
level.scheduleTick(pos, fluid.getType(), fluid.getType().getTickDelay(level));
132+
return true;
133+
} else {
134+
return false;
135+
}
136+
}
137+
102138
}

src/main/java/galena/oreganized/index/OBlocks.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import net.minecraft.world.item.Item;
2727
import net.minecraft.world.level.block.Block;
2828
import net.minecraft.world.level.block.Blocks;
29+
import net.minecraft.world.level.block.CandleBlock;
2930
import net.minecraft.world.level.block.DropExperienceBlock;
3031
import net.minecraft.world.level.block.IceBlock;
3132
import net.minecraft.world.level.block.LiquidBlock;
@@ -202,7 +203,7 @@ private static BlockBehaviour.Properties leadDecoProperties() {
202203
new MoltenLeadBlock(OFluids.MOLTEN_LEAD, BlockBehaviour.Properties.copy(Blocks.LAVA).mapColor(MapColor.COLOR_PURPLE)));
203204
public static final RegistryObject<Block> MOLTEN_LEAD_CAULDRON = HELPER.createBlock("molten_lead_cauldron", () -> new MoltenLeadCauldronBlock(BlockBehaviour.Properties.copy(Blocks.LAVA_CAULDRON).randomTicks()));
204205

205-
private static final Supplier<BlockBehaviour.Properties> VIGIL_CANDLE_PROPERTIES = () -> BlockBehaviour.Properties.of().lightLevel(state -> 10).sound(SoundType.METAL).pushReaction(PushReaction.DESTROY);
206+
private static final Supplier<BlockBehaviour.Properties> VIGIL_CANDLE_PROPERTIES = () -> BlockBehaviour.Properties.of().lightLevel(CandleBlock.LIGHT_EMISSION).sound(SoundType.METAL).pushReaction(PushReaction.DESTROY);
206207
public static final RegistryObject<Block> VIGIL_CANDLE = register("vigil_candle", () ->new VigilCandleBlock(VIGIL_CANDLE_PROPERTIES.get()));
207208
public static final Map<DyeColor, RegistryObject<Block>> COLORED_VIGIL_CANDLES = registerColored("vigil_candle", color -> new VigilCandleBlock(VIGIL_CANDLE_PROPERTIES.get().mapColor(color)));
208209

0 commit comments

Comments
 (0)