Fix texture_pile (#1340)

* Fix texture pile

* Update src/rotation/texture_pile.zig

Co-authored-by: IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com>

* Apply review change requests

* Apply review change requests

* Update src/rotation/texture_pile.zig

Co-authored-by: IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com>

* Apply review change requests

---------

Co-authored-by: IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com>
This commit is contained in:
Krzysztof Wiśniewski 2025-04-25 20:50:48 +02:00 committed by GitHub
parent fde5a69cdc
commit c06e2c4673
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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};
}
},
}