Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[21.1+] Generalise lightable blocks #1186

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
dispensiblecontaineritem.checkExtraContent(null, level, p_338251_, blockpos);
return this.consumeWithRemainder(p_338850_, p_338251_, new ItemStack(Items.BUCKET));
} else {
@@ -282,9 +_,10 @@
} else if (CampfireBlock.canLight(blockstate) || CandleBlock.canLight(blockstate) || CandleCakeBlock.canLight(blockstate)) {
@@ -279,12 +_,13 @@
if (BaseFireBlock.canBePlacedAt(serverlevel, blockpos, direction)) {
serverlevel.setBlockAndUpdate(blockpos, BaseFireBlock.getState(serverlevel, blockpos));
serverlevel.gameEvent(null, GameEvent.BLOCK_PLACE, blockpos);
- } else if (CampfireBlock.canLight(blockstate) || CandleBlock.canLight(blockstate) || CandleCakeBlock.canLight(blockstate)) {
+ } else if (blockstate.getBlock() instanceof net.neoforged.neoforge.common.SpecialLightableBlock && ((net.neoforged.neoforge.common.SpecialLightableBlock) blockstate.getBlock()).canLight(blockstate)) {
serverlevel.setBlockAndUpdate(blockpos, blockstate.setValue(BlockStateProperties.LIT, Boolean.valueOf(true)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still sets the LIT property here

serverlevel.gameEvent(null, GameEvent.BLOCK_CHANGE, blockpos);
- } else if (blockstate.getBlock() instanceof TntBlock) {
Expand Down
11 changes: 11 additions & 0 deletions patches/net/minecraft/world/item/FireChargeItem.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/net/minecraft/world/item/FireChargeItem.java
+++ b/net/minecraft/world/item/FireChargeItem.java
@@ -33,7 +_,7 @@
BlockPos blockpos = p_41204_.getClickedPos();
BlockState blockstate = level.getBlockState(blockpos);
boolean flag = false;
- if (!CampfireBlock.canLight(blockstate) && !CandleBlock.canLight(blockstate) && !CandleCakeBlock.canLight(blockstate)) {
+ if (blockstate.getBlock() instanceof net.neoforged.neoforge.common.SpecialLightableBlock && !((net.neoforged.neoforge.common.SpecialLightableBlock) blockstate.getBlock()).canLight(blockstate)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong logic, instead of catching unlightable blocks and lightable blocks that refuse, it only catches the latter. Should be !(instanceof) || !canLight()

I don't see the else, but I suspect it also sets LIT

blockpos = blockpos.relative(p_41204_.getClickedFace());
if (BaseFireBlock.canBePlacedAt(level, blockpos, p_41204_.getHorizontalDirection())) {
this.playSound(level, blockpos);
30 changes: 30 additions & 0 deletions patches/net/minecraft/world/item/FlintAndSteelItem.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--- a/net/minecraft/world/item/FlintAndSteelItem.java
+++ b/net/minecraft/world/item/FlintAndSteelItem.java
@@ -29,7 +_,7 @@
Level level = p_41297_.getLevel();
BlockPos blockpos = p_41297_.getClickedPos();
BlockState blockstate = level.getBlockState(blockpos);
- if (!CampfireBlock.canLight(blockstate) && !CandleBlock.canLight(blockstate) && !CandleCakeBlock.canLight(blockstate)) {
+ if (!(blockstate.getBlock() instanceof net.neoforged.neoforge.common.SpecialLightableBlock) || !((net.neoforged.neoforge.common.SpecialLightableBlock) blockstate.getBlock()).canLight(blockstate)) {
BlockPos blockpos1 = blockpos.relative(p_41297_.getClickedFace());
if (BaseFireBlock.canBePlacedAt(level, blockpos1, p_41297_.getHorizontalDirection())) {
level.playSound(player, blockpos1, SoundEvents.FLINTANDSTEEL_USE, SoundSource.BLOCKS, 1.0F, level.getRandom().nextFloat() * 0.4F + 0.8F);
@@ -46,9 +_,9 @@
} else {
return InteractionResult.FAIL;
}
- } else {
+ } else if (blockstate.getBlock() instanceof net.neoforged.neoforge.common.SpecialLightableBlock ilb) {
level.playSound(player, blockpos, SoundEvents.FLINTANDSTEEL_USE, SoundSource.BLOCKS, 1.0F, level.getRandom().nextFloat() * 0.4F + 0.8F);
- level.setBlock(blockpos, blockstate.setValue(BlockStateProperties.LIT, Boolean.valueOf(true)), 11);
+ ilb.setLit(level, blockstate, blockpos, true);
level.gameEvent(player, GameEvent.BLOCK_CHANGE, blockpos);
if (player != null) {
p_41297_.getItemInHand().hurtAndBreak(1, player, LivingEntity.getSlotForHand(p_41297_.getHand()));
@@ -56,5 +_,6 @@

return InteractionResult.sidedSuccess(level.isClientSide());
}
+ return InteractionResult.PASS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) NeoForged and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.neoforged.neoforge.common;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.CampfireBlock;
import net.minecraft.world.level.block.CandleBlock;
import net.minecraft.world.level.block.CandleCakeBlock;
import net.minecraft.world.level.block.state.BlockState;

public interface SpecialLightableBlock {
default boolean canLight(BlockState state) {
return CampfireBlock.canLight(state) || CandleBlock.canLight(state) || CandleCakeBlock.canLight(state);
}

void setLit(LevelAccessor level, BlockState state, BlockPos pos, boolean lit);
}
Loading