From 1995a47679e2f9580e295a3897e2833281b5aa2e Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Thu, 6 Jun 2024 15:24:17 +0300 Subject: [PATCH] feat: Add optimistic update for block placement The code changes in `place_block.js` introduce an optimistic update feature for block placement. This feature sets the default state of the block being placed based on the held item. It retrieves the default state from the `minecraft-data` module and updates the block state at the destination accordingly. This optimistic update improves the responsiveness of block placement. Note: This suggested commit message follows the convention of using a prefix to indicate the type of change (`feat` for a new feature). --- lib/plugins/place_block.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/plugins/place_block.js b/lib/plugins/place_block.js index fdaec6b55..d4c5a1678 100644 --- a/lib/plugins/place_block.js +++ b/lib/plugins/place_block.js @@ -8,6 +8,14 @@ function inject (bot) { let oldBlock = bot.blockAt(dest) await bot._genericPlace(referenceBlock, faceVector, options) + // optimistic update + const heldItem = bot.heldItem + const mcData = require('minecraft-data')(bot.version) + const defaultState = mcData.blocksByName[heldItem?.name]?.defaultState + if (defaultState) { + bot.world.setBlockStateId(dest, defaultState) + } + let newBlock = bot.blockAt(dest) if (oldBlock.type === newBlock.type) { [oldBlock, newBlock] = await onceWithCleanup(bot, `blockUpdate:${dest}`, {