From 37cbaa4a3ceba493057c764cfe5d283b2b23a63d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Wed, 3 Nov 2021 16:41:42 +0100 Subject: [PATCH] Restrict item overdraw placement --- code/game/src/items.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/code/game/src/items.c b/code/game/src/items.c index e54e88b..3c6380a 100644 --- a/code/game/src/items.c +++ b/code/game/src/items.c @@ -54,7 +54,13 @@ void item_use(ecs_world_t *ecs, ItemDrop *it, Position p, uint64_t udata) { case UKIND_HOLD: /* NOOP */ break; case UKIND_PLACE:{ world_block_lookup l = world_block_from_realpos(p.x, p.y); - if (l.block_id > 0) { + if (l.is_outer && l.block_id > 0) { + // NOTE(zaklaus): Check if block is a placeable item, cancel the placement if not met + asset_id item_asset = blocks_get_asset(l.block_id); + uint16_t item_asset_id = item_find(item_asset); + if (item_asset_id == ASSET_INVALID) return; + if (item_get_usage(item_asset_id) > UKIND_END_PLACE) return; + world_chunk_destroy_block(p.x, p.y, true); } world_chunk_replace_block(l.chunk_id, l.id, blocks_find(desc->place.kind + (asset_id)udata));