Skip to content

Commit afed251

Browse files
BoySaniccareeokiIntegratedQuantum
authored
Implement Chisel as a proper tool (PixelGuys#2095)
- Replaces logic that checks for a chisel item for logic that checks for a chisel tool - Adds chisel tool via chisel.zig.zon TODO: - [x] ~~Fix break animation so that it displays only on the 1/8th of the block that's being broken~~ ~~Ended up disabling the animation for the chisel to match current behavior.~~ Fixing the animation will be in a separate issue. - [x] Fix chisel textures because they're completely broken right now - [x] Fix chisel matrix as it likely doesn't entirely make sense - [x] Make chisels take durability damage when breaking parts of a block Fixes PixelGuys#625 fixes PixelGuys#2140 --------- Co-authored-by: Carrie <carriecapp9@gmail.com> Co-authored-by: IntegratedQuantum <jahe788@gmail.com>
1 parent dda5fcb commit afed251

File tree

12 files changed

+146
-28
lines changed

12 files changed

+146
-28
lines changed

‎assets/cubyz/items/_migrations.zig.zon‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
.{.old = "coal", .new = "coal_ore"},
77
.{.old = "diamond", .new = "diamond_ore"},
88
.{.old = "mossy_cobblestone", .new = "cobblestone"},
9+
.{.old = "chisel", .new = "iron_ingot"},
910
}

‎assets/cubyz/items/chisel.zig.zon‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎assets/cubyz/recipes/special_recipes.zig.zon‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
.{
2-
.{
3-
.inputs = .{"{mod}:{type}_planks", "cubyz:iron_ingot"},
4-
.output = "cubyz:chisel",
5-
},
62
.{
73
.inputs = .{"cubyz:coal_ore", "{mod}:{type}_ore"},
84
.output = "{mod}:{type}_ingot",

‎assets/cubyz/tools/chisel.png‎

166 Bytes
Loading

‎assets/cubyz/tools/chisel.zig.zon‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
.{
2+
.blockTags = .{.chiselable},
3+
.disabled = .{
4+
0, 0, 1, 1, 1,
5+
0, 0, 0, 1, 1,
6+
1, 0, 0, 1, 1,
7+
1, 1, 1, 0, 0,
8+
1, 1, 1, 0, 0,
9+
},
10+
.optional = .{
11+
0, 1, 0, 0, 0,
12+
1, 1, 1, 0, 0,
13+
0, 1, 1, 0, 0,
14+
0, 0, 0, 1, 1,
15+
0, 0, 0, 1, 0,
16+
},
17+
.parameters = .{
18+
.{
19+
.source = .massDamage,
20+
.destination = .damage,
21+
.matrix = .{
22+
0.5, 0.5, 0x0, 0x0, 0x0,
23+
0.5, 0.5, 0.5, 0x0, 0x0,
24+
0x0, 0.5, 0.5, 0x0, 0x0,
25+
0x0, 0x0, 0x0, 0.5, 0.5,
26+
0x0, 0x0, 0x0, 0.5, 0.5,
27+
},
28+
.factor = 0.2,
29+
.method = .sum,
30+
},
31+
.{
32+
.source = .massDamage,
33+
.destination = .damage,
34+
.matrix = .{
35+
0.5, 0.5, 0x0, 0x0, 0x0,
36+
0.5, 0.5, 0.5, 0x0, 0x0,
37+
0x0, 0.5, 0.5, 0x0, 0x0,
38+
0x0, 0x0, 0x0, 0.5, 0.5,
39+
0x0, 0x0, 0x0, 0.5, 0.5,
40+
},
41+
.factor = 0.8,
42+
.method = .average,
43+
},
44+
.{
45+
.source = .hardnessDamage,
46+
.destination = .damage,
47+
.matrix = .{
48+
0.2, 0.1, 0x0, 0x0, 0x0,
49+
0.1, 0.1, 0.0, 0x0, 0x0,
50+
0x0, 0.0, 0.0, 0x0, 0x0,
51+
0x0, 0x0, 0x0, 0.0, 0.0,
52+
0x0, 0x0, 0x0, 0.0, 0.0,
53+
},
54+
.factor = 1.0,
55+
.method = .average,
56+
},
57+
.{
58+
.source = .durability,
59+
.destination = .maxDurability,
60+
.matrix = .{
61+
1.5, 1.5, 0x0, 0x0, 0x0,
62+
1.5, 2.0, 1.0, 0x0, 0x0,
63+
0x0, 1.0, 0.5, 0.5, 0x0,
64+
0x0, 0x0, 0.5, 0.1, 0.1,
65+
0x0, 0x0, 0x0, 0.1, 0.1,
66+
},
67+
.factor = 0.2,
68+
.method = .sum,
69+
},
70+
.{
71+
.source = .durability,
72+
.destination = .maxDurability,
73+
.matrix = .{
74+
1.5, 1.5, 0x0, 0x0, 0x0,
75+
1.5, 2.0, 1.0, 0x0, 0x0,
76+
0x0, 1.0, 0.5, 0.5, 0x0,
77+
0x0, 0x0, 0.5, 0.1, 0.1,
78+
0x0, 0x0, 0x0, 0.1, 0.1,
79+
},
80+
.factor = 0.8,
81+
.method = .average,
82+
},
83+
.{
84+
.source = .swingSpeed,
85+
.destination = .swingSpeed,
86+
.matrix = .{
87+
1.0, 1.0, 0x0, 0x0, 0x0,
88+
1.0, 1.5, 1.0, 0x0, 0x0,
89+
0x0, 1.0, 1.0, 1.0, 0x0,
90+
0x0, 0x0, 1.0, 0.5, 0.5,
91+
0x0, 0x0, 0x0, 0.5, 0.5,
92+
},
93+
.factor = -0.2,
94+
.method = .sum,
95+
},
96+
.{
97+
.source = .swingSpeed,
98+
.destination = .swingSpeed,
99+
.matrix = .{
100+
1.0, 1.0, 0x0, 0x0, 0x0,
101+
1.0, 1.5, 1.0, 0x0, 0x0,
102+
0x0, 1.0, 1.0, 1.0, 0x0,
103+
0x0, 0x0, 1.0, 0.5, 0.5,
104+
0x0, 0x0, 0x0, 0.5, 0.5,
105+
},
106+
.factor = 1.2,
107+
.method = .average,
108+
},
109+
},
110+
}
184 Bytes
Loading

‎mods/cubyz/rotation/stairs.zig‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const RayIntersectionResult = rotation.RayIntersectionResult;
1111
const RotationMode = rotation.RotationMode;
1212
const vec = main.vec;
1313
const Mat4f = vec.Mat4f;
14+
const Tag = main.Tag;
1415
const Vec2f = vec.Vec2f;
1516
const Vec3f = vec.Vec3f;
1617
const Vec3i = vec.Vec3i;
@@ -276,9 +277,12 @@ fn closestRay(comptime typ: enum {bit, intersection}, block: Block, relativePlay
276277
pub fn rayIntersection(block: Block, item: ?main.items.Item, relativePlayerPos: Vec3f, playerDir: Vec3f) ?RayIntersectionResult {
277278
if(item) |_item| {
278279
switch(_item) {
279-
.baseItem => |baseItem| {
280-
if(std.mem.eql(u8, baseItem.id(), "cubyz:chisel")) { // Select only one eighth of a block
281-
return closestRay(.intersection, block, relativePlayerPos, playerDir);
280+
.tool => |tool| {
281+
const tags = tool.type.blockTags();
282+
for(tags) |tag| {
283+
if(tag == .chiselable) {
284+
return closestRay(.intersection, block, relativePlayerPos, playerDir);
285+
}
282286
}
283287
},
284288
else => {},
@@ -290,11 +294,13 @@ pub fn rayIntersection(block: Block, item: ?main.items.Item, relativePlayerPos:
290294
pub fn onBlockBreaking(item: ?main.items.Item, relativePlayerPos: Vec3f, playerDir: Vec3f, currentData: *Block) void {
291295
if(item) |_item| {
292296
switch(_item) {
293-
.baseItem => |baseItem| {
294-
if(std.mem.eql(u8, baseItem.id(), "cubyz:chisel")) { // Break only one eigth of a block
295-
currentData.data |= closestRay(.bit, currentData.*, relativePlayerPos, playerDir);
296-
if(currentData.data == 255) currentData.* = .{.typ = 0, .data = 0};
297-
return;
297+
.tool => |tool| {
298+
for(tool.type.blockTags()) |tag| {
299+
if(tag == .chiselable) {
300+
currentData.data |= closestRay(.bit, currentData.*, relativePlayerPos, playerDir);
301+
if(currentData.data == 255) currentData.* = .{.typ = 0, .data = 0};
302+
return;
303+
}
298304
}
299305
},
300306
else => {},
@@ -306,8 +312,12 @@ pub fn onBlockBreaking(item: ?main.items.Item, relativePlayerPos: Vec3f, playerD
306312
pub fn canBeChangedInto(oldBlock: Block, newBlock: Block, item: main.items.ItemStack, shouldDropSourceBlockOnSuccess: *bool) RotationMode.CanBeChangedInto {
307313
if(oldBlock.typ != newBlock.typ) return RotationMode.DefaultFunctions.canBeChangedInto(oldBlock, newBlock, item, shouldDropSourceBlockOnSuccess);
308314
if(oldBlock.data == newBlock.data) return .no;
309-
if(item.item != null and item.item.? == .baseItem and std.mem.eql(u8, item.item.?.baseItem.id(), "cubyz:chisel")) {
310-
return .yes; // TODO: Durability change, after making the chisel a proper tool.
315+
if(item.item != null and item.item.? == .tool) {
316+
return .{.yes_costsDurability = 1};
311317
}
312318
return .no;
313319
}
320+
321+
pub fn getBlockTags() []const Tag {
322+
return &.{.chiselable};
323+
}

‎src/blocks.zig‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ pub fn register(_: []const u8, id: []const u8, zon: ZonElement) u16 {
102102
_mode[size] = rotation.getByID(zon.get([]const u8, "rotation", "cubyz:no_rotation"));
103103
_blockHealth[size] = zon.get(f32, "blockHealth", 1);
104104
_blockResistance[size] = zon.get(f32, "blockResistance", 0);
105+
const rotation_tags = _mode[size].getBlockTags();
106+
const block_tags = Tag.loadTagsFromZon(main.stackAllocator, zon.getChild("tags"));
107+
defer main.stackAllocator.free(block_tags);
108+
_blockTags[size] = std.mem.concat(main.worldArena.allocator, Tag, &.{rotation_tags, block_tags}) catch unreachable;
105109

106-
_blockTags[size] = Tag.loadTagsFromZon(main.worldArena, zon.getChild("tags"));
107110
if(_blockTags[size].len == 0) std.log.err("Block {s} is missing 'tags' field", .{id});
108111
for(_blockTags[size]) |tag| {
109112
if(tag == Tag.sbbChild) {

‎src/items.zig‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,6 @@ pub const Tool = struct { // MARK: Tool
811811
return self.texture.?;
812812
}
813813

814-
fn id(self: *Tool) []const u8 {
815-
return self.type.id();
816-
}
817-
818814
fn getTooltip(self: *Tool) []const u8 {
819815
self.tooltip.clearRetainingCapacity();
820816
self.tooltip.writer().print(
@@ -958,7 +954,10 @@ pub const Item = union(ItemType) { // MARK: Item
958954

959955
pub fn id(self: Item) []const u8 {
960956
switch(self) {
961-
inline else => |item| {
957+
.tool => |tool| {
958+
return tool.type.id();
959+
},
960+
.baseItem => |item| {
962961
return item.id();
963962
},
964963
}

‎src/renderer.zig‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,10 +1069,6 @@ pub const MeshSelection = struct { // MARK: MeshSelection
10691069
if(isTool) {
10701070
damage = stack.item.?.tool.getBlockDamage(block);
10711071
}
1072-
const isChisel = stack.item != null and stack.item.? == .baseItem and std.mem.eql(u8, stack.item.?.baseItem.id(), "cubyz:chisel");
1073-
if(isChisel and block.mode() == main.rotation.getByID("cubyz:stairs")) { // TODO: Remove once the chisel is a tool.
1074-
damage = block.blockHealth() + block.blockResistance();
1075-
}
10761072
damage -= block.blockResistance();
10771073
if(damage > 0) {
10781074
const swingTime = if(isTool and stack.item.?.tool.isEffectiveOn(block)) 1.0/stack.item.?.tool.swingSpeed else 0.5;

0 commit comments

Comments
 (0)