Skip to content

Commit 1605738

Browse files
Miro-AndrinTracreedambeeeeee
authored
Refactor such that libcraft contains all generated files (almost). (#461)
* Refactoring ongoing * Added libcraft-inventory * cha-cha-cha-Changes * Turn and face the stranger * Ch-ch-Changes * Don't want to be a richer one * Ch-ch-ch-ch-Changes * (Turn and face the stranger) * hHAHAHA * Changed stuff as a test * Changed stuff. * Something * Fixed a problem * Fixed most things. Some problems left. * Finnished up. * removed Filled from use. * Ongoing refactor. * Fixed so it compiles and runs fine. * Fix missing offhand area in inventory.json. * Clippy issues. * Appease the clippy gods. * cargo fmt * Added clippy ignore to inventory generator. * Just fixed the generator instead. No need to ignore clippy. * Fix Some(slot + 0) * Fixed `let slot = index - 0;` * Removed unnecessary borrows. * Added _ to unread struct field. * Derived default where it was possible. * Spelling error. * `cargo fmt` wants new lines at the end of files. * Fix merge issues. * Removed commented out code. * Format doc comment better. * Remove default derive on HotbarSlot. * Clarify why the `unreachable!()` is unreachable. * Add trailing newline. * Update feather/base/src/anvil/entity.rs Co-authored-by: Amber <amberkowalski03@gmail.com> * set_slot takes a reference instead. * remove clone from handle_click_window. * Made damage an i32 on ItemStackMeta * Changed code to use filter_map. Co-authored-by: Tracreed <davidalasow@gmail.com> Co-authored-by: Amber <amberkowalski03@gmail.com>
1 parent 7288a29 commit 1605738

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1451
-27798
lines changed

Cargo.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
"libcraft/macros",
99
"libcraft/particles",
1010
"libcraft/text",
11+
"libcraft/inventory",
1112

1213
# Quill
1314
"quill/sys-macros",
@@ -29,7 +30,6 @@ members = [
2930

3031
# Feather (common and server)
3132
"feather/utils",
32-
"feather/generated",
3333
"feather/blocks",
3434
"feather/blocks/generator",
3535
"feather/base",

feather/base/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ bitflags = "1"
1212
bitvec = "0.21"
1313
blocks = { path = "../blocks", package = "feather-blocks" }
1414
byteorder = "1"
15-
generated = { path = "../generated", package = "feather-generated" }
1615
hematite-nbt = { git = "https://github.com/PistonDevelopers/hematite_nbt" }
16+
1717
libcraft-blocks = { path = "../../libcraft/blocks" }
1818
libcraft-core = { path = "../../libcraft/core" }
1919
libcraft-items = { path = "../../libcraft/items" }
2020
libcraft-particles = { path = "../../libcraft/particles" }
21-
libcraft-text = { path = "../../libcraft/text" }
21+
libcraft-text = { path = "../../libcraft/text" }
22+
libcraft-inventory = { path = "../../libcraft/inventory" }
23+
2224
nom = "5"
2325
nom_locate = "2"
2426
num-derive = "0.3"

feather/base/src/anvil/entity.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use arrayvec::ArrayVec;
2-
use generated::{Item, ItemStack};
2+
use libcraft_items::{Item, ItemStack, ItemStackBuilder};
33
use serde::ser::Error;
44
use serde::{Deserialize, Serialize, Serializer};
55
use thiserror::Error;
@@ -219,8 +219,8 @@ where
219219
Some(nbt)
220220
};
221221
Self {
222-
count: stack.count as i8,
223-
item: stack.item.name().to_owned(),
222+
count: stack.count() as i8,
223+
item: stack.item().name().to_owned(),
224224
nbt,
225225
}
226226
}
@@ -235,12 +235,22 @@ pub struct ItemNbt {
235235
}
236236

237237
impl ItemNbt {
238-
/// Create an `ItemStack` of the specified item and amount, setting any nbt present.
238+
/// Create an `ItemStack` of the specified item and amount, setting any NBT present.
239+
///
240+
/// # Panics
241+
/// Panics if `count` is zero.
239242
pub fn item_stack(nbt: &Option<Self>, item: Item, count: u8) -> ItemStack {
240-
ItemStack {
241-
count: count as u32,
242-
item,
243-
damage: nbt.as_ref().map(|n| n.damage).flatten().map(|x| x as u32),
243+
match nbt {
244+
Some(ItemNbt {
245+
damage: Some(damage),
246+
}) => ItemStackBuilder::with_item(item)
247+
.count(count as u32)
248+
.damage(*damage)
249+
.into(),
250+
251+
Some(ItemNbt { damage: None }) | None => {
252+
ItemStackBuilder::with_item(item).count(count as u32).into()
253+
}
244254
}
245255
}
246256
}
@@ -252,7 +262,7 @@ where
252262
fn from(s: S) -> Self {
253263
let stack = s.borrow();
254264
Self {
255-
damage: stack.damage.map(|d| d as i32),
265+
damage: stack.damage_taken().map(|d| d as i32),
256266
}
257267
}
258268
}

feather/base/src/anvil/level.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Implements level.dat file loading.
22
3-
use generated::{Biome, Item};
3+
use libcraft_core::Biome;
4+
use libcraft_items::Item;
45
use serde::{Deserialize, Serialize};
56
use std::io::{Cursor, Read, Write};
67
use std::{collections::HashMap, fs::File};

feather/base/src/anvil/player.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use libcraft_items::{Item, ItemStack};
12
use std::{
23
collections::HashMap,
34
fs,
@@ -9,7 +10,6 @@ use nbt::Value;
910
use serde::{Deserialize, Serialize};
1011
use uuid::Uuid;
1112

12-
use generated::{Item, ItemStack};
1313
use quill_common::components::{
1414
CanBuild, CanCreativeFly, CreativeFlying, CreativeFlyingSpeed, Instabreak, Invulnerable,
1515
WalkSpeed,
@@ -99,9 +99,9 @@ impl InventorySlot {
9999
Some(nbt)
100100
};
101101
Self {
102-
count: stack.count as i8,
102+
count: stack.count() as i8,
103103
slot,
104-
item: stack.item.name().to_owned(),
104+
item: stack.item().name().to_owned(),
105105
nbt,
106106
}
107107
}
@@ -222,8 +222,8 @@ mod tests {
222222
};
223223

224224
let item_stack: ItemStack = slot.into();
225-
assert_eq!(item_stack.item, Item::Feather);
226-
assert_eq!(item_stack.count, 1);
225+
assert_eq!(item_stack.item(), Item::Feather);
226+
assert_eq!(item_stack.count(), 1);
227227
}
228228

229229
#[test]
@@ -236,9 +236,9 @@ mod tests {
236236
};
237237

238238
let item_stack: ItemStack = slot.into();
239-
assert_eq!(item_stack.item, Item::DiamondAxe);
240-
assert_eq!(item_stack.count, 1);
241-
assert_eq!(item_stack.damage, Some(42));
239+
assert_eq!(item_stack.item(), Item::DiamondAxe);
240+
assert_eq!(item_stack.count(), 1);
241+
assert_eq!(item_stack.damage_taken(), Some(42));
242242
}
243243

244244
#[test]
@@ -251,7 +251,7 @@ mod tests {
251251
};
252252

253253
let item_stack: ItemStack = slot.into();
254-
assert_eq!(item_stack.item, Item::Air);
254+
assert_eq!(item_stack.item(), Item::Air);
255255
}
256256

257257
#[test]
@@ -285,7 +285,10 @@ mod tests {
285285
};
286286
assert_eq!(slot.convert_index().unwrap(), expected);
287287
assert_eq!(
288-
InventorySlot::from_network_index(expected, ItemStack::new(Item::Stone, 1)),
288+
InventorySlot::from_network_index(
289+
expected,
290+
ItemStack::new(Item::Stone, 1).unwrap()
291+
),
289292
Some(slot),
290293
);
291294
}

feather/base/src/anvil/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use super::{block_entity::BlockEntityData, entity::EntityData};
1010
use bitvec::{bitvec, vec::BitVec};
1111
use blocks::BlockId;
1212
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
13-
use generated::Biome;
13+
use libcraft_core::Biome;
1414
use serde::{Deserialize, Serialize};
1515
use std::borrow::Cow;
1616
use std::collections::BTreeMap;

feather/base/src/chunk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::usize;
22

33
use ::blocks::BlockId;
4-
use generated::Biome;
4+
use libcraft_core::Biome;
55

66
use crate::ChunkPosition;
77

feather/base/src/chunk/biome_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use generated::Biome;
1+
use libcraft_core::Biome;
22

33
use crate::{CHUNK_HEIGHT, CHUNK_WIDTH};
44

feather/base/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ pub use block::{BlockPositionValidationError, ValidBlockPosition};
2020
pub use blocks::*;
2121
pub use chunk::{Chunk, ChunkSection, CHUNK_HEIGHT, CHUNK_WIDTH};
2222
pub use chunk_lock::*;
23-
pub use generated::{Area, Biome, EntityKind, Inventory, Item, ItemStack};
23+
2424
pub use libcraft_blocks::{BlockKind, BlockState};
25-
pub use libcraft_core::{position, vec3, BlockPosition, ChunkPosition, Gamemode, Position, Vec3d};
25+
pub use libcraft_core::{
26+
position, vec3, Biome, BlockPosition, ChunkPosition, EntityKind, Gamemode, Position, Vec3d,
27+
};
28+
pub use libcraft_inventory::{Area, Inventory};
29+
pub use libcraft_items::{Item, ItemStack, ItemStackBuilder, ItemStackError};
2630
pub use libcraft_particles::{Particle, ParticleKind};
2731
pub use libcraft_text::{deserialize_text, Text, Title};
2832
#[doc(inline)]

0 commit comments

Comments
 (0)