Merge pull request #2244 from kacpherek/fix/lightning-cleans-copper

🤖 Agent: Merged by hand by Ludovic's AI agent (orchestrator) after the contribution gate. rdbtCVS's change request is addressed at this head; a re-review was asked, with no new objection since. Proven in wave 5's union run (cg21 union 65b0cb252 (main c1ebf5d1b + 72 kacpherek PRs) playhorizon 94/95, use_item_on fixed (#2126 523280e78).
This commit is contained in:
Ludovic Marie
2026-10-27 12:18:16 +01:00
committed by GitHub
2 changed files with 100 additions and 0 deletions
@@ -278,6 +278,13 @@ impl Game<'_> {
}
self.strike_rod(b.at);
}
// LightningBolt.tick runs clearCopperOnLightningStrike for
// every server bolt, a skeleton trap's visual one included;
// a client's copy of a server bolt (spawn_remote_bolt) only
// flashes.
if self.remote.is_none() {
self.bolt_clear_copper(b.at);
}
}
b.life -= 1;
if b.life < 0 {
@@ -334,6 +341,16 @@ impl Game<'_> {
self.level_event_at(3002, p, axis);
}
}
/// `LightningBolt.clearCopperOnLightningStrike` at the block the bolt struck.
fn bolt_clear_copper(&mut self, at: [f64; 3]) {
let p = BlockPos::new(
at[0].floor() as i32,
(at[1] - 1.0e-6).floor() as i32,
at[2].floor() as i32,
);
self.with_level(|b, level, ticks| b.lightning_clear_copper(level, ticks, p));
let _ = self.process_level_events();
}
/// `thunderHit` for entities within 3 blocks (up to 9 above).
fn thunder_hit(&mut self, b: &mut Bolt) {
let at = b.at;
+83
View File
@@ -1478,6 +1478,80 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
let block = b.table.block_by_name(&format!("minecraft:{next}"))?;
Some(b.table.with_properties_of(block, state))
}
/// `WeatheringCopper.getPrevious` (and `getFirst` by repeating it) by
/// registry naming: the block one oxidation step back.
fn copper_previous_name(path: &str) -> Option<String> {
if let Some(rest) = path.strip_prefix("oxidized_") {
Some(format!("weathered_{rest}"))
} else if let Some(rest) = path.strip_prefix("weathered_") {
Some(format!("exposed_{rest}"))
} else {
path.strip_prefix("exposed_").map(|rest| {
if rest == "copper" {
"copper_block".to_owned()
} else {
rest.to_owned()
}
})
}
}
fn copper_stepped(&self, state: BlockStateId, all_the_way: bool) -> Option<BlockStateId> {
let b = self.b;
let name = &*b.table.info(b.block(state)).name;
let mut path = Self::copper_previous_name(name.strip_prefix("minecraft:")?)?;
while all_the_way && let Some(earlier) = Self::copper_previous_name(&path) {
path = earlier;
}
let block = b.table.block_by_name(&format!("minecraft:{path}"))?;
Some(b.table.with_properties_of(block, state))
}
/// `LightningBolt.clearCopperOnLightningStrike`: the struck copper goes
/// back to unoxidized, then 3 to 5 random walks of up to 8 steps each
/// scrape one step of oxidation off the weathering copper they land on.
/// A waxed block is left as it is but still starts the walks.
pub(crate) fn lightning_clear_copper(&mut self, struck: BlockPos) {
let b = self.b;
let state = self.state(struck);
let weathering = b
.data(state)
.implements(super::classes::Interface::WeatheringCopper);
let waxed = b.table.name(state).starts_with("minecraft:waxed_");
if !(weathering || waxed) {
return;
}
if weathering && let Some(first) = self.copper_stepped(state, true) {
self.set_block_and_update(struck, first);
}
for _ in 0..self.rand_int(3) + 3 {
let mut at = struck;
for _ in 0..self.rand_int(8) + 1 {
// randomStepCleaningCopper: up to 10 random blocks in the
// 3x3x3 cube around the walk's position.
let mut next = None;
for _ in 0..10 {
let x = at.x - 1 + self.rand_int(3);
let y = at.y - 1 + self.rand_int(3);
let z = at.z - 1 + self.rand_int(3);
let candidate = BlockPos::new(x, y, z);
let state = self.state(candidate);
if b.data(state)
.implements(super::classes::Interface::WeatheringCopper)
{
if let Some(previous) = self.copper_stepped(state, false) {
self.set_block_and_update(candidate, previous);
}
self.level_event(3002, candidate, -1);
next = Some(candidate);
break;
}
}
match next {
Some(p) => at = p,
None => break,
}
}
}
}
}
/// `Biome.Precipitation` at a position.
@@ -1661,6 +1735,15 @@ impl Behaviours {
) {
self.sim(level, ticks).random_tick_at(pos);
}
/// `LightningBolt.clearCopperOnLightningStrike` for the block at `struck`.
pub fn lightning_clear_copper<L: LevelAccess + ?Sized>(
&self,
level: &mut L,
ticks: &mut Ticks,
struck: BlockPos,
) {
self.sim(level, ticks).lightning_clear_copper(struck);
}
/// Run one scheduled block tick at `pos` immediately (no queue check).
pub fn scheduled_block_tick<L: LevelAccess + ?Sized>(
&self,