fix recently introduced bug with crafting in singleplayer
This commit is contained in:
parent
00dd606091
commit
0d3a3affd7
8 changed files with 51 additions and 19 deletions
|
|
@ -118,7 +118,9 @@ const dataTypeBundling = {
|
|||
blockLoot: {
|
||||
arrKey: 'block'
|
||||
},
|
||||
recipes: {}, // todo we can do better
|
||||
recipes: {
|
||||
raw: true
|
||||
}, // todo we can do better
|
||||
blockCollisionShapes: {},
|
||||
loginPacket: {},
|
||||
protocol: {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const json = JSON.parse(fs.readFileSync('./generated/minecraft-data-optimized.js
|
|||
const dataPaths = require('minecraft-data/minecraft-data/data/dataPaths.json')
|
||||
|
||||
const validateData = (ver, type) => {
|
||||
const target = JsonOptimizer.restoreData(json[type], ver)
|
||||
const target = JsonOptimizer.restoreData(structuredClone(json[type]), ver)
|
||||
const arrKey = json[type].arrKey
|
||||
const originalPath = dataPaths.pc[ver][type]
|
||||
const original = require(`minecraft-data/minecraft-data/data/${originalPath}/${type}.json`)
|
||||
|
|
@ -43,16 +43,33 @@ const validateData = (ver, type) => {
|
|||
}
|
||||
}
|
||||
|
||||
const checkObj = (source, diffing) => {
|
||||
checkKeys(Object.keys(source), Object.keys(diffing))
|
||||
for (const [key, val] of Object.entries(source)) {
|
||||
if (JSON.stringify(val) !== JSON.stringify(diffing[key])) {
|
||||
throw new Error(`different value of ${key}: ${val} ${diffing[key]}`)
|
||||
}
|
||||
const sortObj = (obj) => {
|
||||
const sorted = {}
|
||||
for (const key of Object.keys(obj).sort()) {
|
||||
sorted[key] = obj[key]
|
||||
}
|
||||
return sorted
|
||||
}
|
||||
|
||||
const checkKeys = (source, diffing, isUniq = true, msg = '', redunantOk = false) => {
|
||||
const checkObj = (source, diffing) => {
|
||||
if (!Array.isArray(source)) {
|
||||
source = sortObj(source)
|
||||
}
|
||||
if (!Array.isArray(diffing)) {
|
||||
diffing = sortObj(diffing)
|
||||
}
|
||||
if (JSON.stringify(source) !== JSON.stringify(diffing)) {
|
||||
throw new Error(`different value: ${JSON.stringify(source)} ${JSON.stringify(diffing)}`)
|
||||
}
|
||||
// checkKeys(Object.keys(source), Object.keys(diffing))
|
||||
// for (const [key, val] of Object.entries(source)) {
|
||||
// if (JSON.stringify(val) !== JSON.stringify(diffing[key])) {
|
||||
// throw new Error(`different value of ${key}: ${val} ${diffing[key]}`)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
const checkKeys = (source, diffing, isUniq = true, msg = '', redundantIsOk = false) => {
|
||||
if (isUniq) {
|
||||
for (const [i, item] of diffing.entries()) {
|
||||
if (diffing.indexOf(item) !== i) {
|
||||
|
|
@ -65,7 +82,7 @@ const checkKeys = (source, diffing, isUniq = true, msg = '', redunantOk = false)
|
|||
throw new Error(`Diffing does not include "${key}" (${msg})`)
|
||||
}
|
||||
}
|
||||
if (!redunantOk) {
|
||||
if (!redundantIsOk) {
|
||||
for (const key of diffing) {
|
||||
if (!source.includes(key)) {
|
||||
throw new Error(`Source does not include "${key}" (${msg})`)
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 18 KiB |
|
|
@ -69,11 +69,12 @@ export const onGameLoad = (onLoad) => {
|
|||
}
|
||||
})
|
||||
|
||||
// workaround: singleplayer player inventory crafting
|
||||
bot.inventory.on('updateSlot', ((_oldSlot, oldItem, newItem) => {
|
||||
const oldSlot = _oldSlot as number
|
||||
const currentSlot = _oldSlot as number
|
||||
if (!miscUiState.singleplayer) return
|
||||
const { craftingResultSlot } = bot.inventory
|
||||
if (oldSlot === craftingResultSlot && oldItem && !newItem) {
|
||||
if (currentSlot === craftingResultSlot && oldItem && !newItem) {
|
||||
for (let i = 1; i < 5; i++) {
|
||||
const count = bot.inventory.slots[i]?.count
|
||||
if (count && count > 1) {
|
||||
|
|
@ -86,6 +87,7 @@ export const onGameLoad = (onLoad) => {
|
|||
}
|
||||
return
|
||||
}
|
||||
if (currentSlot > 4) return
|
||||
const craftingSlots = bot.inventory.slots.slice(1, 5)
|
||||
try {
|
||||
const resultingItem = getResultingRecipe(craftingSlots, 2)
|
||||
|
|
|
|||
|
|
@ -192,7 +192,12 @@ export default class JsonOptimizer {
|
|||
for (const [key, removePropsId] of removedProps) {
|
||||
for (const removePropId of removePropsId) {
|
||||
const removeProp = propertiesById[removePropId]
|
||||
delete dataByKeys[key][removeProp]
|
||||
// todo: this is not correct!
|
||||
if (Array.isArray(dataByKeys[key])) {
|
||||
dataByKeys[key].splice(removeProp, 1)
|
||||
} else {
|
||||
delete dataByKeys[key][removeProp]
|
||||
}
|
||||
}
|
||||
}
|
||||
if (versionToNumber(versionKey) <= versionToNumber(targetKey)) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useSnapshot } from 'valtio'
|
||||
import { miscUiState } from './globalState'
|
||||
import Input from './react/Input'
|
||||
import { miscUiState } from '../globalState'
|
||||
import Input from './Input'
|
||||
|
||||
function InnerSearch () {
|
||||
const { currentTouch } = useSnapshot(miscUiState)
|
||||
|
|
@ -19,7 +19,6 @@ function InnerSearch () {
|
|||
autoFocus={currentTouch === false}
|
||||
width={50}
|
||||
placeholder='Search...'
|
||||
defaultValue=""
|
||||
onChange={({ target: { value } }) => {
|
||||
customEvents.emit('search', value)
|
||||
}}
|
||||
|
|
@ -27,8 +27,16 @@ export default ({ autoFocus, rootStyles, inputRef, validateInput, ...inputProps
|
|||
|
||||
return <div id='input-container' className={styles.container} style={rootStyles}>
|
||||
<input
|
||||
ref={ref} className={styles.input} autoComplete='off' autoCapitalize='off' autoCorrect='off' autoSave='off' spellCheck='false'
|
||||
style={{ ...validationStyle }} {...inputProps} value={value}
|
||||
ref={ref}
|
||||
className={styles.input}
|
||||
autoComplete='off'
|
||||
autoCapitalize='off'
|
||||
autoCorrect='off'
|
||||
autoSave='off'
|
||||
spellCheck='false'
|
||||
style={{ ...validationStyle }}
|
||||
{...inputProps}
|
||||
value={value}
|
||||
onChange={(e) => {
|
||||
setValidationStyle(validateInput?.(e.target.value) ?? {})
|
||||
setValue(e.target.value)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import SoundMuffler from './react/SoundMuffler'
|
|||
import TouchControls from './react/TouchControls'
|
||||
import widgets from './react/widgets'
|
||||
import { useIsWidgetActive } from './react/utilsApp'
|
||||
import GlobalSearchInput from './GlobalSearchInput'
|
||||
import GlobalSearchInput from './react/GlobalSearchInput'
|
||||
import TouchAreasControlsProvider from './react/TouchAreasControlsProvider'
|
||||
import NotificationProvider, { showNotification } from './react/NotificationProvider'
|
||||
import HotbarRenderApp from './react/HotbarRenderApp'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue