Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion assets/cubyz/blocks/duckweed.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
.texture3 = "cubyz:duckweed/3",
.item = .{
.texture = "duckweed.png",
.tags = .{.fluidPlaceable},
.placementTags = .{.fluid},
},
.lodReplacement = "cubyz:air",
}
2 changes: 1 addition & 1 deletion assets/cubyz/blocks/lava.zig.zon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.{
.tags = .{.fluid, .hot},
.drops = .{},
.selectionRule = .toolEffective,
.selectionRule = .placeable,
.replaceable = true,
.degradable = true,
.transparent = true,
Expand Down
2 changes: 1 addition & 1 deletion assets/cubyz/blocks/lily_pad.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
.texture = "cubyz:lily_pad",
.item = .{
.texture = "lily_pad.png",
.tags = .{.fluidPlaceable},
.placementTags = .{.fluid},
},
.lodReplacement = "cubyz:air",
}
2 changes: 1 addition & 1 deletion assets/cubyz/blocks/water.zig.zon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.{
.tags = .{.fluid},
.drops = .{},
.selectionRule = .toolEffective,
.selectionRule = .placeable,
.replaceable = true,
.degradable = true,
.transparent = true,
Expand Down
8 changes: 2 additions & 6 deletions src/blocks.zig
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub const Ore = struct {
seed: u64,
};

const SelectionRule = enum { always, toolEffective, never };
const SelectionRule = enum { always, toolEffective, placeable, never };

var _transparent: [maxBlockCount]bool = undefined;
var _collide: [maxBlockCount]bool = undefined;
Expand Down Expand Up @@ -530,14 +530,10 @@ pub const Block = packed struct(u32) { // MARK: Block
pub fn isSelectableByItem(self: Block, item: Item) bool {
if (item == .baseItem and item.baseItem.block() == self.typ) return true;

if (self.hasTag(.fluid)) {
const fluidPlaceable = item == .baseItem and item.baseItem.hasTag(.fluidPlaceable);
return fluidPlaceable;
}

return switch (self.selectionRule()) {
.always => true,
.toolEffective => item == .proceduralItem and item.proceduralItem.isEffectiveOn(self),
.placeable => item == .baseItem and item.baseItem.isPlaceableOn(self),
.never => false,
};
}
Expand Down
22 changes: 22 additions & 0 deletions src/items.zig
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ pub const BaseItemIndex = enum(u16) { // MARK: BaseItemIndex
pub fn hasTag(self: BaseItemIndex, tag: Tag) bool {
return itemList[@intFromEnum(self)].hasTag(tag);
}
pub fn hasPlacementTag(self: BaseItemIndex, tag: Tag) bool {
return itemList[@intFromEnum(self)].hasPlacementTag(tag);
}
pub fn isPlaceableOn(self: BaseItemIndex, targetedBlock: Block) bool {
return itemList[@intFromEnum(self)].isPlaceableOn(targetedBlock);
}
pub fn hashCode(self: BaseItemIndex) u32 {
return itemList[@intFromEnum(self)].hashCode();
}
Expand All @@ -268,6 +274,7 @@ pub const BaseItem = struct { // MARK: BaseItem
id: []const u8,
name: []const u8,
tags: []const Tag,
placementTags: []const Tag,
tooltip: []const u8,

stackSize: u16,
Expand All @@ -287,6 +294,7 @@ pub const BaseItem = struct { // MARK: BaseItem
}
self.name = allocator.dupe(u8, zon.get([]const u8, "name", id));
self.tags = Tag.loadTagsFromZon(allocator, zon.getChild("tags"));
self.placementTags = Tag.loadTagsFromZon(allocator, zon.getChild("placementTags"));
self.stackSize = zon.get(u16, "stackSize", 120);
const material = zon.getChild("material");
if (material == .object) {
Expand Down Expand Up @@ -356,6 +364,20 @@ pub const BaseItem = struct { // MARK: BaseItem
}
return false;
}

pub fn hasPlacementTag(self: *const BaseItem, tag: Tag) bool {
for (self.placementTags) |other| {
if (other == tag) return true;
}
return false;
}

pub fn isPlaceableOn(self: *const BaseItem, block: Block) bool {
for (block.tags()) |tag| {
if (self.hasPlacementTag(tag)) return true;
}
return false;
}
};

/// Generates the texture of a ProceduralItem using the material information.
Expand Down
5 changes: 2 additions & 3 deletions src/tag.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ pub const Tag = enum(u32) {
air = 0,
fluid = 1,
sbbChild = 2,
fluidPlaceable = 3,
chiselable = 4,
playerModel = 5,
chiselable = 3,
playerModel = 4,
_,

pub fn initTags() void {
Expand Down
Loading