Add replaceable boolean to block states (#116)

This commit is contained in:
Ryan Johnson 2022-10-16 03:50:57 -07:00 committed by GitHub
parent 59ca1ab573
commit ad153159dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21478 additions and 8 deletions

View file

@ -46,6 +46,7 @@ struct State {
id: u16,
luminance: u8,
opaque: bool,
replaceable: bool,
collision_shapes: Vec<u16>,
}
@ -113,6 +114,18 @@ pub fn build() -> anyhow::Result<TokenStream> {
})
.collect::<TokenStream>();
let state_to_replaceable_arms = blocks
.iter()
.flat_map(|b| {
b.states.iter().filter(|s| s.replaceable).map(|s| {
let id = s.id;
quote! {
#id => true,
}
})
})
.collect::<TokenStream>();
let shapes = shapes.iter().map(|s| {
let min_x = s.min_x;
let min_y = s.min_y;
@ -517,6 +530,13 @@ pub fn build() -> anyhow::Result<TokenStream> {
}
}
pub const fn is_replaceable(self) -> bool {
match self.0 {
#state_to_replaceable_arms
_ => false,
}
}
const SHAPES: [[f64; 6]; #shape_count] = [
#(#shapes,)*
];

File diff suppressed because it is too large Load diff

View file

@ -3,6 +3,7 @@ package rs.valence.extractor.extractors;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.EmptyBlockView;
@ -60,6 +61,7 @@ public class Blocks implements Main.Extractor {
stateJson.addProperty("id", id);
stateJson.addProperty("luminance", state.getLuminance());
stateJson.addProperty("opaque", state.isOpaque());
stateJson.addProperty("replaceable", state.getMaterial().isReplaceable());
if (block.getDefaultState().equals(state)) {
blockJson.addProperty("default_state_id", id);

View file

@ -227,7 +227,7 @@ pub struct Client<C: Config> {
new_game_mode: GameMode,
old_game_mode: GameMode,
settings: Option<Settings>,
dug_block_sequence: i32,
block_change_sequence: i32,
/// Should be sent after login packet.
msgs_to_send: Vec<Text>,
bar_to_send: Option<Text>,
@ -301,7 +301,7 @@ impl<C: Config> Client<C> {
new_game_mode: GameMode::Survival,
old_game_mode: GameMode::Survival,
settings: None,
dug_block_sequence: 0,
block_change_sequence: 0,
msgs_to_send: Vec::new(),
bar_to_send: None,
resource_pack_to_send: None,
@ -1016,7 +1016,7 @@ impl<C: Config> Client<C> {
C2sPlayPacket::PlayerAbilitiesC2s(_) => {}
C2sPlayPacket::PlayerAction(p) => {
if p.sequence.0 != 0 {
self.dug_block_sequence = p.sequence.0;
self.block_change_sequence = p.sequence.0;
}
self.events.push_back(match p.status {
@ -1100,7 +1100,7 @@ impl<C: Config> Client<C> {
face: p.face,
cursor_pos: p.cursor_pos,
head_inside_block: p.head_inside_block,
sequence: p.sequence,
sequence: dbg!(p.sequence),
}),
C2sPlayPacket::UseItem(_) => {}
}
@ -1361,15 +1361,15 @@ impl<C: Config> Client<C> {
}
}
// Acknowledge broken blocks.
if self.dug_block_sequence != 0 {
// Acknowledge broken/placed blocks.
if self.block_change_sequence != 0 {
send_packet(
&mut self.send,
AcknowledgeBlockChange {
sequence: VarInt(self.dug_block_sequence),
sequence: VarInt(self.block_change_sequence),
},
);
self.dug_block_sequence = 0;
self.block_change_sequence = 0;
}
// Teleport the player.