Allow sticking ores back into the ground (and other things)

fixes #982
This commit is contained in:
IntegratedQuantum 2025-02-09 19:57:46 +01:00
parent 5bea8f41b6
commit a0663d7338
2 changed files with 24 additions and 0 deletions

View File

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

View File

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