Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fd3bb11
Add hardcoded rockwool -> wool conversion
iceiix May 14, 2019
e786691
Add modid macro token, skipped from vanilla, and Rockwool with modid
iceiix May 15, 2019
9dd51dd
Add get_modid() accessor for modid macro token
iceiix May 15, 2019
12034c3
Change to skip modid in vanilla block iter, instead of offset/data ac…
iceiix May 15, 2019
b8881b9
Return the new Rockwool block for modded id instead of vanilla Wool
iceiix May 15, 2019
6d838ef
Register modded blocks by modid->[data], and lookup correct rockwool …
iceiix May 15, 2019
1f38e35
Lookup modded after vanilla
iceiix May 15, 2019
8435ac7
Save block IDs from ModIdData/RegistryData to self.modded_block_ids
iceiix May 15, 2019
cd16840
Attempt to add by_vanilla_id protocol-specific accessor in World
iceiix May 15, 2019
588a74a
Revert "Attempt to add by_vanilla_id protocol-specific accessor in Wo…
iceiix May 15, 2019
19230b1
Pass and lookup modded_block_ids in by_vanilla_id
iceiix May 15, 2019
e8636ba
Fix crashing on unsupported but known modded blocks
iceiix May 15, 2019
f6d4d3a
Less logging
iceiix May 15, 2019
573bcee
Register modded blocks in World instance as well
iceiix May 15, 2019
b1f976b
Fix rockwool block modid name, has a \u{2} prefix for some reason
iceiix May 15, 2019
c2256b0
Remove modded block ID logging since they are always registered
iceiix May 15, 2019
27dd400
Switch to using fixed-size 16-element array for modded block data map…
iceiix May 15, 2019
5d85080
Remove modded block logging as it is too noisy, uncomment and recompi…
iceiix May 15, 2019
dbfd188
Remove obsolete comment
iceiix May 15, 2019
aa7efab
Broken attempt at namespaced id mappings (length is wrong)
iceiix May 15, 2019
d2c6de0
Add namespaced mod ids, working, \u{1}=block \u{2}=item
iceiix May 15, 2019
b8fa00f
Remove duplicate modded_block_ids in Server, use in World
iceiix May 15, 2019
b68be79
Another outdated comment
iceiix May 15, 2019
b4be0bc
Add ThermalFoundation's Rockwool (1.12.2)
iceiix May 15, 2019
73a87df
Merge branch 'master' into rockwool
iceiix May 15, 2019
686bca7
Merge branch 'master' into rockwool
iceiix May 15, 2019
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
102 changes: 99 additions & 3 deletions blocks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::shared::{Axis, Direction, Position};
use collision::Aabb3;
use cgmath::Point3;
use lazy_static::lazy_static;
use std::collections::HashMap;

pub mod material;
pub use self::material::Material;
Expand Down Expand Up @@ -44,12 +45,14 @@ macro_rules! create_ids {
struct VanillaIDMap {
flat: Vec<Option<Block>>,
hier: Vec<Option<Block>>,
modded: HashMap<String, [Option<Block>; 16]>,
}

macro_rules! define_blocks {
(
$(
$name:ident {
$(modid $modid:expr,)*
props {
$(
$fname:ident : $ftype:ty = [$($val:expr),+],
Expand Down Expand Up @@ -133,11 +136,43 @@ macro_rules! define_blocks {
}
}

pub fn by_vanilla_id(id: usize, protocol_version: i32) -> Block {
#[allow(unused_variables, unreachable_code)]
pub fn get_modid(&self) -> Option<&str> {
match *self {
$(
Block::$name {
$($fname,)*
} => {
$(
return Some($modid);
)*
None
}
)+
}
}

pub fn by_vanilla_id(id: usize, protocol_version: i32, modded_block_ids: &HashMap<usize, String>) -> Block {
if protocol_version >= 404 {
VANILLA_ID_MAP.flat.get(id).and_then(|v| *v).unwrap_or(Block::Missing{})
// TODO: support modded 1.13.2+ blocks after https://github.com/iceiix/stevenarella/pull/145
} else {
VANILLA_ID_MAP.hier.get(id).and_then(|v| *v).unwrap_or(Block::Missing{})
if let Some(block) = VANILLA_ID_MAP.hier.get(id).and_then(|v| *v) {
block
} else {
let data = id & 0xf;

if let Some(name) = modded_block_ids.get(&(id >> 4)) {
if let Some(blocks_by_data) = VANILLA_ID_MAP.modded.get(name) {
blocks_by_data[data].unwrap_or(Block::Missing{})
} else {
//println!("Modded block not supported yet: {}:{} -> {}", id >> 4, data, name);
Block::Missing{}
}
} else {
Block::Missing{}
}
}
}
}

Expand Down Expand Up @@ -257,6 +292,7 @@ macro_rules! define_blocks {
static ref VANILLA_ID_MAP: VanillaIDMap = {
let mut blocks_flat = vec![];
let mut blocks_hier = vec![];
let mut blocks_modded: HashMap<String, [Option<Block>; 16]> = HashMap::new();
let mut flat_id = 0;
let mut last_internal_id = 0;
let mut hier_block_id = 0;
Expand Down Expand Up @@ -353,6 +389,16 @@ macro_rules! define_blocks {
for block in iter {
let internal_id = block.get_internal_id();
let hier_data: Option<usize> = block.get_hierarchical_data();
if let Some(modid) = block.get_modid() {
let hier_data = hier_data.unwrap();
if !blocks_modded.contains_key(modid) {
blocks_modded.insert(modid.to_string(), [None; 16]);
}
let block_from_data = blocks_modded.get_mut(modid).unwrap();
block_from_data[hier_data] = Some(block);
continue
}

let vanilla_id =
if let Some(hier_data) = hier_data {
if internal_id != last_internal_id {
Expand Down Expand Up @@ -422,7 +468,7 @@ macro_rules! define_blocks {
}
})+

VanillaIDMap { flat: blocks_flat, hier: blocks_hier }
VanillaIDMap { flat: blocks_flat, hier: blocks_hier, modded: blocks_modded }
};
}
);
Expand Down Expand Up @@ -1014,6 +1060,56 @@ define_blocks! {
data Some(color.data()),
model { ("minecraft", format!("{}_wool", color.as_string()) ) },
}
ThermalExpansionRockwool {
modid "ThermalExpansion:Rockwool",
props {
color: ColoredVariant = [
ColoredVariant::White,
ColoredVariant::Orange,
ColoredVariant::Magenta,
ColoredVariant::LightBlue,
ColoredVariant::Yellow,
ColoredVariant::Lime,
ColoredVariant::Pink,
ColoredVariant::Gray,
ColoredVariant::Silver,
ColoredVariant::Cyan,
ColoredVariant::Purple,
ColoredVariant::Blue,
ColoredVariant::Brown,
ColoredVariant::Green,
ColoredVariant::Red,
ColoredVariant::Black
],
},
data Some(color.data()),
model { ("minecraft", format!("{}_wool", color.as_string()) ) },
}
ThermalFoundationRockwool {
modid "thermalfoundation:rockwool",
props {
color: ColoredVariant = [
ColoredVariant::White,
ColoredVariant::Orange,
ColoredVariant::Magenta,
ColoredVariant::LightBlue,
ColoredVariant::Yellow,
ColoredVariant::Lime,
ColoredVariant::Pink,
ColoredVariant::Gray,
ColoredVariant::Silver,
ColoredVariant::Cyan,
ColoredVariant::Purple,
ColoredVariant::Blue,
ColoredVariant::Brown,
ColoredVariant::Green,
ColoredVariant::Red,
ColoredVariant::Black
],
},
data Some(color.data()),
model { ("minecraft", format!("{}_wool", color.as_string()) ) },
}
PistonExtension {
props {
facing: Direction = [
Expand Down
3 changes: 3 additions & 0 deletions src/protocol/forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ impl Serializable for ModIdMapping {
}
}

pub static BLOCK_NAMESPACE: &'static str = "\u{1}";
pub static ITEM_NAMESPACE: &'static str = "\u{2}";

#[derive(Debug)]
pub enum FmlHs {
ServerHello {
Expand Down
23 changes: 16 additions & 7 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,17 +711,26 @@ impl Server {

self.write_fmlhs_plugin_message(&HandshakeAck { phase: WaitingServerData });
},
ModIdData { mappings: _, block_substitutions: _, item_substitutions: _ } => {
ModIdData { mappings, block_substitutions: _, item_substitutions: _ } => {
println!("Received FML|HS ModIdData");
for m in mappings.data {
let (namespace, name) = m.name.split_at(1);
if namespace == protocol::forge::BLOCK_NAMESPACE {
self.world.modded_block_ids.insert(m.id.0 as usize, name.to_string());
}
}
self.write_fmlhs_plugin_message(&HandshakeAck { phase: WaitingServerComplete });
// TODO: dynamically register mod blocks
},
RegistryData { has_more, name, ids: _, substitutions: _, dummies: _ } => {
RegistryData { has_more, name, ids, substitutions: _, dummies: _ } => {
println!("Received FML|HS RegistryData for {}", name);
if name == "minecraft:blocks" {
for m in ids.data {
self.world.modded_block_ids.insert(m.id.0 as usize, m.name);
}
}
if !has_more {
self.write_fmlhs_plugin_message(&HandshakeAck { phase: WaitingServerComplete });
}
// TODO: dynamically register mod blocks
},
HandshakeAck { phase } => {
match phase {
Expand Down Expand Up @@ -1285,7 +1294,7 @@ impl Server {
}

fn on_block_change(&mut self, location: Position, id: i32) {
self.world.set_block(location, block::Block::by_vanilla_id(id as usize, self.protocol_version))
self.world.set_block(location, block::Block::by_vanilla_id(id as usize, self.protocol_version, &self.world.modded_block_ids))
}

fn on_block_change_varint(&mut self, block_change: packet::play::clientbound::BlockChange_VarInt) {
Expand All @@ -1309,7 +1318,7 @@ impl Server {
record.y as i32,
oz + (record.xz & 0xF) as i32
),
block::Block::by_vanilla_id(record.block_id.0 as usize, self.protocol_version)
block::Block::by_vanilla_id(record.block_id.0 as usize, self.protocol_version, &self.world.modded_block_ids)
);
}
}
Expand All @@ -1332,7 +1341,7 @@ impl Server {

self.world.set_block(
Position::new(x, y, z),
block::Block::by_vanilla_id(id as usize, self.protocol_version)
block::Block::by_vanilla_id(id as usize, self.protocol_version, &self.world.modded_block_ids)
);
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct World {
block_entity_actions: VecDeque<BlockEntityAction>,

protocol_version: i32,
pub modded_block_ids: HashMap<usize, String>,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -619,7 +620,7 @@ impl World {

for bi in 0 .. 4096 {
let id = data.read_u16::<byteorder::LittleEndian>()?;
section.blocks.set(bi, block::Block::by_vanilla_id(id as usize, self.protocol_version));
section.blocks.set(bi, block::Block::by_vanilla_id(id as usize, self.protocol_version, &self.modded_block_ids));

// Spawn block entities
let b = section.blocks.get(bi);
Expand Down Expand Up @@ -805,7 +806,7 @@ impl World {

for bi in 0 .. 4096 {
let id = ((block_add[i].get(bi) as u16) << 12) | ((block_types[i][bi] as u16) << 4) | (block_meta[i].get(bi) as u16);
section.blocks.set(bi, block::Block::by_vanilla_id(id as usize, self.protocol_version));
section.blocks.set(bi, block::Block::by_vanilla_id(id as usize, self.protocol_version, &self.modded_block_ids));

// Spawn block entities
let b = section.blocks.get(bi);
Expand Down Expand Up @@ -882,7 +883,7 @@ impl World {
let count = VarInt::read_from(&mut data)?.0;
for i in 0 .. count {
let id = VarInt::read_from(&mut data)?.0;
let bl = block::Block::by_vanilla_id(id as usize, self.protocol_version);
let bl = block::Block::by_vanilla_id(id as usize, self.protocol_version, &self.modded_block_ids);
mappings.insert(i as usize, bl);
}
}
Expand All @@ -892,7 +893,7 @@ impl World {

for bi in 0 .. 4096 {
let id = m.get(bi);
section.blocks.set(bi, mappings.get(&id).cloned().unwrap_or(block::Block::by_vanilla_id(id, self.protocol_version)));
section.blocks.set(bi, mappings.get(&id).cloned().unwrap_or(block::Block::by_vanilla_id(id, self.protocol_version, &self.modded_block_ids)));
// Spawn block entities
let b = section.blocks.get(bi);
if block_entity::BlockEntityType::get_block_entity(b).is_some() {
Expand Down