feat: now project uses correct interaction box shapes for all blocks! For example redstone wire or wall sign didn't have correct cursor interaction shapes, which was annoying when you wanted to destroy the wire after the current one. The only known unsupported block is light block which can be focused / destroyed only when you hold the light item in your hand
This commit is contained in:
parent
e938212435
commit
01c2673f70
5 changed files with 6624 additions and 11 deletions
9
src/devtools.ts
Normal file
9
src/devtools.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// global variables useful for debugging
|
||||
|
||||
// Object.defineProperty(window, 'cursorBlock', )
|
||||
|
||||
window.cursorBlockRel = (x = 0, y = 0, z = 0) => {
|
||||
const newPos = bot.blockAtCursor(5)?.position.offset(x, y, z)
|
||||
if (!newPos) return
|
||||
return bot.world.getBlock(newPos)
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import './styles.css'
|
|||
import './globals'
|
||||
import 'iconify-icon'
|
||||
import './getCollisionShapes'
|
||||
import './devtools'
|
||||
import { onGameLoad } from './playerWindows'
|
||||
|
||||
import './menus/components/button'
|
||||
|
|
@ -85,6 +86,8 @@ import { loadInMemorySave } from './react/SingleplayerProvider'
|
|||
// side effects
|
||||
import { downloadSoundsIfNeeded } from './soundSystem'
|
||||
import EventEmitter from 'events'
|
||||
import outputInteractionShapesJson from './interactionShapesGenerated.json'
|
||||
window.interactionShapes = outputInteractionShapesJson
|
||||
|
||||
window.debug = debug
|
||||
window.THREE = THREE
|
||||
|
|
|
|||
6593
src/interactionShapesGenerated.json
Normal file
6593
src/interactionShapesGenerated.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -49,6 +49,8 @@ const defaultOptions = {
|
|||
disableLoadPrompts: false,
|
||||
guestUsername: 'guest',
|
||||
askGuestName: true,
|
||||
/** Actually might be useful */
|
||||
showCursorBlockInSpectator: false,
|
||||
|
||||
// advanced bot options
|
||||
autoRespawn: false,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import { Vec3 } from 'vec3'
|
|||
import { LineMaterial, Wireframe, LineSegmentsGeometry } from 'three-stdlib'
|
||||
import { isGameActive } from './globalState'
|
||||
import { assertDefined } from './utils'
|
||||
import { options } from './optionsStorage'
|
||||
|
||||
function getViewDirection (pitch, yaw) {
|
||||
const csPitch = Math.cos(pitch)
|
||||
|
|
@ -131,6 +132,19 @@ class WorldInteraction {
|
|||
bot.on('diggingAborted', () => {
|
||||
this.breakStartTime = undefined
|
||||
})
|
||||
|
||||
const upLineMaterial = () => {
|
||||
const inCreative = bot.game.gameMode === 'creative'
|
||||
this.lineMaterial = new LineMaterial({
|
||||
color: inCreative ? 0x40_80_ff : 0x00_00_00,
|
||||
linewidth: viewer.renderer.getPixelRatio() * 2,
|
||||
// dashed: true,
|
||||
// dashSize: 5,
|
||||
})
|
||||
}
|
||||
upLineMaterial()
|
||||
// todo use gamemode update only
|
||||
bot.on('game', upLineMaterial)
|
||||
}
|
||||
|
||||
updateBlockInteractionLines (blockPos: Vec3 | null, shapePositions?: Array<{ position; width; height; depth }>) {
|
||||
|
|
@ -147,23 +161,14 @@ class WorldInteraction {
|
|||
}
|
||||
|
||||
const group = new THREE.Group()
|
||||
//@ts-expect-error
|
||||
for (const { position, width, height, depth } of shapePositions) {
|
||||
for (const { position, width, height, depth } of shapePositions ?? []) {
|
||||
const scale = [1.0001 * width, 1.0001 * height, 1.0001 * depth] as const
|
||||
const geometry = new THREE.BoxGeometry(...scale)
|
||||
const lines = new LineSegmentsGeometry().fromEdgesGeometry(new THREE.EdgesGeometry(geometry))
|
||||
const inSelect = true
|
||||
this.lineMaterial ??= new LineMaterial({
|
||||
color: inSelect ? 0x40_80_ff : 0x00_00_00,
|
||||
linewidth: 8,
|
||||
dashed: true,
|
||||
dashSize: 5,
|
||||
})
|
||||
const wireframe = new Wireframe(lines, this.lineMaterial)
|
||||
const pos = blockPos.plus(position)
|
||||
wireframe.position.set(pos.x, pos.y, pos.z)
|
||||
wireframe.computeLineDistances()
|
||||
wireframe.scale.set(...scale)
|
||||
group.add(wireframe)
|
||||
}
|
||||
viewer.scene.add(group)
|
||||
|
|
@ -172,7 +177,8 @@ class WorldInteraction {
|
|||
|
||||
// todo this shouldnt be done in the render loop, migrate the code to dom events to avoid delays on lags
|
||||
update () {
|
||||
const cursorBlock = bot.blockAtCursor(5)
|
||||
const inSpectator = bot.game.gameMode === 'spectator'
|
||||
const cursorBlock = inSpectator && !options.showCursorBlockInSpectator ? null : bot.blockAtCursor(5)
|
||||
let cursorBlockDiggable = cursorBlock
|
||||
if (cursorBlock && !bot.canDigBlock(cursorBlock) && bot.game.gameMode !== 'creative') cursorBlockDiggable = null
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue