Skip to content

Commit

Permalink
add lit state to vigil candles
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Oct 17, 2024
1 parent 4219bff commit b64d606
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@

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;
import org.jetbrains.annotations.Nullable;

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;
Expand Down Expand Up @@ -54,14 +64,15 @@ public VigilCandleBlock(Properties properties) {
super(properties);
registerDefaultState(defaultBlockState()
.setValue(HANGING, false)
.setValue(LIT, false)
.setValue(WATERLOGGED, false)
.setValue(CANDLES, MIN_CANDLES));
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(CANDLES);
builder.add(CANDLES, LIT);
}

public boolean canBeReplaced(BlockState state, BlockPlaceContext context) {
Expand Down Expand Up @@ -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;
}
}

}
3 changes: 2 additions & 1 deletion src/main/java/galena/oreganized/index/OBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Block> MOLTEN_LEAD_CAULDRON = HELPER.createBlock("molten_lead_cauldron", () -> new MoltenLeadCauldronBlock(BlockBehaviour.Properties.copy(Blocks.LAVA_CAULDRON).randomTicks()));

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

Expand Down

0 comments on commit b64d606

Please sign in to comment.