diff --git a/src/rotation/texture_pile.zig b/src/rotation/texture_pile.zig index 69d2705c..cbfec4da 100644 --- a/src/rotation/texture_pile.zig +++ b/src/rotation/texture_pile.zig @@ -73,20 +73,26 @@ pub fn onBlockBreaking(_: ?main.items.Item, _: Vec3f, _: Vec3f, currentData: *Bl if(currentData.data == 0) { currentData.* = .{.typ = 0, .data = 0}; } else { - currentData.data = currentData.data - 1; + currentData.data = @min(currentData.data, currentData.modeData() - 1) - 1; } } +fn isItemBlock(block: Block, item: main.items.ItemStack) bool { + return item.item != null and item.item.? == .baseItem and item.item.?.baseItem.block == block.typ; +} + pub fn canBeChangedInto(oldBlock: Block, newBlock: Block, item: main.items.ItemStack, shouldDropSourceBlockOnSuccess: *bool) RotationMode.CanBeChangedInto { switch(RotationMode.DefaultFunctions.canBeChangedInto(oldBlock, newBlock, item, shouldDropSourceBlockOnSuccess)) { .no, .yes_costsDurability, .yes_dropsItems => return .no, - .yes, .yes_costsItems => { - const amountChange = @as(i32, newBlock.data) - if(oldBlock.typ == newBlock.typ) @as(i32, oldBlock.data) else 0; - if(amountChange <= 0) { - return .{.yes_dropsItems = @intCast(-amountChange)}; + .yes_costsItems => |r| return .{.yes_costsItems = r}, + .yes => { + const oldAmount = if(oldBlock.typ == newBlock.typ) @min(oldBlock.data, oldBlock.modeData() - 1) else 0; + if(oldAmount == newBlock.data) return .no; + if(oldAmount < newBlock.data) { + if(!isItemBlock(newBlock, item)) return .no; + return .{.yes_costsItems = newBlock.data - oldAmount}; } else { - if(item.item == null or item.item.? != .baseItem or item.item.?.baseItem.block != newBlock.typ) return .no; - return .{.yes_costsItems = @intCast(amountChange)}; + return .{.yes_dropsItems = oldAmount - newBlock.data}; } }, }