From 07f5d823ddb95fabfa529e88d246bd9cb7437fd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Wi=C5=9Bniewski?= Date: Sun, 23 Mar 2025 19:35:38 +0100 Subject: [PATCH] Add `pile` rotation mode (#1216) * Add pile rotation mode * Fix formatting issues * Rename to .zig.zon * Update textures to those provided by ikabood-kee * Add gradual block breaking * Adapt to new model and texture changes * New duckweed textures * Add configurable state count * Rename to texturePile * Add moreData storage * Apply review suggestions --------- Co-authored-by: Carrie --- assets/cubyz/blocks/duckweed.zig.zon | 24 +++++ assets/cubyz/blocks/textures/duckweed/0.png | Bin 0 -> 282 bytes assets/cubyz/blocks/textures/duckweed/1.png | Bin 0 -> 362 bytes assets/cubyz/blocks/textures/duckweed/2.png | Bin 0 -> 469 bytes assets/cubyz/blocks/textures/duckweed/3.png | Bin 0 -> 483 bytes assets/cubyz/items/textures/duckweed.png | Bin 0 -> 306 bytes src/blocks.zig | 7 +- src/rotation.zig | 102 ++++++++++++++++++-- 8 files changed, 122 insertions(+), 11 deletions(-) create mode 100644 assets/cubyz/blocks/duckweed.zig.zon create mode 100644 assets/cubyz/blocks/textures/duckweed/0.png create mode 100644 assets/cubyz/blocks/textures/duckweed/1.png create mode 100644 assets/cubyz/blocks/textures/duckweed/2.png create mode 100644 assets/cubyz/blocks/textures/duckweed/3.png create mode 100644 assets/cubyz/items/textures/duckweed.png diff --git a/assets/cubyz/blocks/duckweed.zig.zon b/assets/cubyz/blocks/duckweed.zig.zon new file mode 100644 index 00000000..4ba7afd8 --- /dev/null +++ b/assets/cubyz/blocks/duckweed.zig.zon @@ -0,0 +1,24 @@ +.{ + .tags = .{.leaf}, + .blockHealth = 0.2, + .drops = .{ + .{.items = .{.auto}}, + }, + .degradable = true, + .collide = false, + .alwaysViewThrough = true, + .absorbedLight = 0x000000, + .model = .{ + .model = "cubyz:plane", + .states = 4, + }, + .rotation = .texturePile, + .texture0 = "cubyz:duckweed/0", + .texture1 = "cubyz:duckweed/1", + .texture2 = "cubyz:duckweed/2", + .texture3 = "cubyz:duckweed/3", + .item = .{ + .texture = "duckweed.png", + }, + .lodReplacement = "cubyz:air", +} diff --git a/assets/cubyz/blocks/textures/duckweed/0.png b/assets/cubyz/blocks/textures/duckweed/0.png new file mode 100644 index 0000000000000000000000000000000000000000..6d415a0aba4ea8a49e459376ad4ff018c550c262 GIT binary patch literal 282 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`4?SHRLo9le6Amyc-TM0PcG{}{ z$5r{6eRinG#r!*VK=(k~h3** zSIvTTTGH)!2LQOQ=mEe=ZTpT^chJoppWh$-zap;*0Gvn#hFORG75c;&)^5i~^CqjF zB)ht~7?U?yMPcF_?#s4U4F7DRK>RrDuh?W2(XgmbjCEQXL*sPLxq)&`icL)=oi@YY?T%cj< z9kcVM1V;iR@f5>~yr%K}BNg-vA7O5Qd<61Ih~3dh1YpT|8wrrHP;KC? z-eN|p?TCK;UQzE=0e{ZX?D%MQtnYCW`8xo_N%R9F063&uZry-YxI}I&0l@yW;qccR zS~uYH7Xv_%mDIYyiw^15cjy|%?fO8RL_Dc1L|sU*@cji< zwnLGXv_EYa00Qkxh&l@ZXx)Iyc5uyKxX4N>vXX*TxWw~5`iI-~0oO2eSkL>2#d-!; z_b9T`cXvp)Ja=`E#d-z+$c?2qiP+Ws#FiH609!X;QcWiwClNpIBZ{n~quH@*7`d?| zHgDGlK0m%*QxI?!E`94_D^4P=YzLW0ZY)){^Y3#B30NY0C%Af?w7oxVc(I;Mc0pV6 zA2OEjwi6)4Xh;w5} z_FHy9c0Uq>K?xVN01(L%y*W000000 LNkvXXu0mjfd295Jlg}Ya4+8nSFqy3E;}E)42B$jNHIS&FB;p50UH>kBd?KgAStK-2 zr5&^Kzm~#xqJ$<9B3lm}vr=s5ytMa^H>ZUv-6Y~oEb>b9T|_GHn3WPfpfI+uZ&jxM ZzXAUlE}mV$qI>`V002ovPDHLkV1mcy7f=&}i80byh!z{ApdeWb1a<}O zb()=-%>Mj0yTH$fA{OImkLUSnc2M&A9;MhUPRjdb08rl>u18*3k9Qm$gsNE1Zyz00 z1OR|VDVm0g>m>o9dab)!1OOOKY(De|u9pOlTUzuxPA0VVnS@g~5P1nzL8y+k&)|9l zEJ_guF`7ozu+(uqg5xeOm|Il7aNZ}CWl9q)$}G408ca(=7?fh|zV>opb5W!rE+!0O zbO$A?_ 16) { + std.log.err("Block '{s}' uses texture pile with {} states. 'texturePile' can have at most 16 states.", .{blockId, stateCount}); + } + modeData.* = stateCount; + + if(rotatedModels.get(modelId)) |modelIndex| return modelIndex; + + const baseModel = main.models.getModelIndex(modelId).model(); + + const modelIndex = baseModel.transformModel(transform, .{@as(u16, @intCast(0))}); + for(1..16) |data| { + _ = baseModel.transformModel(transform, .{@as(u16, @intCast(data))}); + } + rotatedModels.put(modelId, modelIndex) catch unreachable; + return modelIndex; + } + + pub fn model(block: Block) ModelIndex { + return .{.index = blocks.meshes.modelIndexStart(block).index + @min(block.data, block.modeData() - 1)}; + } + + pub fn generateData(_: *main.game.World, _: Vec3i, _: Vec3f, _: Vec3f, _: Vec3i, _: ?Neighbor, currentData: *Block, _: Block, blockPlacing: bool) bool { + if(blockPlacing) { + currentData.data = 0; + return true; + } + if(currentData.data >= currentData.modeData() - 1) { + return false; + } + currentData.data = currentData.data + 1; + return true; + } + + pub fn onBlockBreaking(_: ?main.items.Item, _: Vec3f, _: Vec3f, currentData: *Block) void { + if(currentData.data == 0) { + currentData.* = .{.typ = 0, .data = 0}; + } else { + currentData.data = currentData.data - 1; + } + } + + 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)}; + } else { + if(item.item == null or item.item.? != .baseItem or item.item.?.baseItem.block != newBlock.typ) return .no; + return .{.yes_costsItems = @intCast(amountChange)}; + } + }, + } + } + }; }; // MARK: init/register