diff --git a/assets/cubyz/blocks/duckweed.zig.zon b/assets/cubyz/blocks/duckweed.zig.zon index e96ad15413..561d04fab8 100644 --- a/assets/cubyz/blocks/duckweed.zig.zon +++ b/assets/cubyz/blocks/duckweed.zig.zon @@ -19,7 +19,7 @@ .texture3 = "cubyz:duckweed/3", .item = .{ .texture = "duckweed.png", - .tags = .{.fluidPlaceable}, + .placementTags = .{.fluid}, }, .lodReplacement = "cubyz:air", } diff --git a/assets/cubyz/blocks/lava.zig.zon b/assets/cubyz/blocks/lava.zig.zon index 5b6d69b8f7..7772926385 100644 --- a/assets/cubyz/blocks/lava.zig.zon +++ b/assets/cubyz/blocks/lava.zig.zon @@ -1,7 +1,7 @@ .{ .tags = .{.fluid, .hot}, .drops = .{}, - .selectionRule = .toolEffective, + .selectionRule = .placeable, .replaceable = true, .degradable = true, .transparent = true, diff --git a/assets/cubyz/blocks/lily_pad.zig.zon b/assets/cubyz/blocks/lily_pad.zig.zon index 538a2ee1e3..ca8bfce059 100644 --- a/assets/cubyz/blocks/lily_pad.zig.zon +++ b/assets/cubyz/blocks/lily_pad.zig.zon @@ -12,7 +12,7 @@ .texture = "cubyz:lily_pad", .item = .{ .texture = "lily_pad.png", - .tags = .{.fluidPlaceable}, + .placementTags = .{.fluid}, }, .lodReplacement = "cubyz:air", } diff --git a/assets/cubyz/blocks/water.zig.zon b/assets/cubyz/blocks/water.zig.zon index bab25cc46f..88a628f78e 100644 --- a/assets/cubyz/blocks/water.zig.zon +++ b/assets/cubyz/blocks/water.zig.zon @@ -1,7 +1,7 @@ .{ .tags = .{.fluid}, .drops = .{}, - .selectionRule = .toolEffective, + .selectionRule = .placeable, .replaceable = true, .degradable = true, .transparent = true, diff --git a/src/blocks.zig b/src/blocks.zig index 99b6962014..e08a55f9ce 100644 --- a/src/blocks.zig +++ b/src/blocks.zig @@ -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; @@ -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, }; } diff --git a/src/items.zig b/src/items.zig index e3f3e2be5d..5347835d3e 100644 --- a/src/items.zig +++ b/src/items.zig @@ -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(); } @@ -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, @@ -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) { @@ -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. diff --git a/src/tag.zig b/src/tag.zig index e773501e1e..8492bee94c 100644 --- a/src/tag.zig +++ b/src/tag.zig @@ -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 {