Light redstone ore when mining begins
This commit is contained in:
@@ -1777,6 +1777,12 @@ impl Game<'_> {
|
||||
});
|
||||
self.process_level_events()
|
||||
}
|
||||
fn attack_block(&mut self, pos: [i32; 3]) -> Result<()> {
|
||||
self.with_level(|b, level, ticks| {
|
||||
b.attack_block(level, ticks, BlockPos::new(pos[0], pos[1], pos[2]));
|
||||
});
|
||||
self.process_level_events()
|
||||
}
|
||||
/// Track which chunks are ticking (Ticks needs chunk load/unload).
|
||||
fn sync_tick_chunks(&mut self) {
|
||||
if !self.tick_chunks.synchronize(&self.world.chunks) {
|
||||
@@ -2885,6 +2891,7 @@ impl Game<'_> {
|
||||
return Ok(());
|
||||
}
|
||||
if self.mining.as_ref().is_none_or(|m| m.pos != hit.pos) {
|
||||
self.attack_block(hit.pos)?;
|
||||
self.mining = Some(Mining {
|
||||
pos: hit.pos,
|
||||
progress: 0.0,
|
||||
|
||||
@@ -409,7 +409,10 @@ impl HandWorld for GameHands<'_, '_> {
|
||||
fn within_border(&mut self, _: [i32; 3]) -> bool {
|
||||
true
|
||||
}
|
||||
fn attack_block(&mut self, _: [i32; 3]) {}
|
||||
fn attack_block(&mut self, pos: [i32; 3]) {
|
||||
let result = self.game.attack_block(pos);
|
||||
self.keep(result);
|
||||
}
|
||||
fn destroy_progress(&mut self, pos: [i32; 3]) -> f32 {
|
||||
self.game.destroy_progress(pos)
|
||||
}
|
||||
|
||||
@@ -513,6 +513,22 @@ impl Behaviours {
|
||||
sim.game_event_state(pos, "minecraft:block_change", next);
|
||||
}
|
||||
|
||||
/// The state change of `RedStoneOreBlock.attack` when mining begins.
|
||||
pub fn attack_block<L: LevelAccess + ?Sized>(
|
||||
&self,
|
||||
level: &mut L,
|
||||
ticks: &mut Ticks,
|
||||
pos: BlockPos,
|
||||
) {
|
||||
let mut sim = self.sim(level, ticks);
|
||||
let state = sim.state(pos);
|
||||
if self.data(state).chain.contains(&Class::RedStoneOre)
|
||||
&& !self.table.bool(state, self.props.lit)
|
||||
{
|
||||
sim.set_block_and_update(pos, self.table.set_bool(state, self.props.lit, true));
|
||||
}
|
||||
}
|
||||
|
||||
/// `BlockState.useWithoutItem` for a right-click on `pos` (hit face and
|
||||
/// absolute hit location as in `BlockHitResult`).
|
||||
pub fn use_without_item<L: LevelAccess + ?Sized>(
|
||||
|
||||
@@ -634,6 +634,27 @@ impl World<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mining_lights_redstone_ore_until_its_random_tick() {
|
||||
let mut w = world!();
|
||||
let pos = BlockPos::new(0, 1, 0);
|
||||
for ore in ["redstone_ore", "deepslate_redstone_ore"] {
|
||||
let unlit = w.id(ore, &[("lit", "false")]);
|
||||
let lit = w.id(ore, &[("lit", "true")]);
|
||||
w.put(pos, unlit);
|
||||
w.b().attack_block(&mut w.level, &mut w.ticks, pos);
|
||||
assert_eq!(w.get(pos), lit);
|
||||
w.b().attack_block(&mut w.level, &mut w.ticks, pos);
|
||||
assert_eq!(w.get(pos), lit);
|
||||
w.b().random_tick(&mut w.level, &mut w.ticks, pos);
|
||||
assert_eq!(w.get(pos), unlit);
|
||||
}
|
||||
let stone = w.id("stone", &[]);
|
||||
w.put(pos, stone);
|
||||
w.b().attack_block(&mut w.level, &mut w.ticks, pos);
|
||||
assert_eq!(w.get(pos), stone);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn placement_orients_blocks() {
|
||||
let mut w = world!();
|
||||
|
||||
Reference in New Issue
Block a user