-
Notifications
You must be signed in to change notification settings - Fork 59
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
blocks: add version-dependent block states, fixes #467 #469
Conversation
Run with: DEBUG_BLOCKS=1 cargo run --release and look for block state output. A quick script to clean up the output:
spot checked some of the values vs #467 (comment), the last one StructureBlock is 8595-8598, this is correct for 1.13.2 but not any other versions:
we don't support protocol 1.13 (protocol support: #18), but do support 1.13.2 (added in iceiix/steven#67 #67), 1.14, 1.14.1, 1.14.2, 1.14.3, 1.14.4; 1.15.1, 1.15.2; 1.16.1, and 1.16.2(/3/4). Presumably minecraft-data's 1.14.4 applies to all of 1.14.x etc., or were new block states actually added in the .4 update? No, this is merely how they are stored, https://github.com/PrismarineJS/minecraft-data/blob/master/data/dataPaths.json has the paths,
so the initial protocol versions we support, for each of the new sets of blocks would be:
Are block states only additive? If so, considering adding a min_protocol_version token to the |
Script to dump the block state ranges from minecraft-data, for comparison to the above parsed DEBUG_BLOCKS output: #!/usr/local/bin/python3
# List block state ranges
import json
versions=('1.13','1.13.2','1.14.4','1.15.2','1.16.1','1.16.2')
block2versions={}
minStates={}
for v in versions:
blocks=json.load(open('data/pc/'+v+'/blocks.json'))
for block in blocks:
#block['id']
#print(v,block['displayName'], block['minStateId'], block['maxStateId'])
name=block['displayName']
if name not in block2versions: block2versions[name] = {}
block2versions[name][v] = range(block['minStateId'], block['maxStateId'])
if v not in minStates: minStates[v]={}
minStates[v][block['minStateId']] = (name, block['maxStateId'])
v = '1.13.2'
for minState in sorted(minStates[v].keys()):
name, maxState = minStates[v][minState]
print("%d-%d %s"%(minState,maxState,name)) Not quite directly comparable because of the 1) identifier naming vs display naming, and 2) tighter block state packing within steven_blocks: but it looks right for 1.13.2, at least the high-level groupings. 1.14.4 (which really means 1.14+) there is a huge shift due to Note Block expanding from 248-747 (500 states) to 248-1047 (800 states): diffing the state count could be a reasonable way to see changes, this gets close (shows the note block expansion, new flower blocks, renamed redstone, but something odd starts going on with signs):
bigger diff: https://gist.github.com/iceiix/158686a6b1754873223c141908505932 Looking further down the list, it does appear some blocks are moved (?):
also dead coral wall fans. Near the end (good), 56 new blocks are added |
Refactored by_vanilla_id to be a method of VanillaIDMap, held by World, initialized with the protocol version (this is already cleaner than before where the protocol_version had to be passed to each call of by_vanilla_id). Started trying to add protocol_version-specific block states, but this fails: offset instrument.offset(protocol_version)
.map(|offset| offset * (25 * 2) + ((note as usize) << 1) + if powered { 0 } else { 1 }),
Why isn't it in scope? $offsetfunc is matched as an expression in: $(offset $offsetfunc:expr,)? then expanded here, where I pass protocol_version as a method parameter, but $offsetfunc can't see it: pub fn get_flat_offset(&self, protocol_version: i32) -> Option<usize> {
match *self {
$(
Block::$name {
$($fname,)?
} => {
$(
let offset: Option<usize> = ($offsetfunc).map(|v| v);
return offset;
)?
$(
let data: Option<usize> = ($datafunc).map(|v| v);
return data;
)?
Some(0)
}
)+
}
} reduced: macro_rules! define_blocks {
(
$(
$name:ident {
props {
$(
$fname:ident : $ftype:ty = [$($val:expr),+],
)*
},
$(offset $offsetfunc:expr,)?
}
)+
) => (
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Block {
$(
$name {
$(
$fname : $ftype,
)?
},
)+
}
impl Block {
#[allow(unused_variables, unreachable_code)]
pub fn get_flat_offset(&self, protocol_version: i32) -> Option<usize> {
match *self {
$(
Block::$name {
$($fname,)?
} => {
$(
println!("offsetfunc = {:?}", $offsetfunc);
let offset: Option<usize> = ($offsetfunc).map(|v| v);
return offset;
)?
Some(0)
}
)+
}
}
}
)
}
define_blocks! {
NoteBlock {
props {
note: usize = [0, 1, 2, 3],
},
offset Some(note),
//offset Some(protocol_version),
}
}
fn main() {
let b = Block::NoteBlock { note: 2 };
println!("{:?}", b);
println!("{:?}", b.get_flat_offset(404));
} with
and this macro output does compile if copied into a new file, but not from the macro. Maybe from https://veykril.github.io/tlborm/macros/minutiae/hygiene.html
macro_rules! using_a {
($a:ident, $e:expr) => {
{
let $a = 42;
$e
}
}
} which explains why |
Added many block variants to 1.14+, fixing offsets, 1.14.4 is looking not too bad: but not all blocks are added. Added up to the stone slab variants, left off here: https://gist.github.com/iceiix/158686a6b1754873223c141908505932#file-gistfile1-txt-L123 before the coral wall fan changes:
not to mention the post-1.14 block changes:
but this pull request is still better than before, will merge it for now |
Adds _some _new blocks and block states, building on the version- dependent block support added in #469. Notably, fixes grass on 1.16.4. 1.16.1+ (protocol_version >= 735) * Add NetherGoldOre * Add SoulFire * Add SoulSoil, Basalt * Add PolishedBasalt, SoulTorch, SoulWallTorch * Add Chain * 1.16.2+ (protocol_version >= 751) * Add Chain axis states
Adds _some _new blocks and block states, building on the version- dependent block support added in #469. Notably, fixes grass on 1.16.4. 1.16.1+ (protocol_version >= 735) * Add NetherGoldOre * Add SoulFire * Add SoulSoil, Basalt * Add PolishedBasalt, SoulTorch, SoulWallTorch * Add Chain * 1.16.2+ (protocol_version >= 751) * Add Chain axis states
Adds _some _new blocks and block states, building on the version- dependent block support added in #469. Notably, fixes grass on 1.16.4. 1.16.1+ (protocol_version >= 735) * Add NetherGoldOre * Add SoulFire * Add SoulSoil, Basalt * Add PolishedBasalt, SoulTorch, SoulWallTorch * Add Chain 1.16.2+ (protocol_version >= 751) * Add Chain axis states
debugging #467