refund block if we replace the same ID

isolation_bkp/dynres
Dominik Madarász 2021-11-03 17:16:35 +01:00
parent 51d60169b3
commit dcd5f0046a
2 changed files with 6 additions and 5 deletions

View File

@ -86,7 +86,7 @@ void buildmode_draw(void) {
} }
if (!is_outside_range) if (!is_outside_range)
renderer_draw_single(cam.x, cam.y, ASSET_EMPTY, ColorAlpha(BLUE, 0.4f)); renderer_draw_single(cam.x, cam.y, ASSET_EMPTY, ColorAlpha(WHITE, 0.2f));
build_num_placements = zpl_min(build_num_placements, qty); build_num_placements = zpl_min(build_num_placements, qty);
} }
@ -94,7 +94,7 @@ void buildmode_draw(void) {
for (size_t i = 0; i < build_num_placements; i++) { for (size_t i = 0; i < build_num_placements; i++) {
item_placement *it = &build_placements[i]; item_placement *it = &build_placements[i];
renderer_draw_single(it->x, it->y, ASSET_EMPTY, ColorAlpha(BLUE, 0.4f)); renderer_draw_single(it->x, it->y, ASSET_EMPTY, ColorAlpha(WHITE, 0.4f));
} }
if (build_is_in_draw_mode) { if (build_is_in_draw_mode) {

View File

@ -55,13 +55,14 @@ void item_use(ecs_world_t *ecs, ItemDrop *it, Position p, uint64_t udata) {
case UKIND_PLACE:{ case UKIND_PLACE:{
world_block_lookup l = world_block_from_realpos(p.x, p.y); world_block_lookup l = world_block_from_realpos(p.x, p.y);
if (l.is_outer && 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); asset_id item_asset = blocks_get_asset(l.block_id);
uint16_t item_asset_id = item_find(item_asset); uint16_t item_asset_id = item_find(item_asset);
if (item_asset_id == ASSET_INVALID) return; 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); // NOTE(zaklaus): If we replace the same item, refund 1 qty and let it replace it
if (item_asset_id == item_id) {
it->quantity++;
}
} }
world_chunk_replace_block(l.chunk_id, l.id, blocks_find(desc->place.kind + (asset_id)udata)); world_chunk_replace_block(l.chunk_id, l.id, blocks_find(desc->place.kind + (asset_id)udata));
it->quantity--; it->quantity--;