Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add optimistic update for block placement #3391

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/plugins/place_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Comment on lines +12 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This should be using the registry
  2. This is not a correct way to deduce correct block state from an item
  3. If world state is mutated then you must ensure that the data is fully in sync with the server (how does this handle the case where the server rejects?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I already answered 3rd question in the description. If the server rejects a block update would be emitted (even if it's air) as this is what the native client also does.

Can you elaborate on the 2nd question?


let newBlock = bot.blockAt(dest)
if (oldBlock.type === newBlock.type) {
[oldBlock, newBlock] = await onceWithCleanup(bot, `blockUpdate:${dest}`, {
Expand Down
Loading