From a0663d733808ad0c89563c65877832b920b53b7a Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Sun, 9 Feb 2025 19:57:46 +0100 Subject: [PATCH] Allow sticking ores back into the ground (and other things) fixes #982 --- src/renderer.zig | 6 ++++++ src/rotation.zig | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/renderer.zig b/src/renderer.zig index 570aed5e..ce9e9605 100644 --- a/src/renderer.zig +++ b/src/renderer.zig @@ -802,6 +802,12 @@ pub const MeshSelection = struct { // MARK: MeshSelection updateBlockAndSendUpdate(inventory, slot, selectedPos[0], selectedPos[1], selectedPos[2], oldBlock, block); return; } + } else { + if(rotationMode.modifyBlock(&block, itemBlock)) { + if(!canPlaceBlock(selectedPos, block)) return; + updateBlockAndSendUpdate(inventory, slot, selectedPos[0], selectedPos[1], selectedPos[2], oldBlock, block); + return; + } } // Check the block in front of it: const neighborPos = posBeforeBlock; diff --git a/src/rotation.zig b/src/rotation.zig index 53677ef1..ea802917 100644 --- a/src/rotation.zig +++ b/src/rotation.zig @@ -35,6 +35,9 @@ pub const RotationMode = struct { // MARK: RotationMode fn updateData(_: *Block, _: Neighbor, _: Block) bool { return false; } + fn modifyBlock(_: *Block, _: u16) bool { + return false; + } fn rayIntersection(block: Block, _: ?main.items.Item, relativePlayerPos: Vec3f, playerDir: Vec3f) ?RayIntersectionResult { return rayModelIntersection(blocks.meshes.model(block), relativePlayerPos, playerDir); } @@ -115,6 +118,8 @@ pub const RotationMode = struct { // MARK: RotationMode /// Updates data of a placed block if the RotationMode dependsOnNeighbors. updateData: *const fn(block: *Block, neighbor: Neighbor, neighborBlock: Block) bool = &DefaultFunctions.updateData, + modifyBlock: *const fn(block: *Block, newType: u16) bool = DefaultFunctions.modifyBlock, + rayIntersection: *const fn(block: Block, item: ?main.items.Item, relativePlayerPos: Vec3f, playerDir: Vec3f) ?RayIntersectionResult = &DefaultFunctions.rayIntersection, onBlockBreaking: *const fn(item: ?main.items.Item, relativePlayerPos: Vec3f, playerDir: Vec3f, currentData: *Block) void = &DefaultFunctions.onBlockBreaking, @@ -947,6 +952,19 @@ pub const RotationModes = struct { modelCache = modelIndex; return modelIndex; } + + pub fn generateData(_: *main.game.World, _: Vec3i, _: Vec3f, _: Vec3f, _: Vec3i, _: ?Neighbor, _: *Block, _: Block, _: bool) bool { + return false; + } + + pub fn modifyBlock(block: *Block, newBlockType: u16) bool { + if(block.transparent() or block.viewThrough()) return false; + if(!main.models.models.items[main.blocks.meshes.modelIndexStart(block.*)].allNeighborsOccluded) return false; + if(block.data != 0) return false; + block.data = block.typ; + block.typ = newBlockType; + return true; + } }; };