Fix #626 update item displays to 1.21.4

This commit is contained in:
Misode
2024-12-06 19:20:48 +01:00
parent c81bafd674
commit e844477c80
12 changed files with 89 additions and 83 deletions

View File

@@ -18,7 +18,7 @@ export const BlockStatePreview = ({ docAndNode, shown }: PreviewProps) => {
const { value: resources } = useAsync(async () => {
if (!shown) return AsyncCancel
const resources = await getResources(version)
const resources = await getResources(version, new Map())
const definition = BlockDefinition.fromJson(safeJsonParse(text) ?? {})
const wrapper = new ResourceWrapper(resources, {
getBlockDefinition(id) {

View File

@@ -315,11 +315,12 @@ export class Deepslate {
finalDensity: this.d.DensityFunction.fromJson(state),
}),
})
const levelHeight: deepslate19.LevelHeight = { minY: 0, height: 256 }
const unknownBiome = this.d.Identifier.create('unknown')
const randomState = new this.d.RandomState(settings, seed)
const biomeSource = new this.d.FixedBiomeSource(unknownBiome)
const chunkGenerator = new this.d.NoiseChunkGenerator(biomeSource, settings)
this.structureContextCache = { seed, settings, randomState, biomeSource, chunkGenerator }
this.structureContextCache = { seed, settings, randomState, biomeSource, chunkGenerator, levelHeight }
class SimpleStructure extends this.d.WorldgenStructure {
constructor(settings: deepslate19.WorldgenStructure.StructureSettings) {

View File

@@ -1,3 +1,4 @@
import type { ItemComponentsProvider } from 'deepslate'
import { NbtByte, NbtDouble, NbtLong } from 'deepslate'
import type { Random } from 'deepslate/core'
import { Identifier, ItemStack, LegacyRandom } from 'deepslate/core'
@@ -20,7 +21,7 @@ const StackMixers = {
type StackMixer = keyof typeof StackMixers
interface LootOptions {
interface LootOptions extends ItemComponentsProvider {
version: VersionId,
seed: bigint,
luck: number,
@@ -32,7 +33,6 @@ interface LootOptions {
getPredicate(id: string): any,
getEnchantments(): Map<string, any>,
getEnchantmentTag(id: string): string[],
getBaseComponents(id: string): Map<string, NbtTag>,
}
interface LootContext extends LootOptions {
@@ -235,12 +235,12 @@ function createItem(entry: any, consumer: ItemConsumer, ctx: LootContext) {
switch (type) {
case 'item':
const id = Identifier.parse(entry.name)
entryConsumer(new ResolvedItem(new ItemStack(id, 1), ctx.getBaseComponents(id.toString())))
entryConsumer(new ResolvedItem(new ItemStack(id, 1), ctx.getItemComponents(id)))
break
case 'tag':
ctx.getItemTag(entry.name).forEach(tagEntry => {
const id = Identifier.parse(tagEntry)
entryConsumer(new ResolvedItem(new ItemStack(id, 1), ctx.getBaseComponents(id.toString())))
entryConsumer(new ResolvedItem(new ItemStack(id, 1), ctx.getItemComponents(id)))
})
break
case 'loot_table':
@@ -303,7 +303,7 @@ const LootFunctions: Record<string, (params: any) => LootFunction> = {
const level = ctx.random.nextInt(maxLevel - 1) + 1
if (item.is('book')) {
item.id = Identifier.create('enchanted_book')
item.base = ctx.getBaseComponents(item.id.toString())
item.base = ctx.getItemComponents(item.id)
}
updateEnchantments(item, levels => {
return levels.set(Identifier.parse(pick).toString(), level)
@@ -314,7 +314,7 @@ const LootFunctions: Record<string, (params: any) => LootFunction> = {
const selected = selectEnchantments(item, computeInt(levels, ctx), allowed, ctx)
if (item.is('book')) {
item.id = Identifier.create('enchanted_book')
item.base = ctx.getBaseComponents(item.id.toString())
item.base = ctx.getItemComponents(item.id)
}
updateEnchantments(item, levelsMap => {
for (const { id, lvl } of selected) {
@@ -437,7 +437,7 @@ const LootFunctions: Record<string, (params: any) => LootFunction> = {
}
if (item.is('book')) {
item.id = Identifier.create('enchanted_book')
item.base = ctx.getBaseComponents(item.id.toString())
item.base = ctx.getItemComponents(item.id)
}
updateEnchantments(item, levels => {
Object.entries(enchantments).forEach(([id, level]) => {
@@ -463,7 +463,7 @@ const LootFunctions: Record<string, (params: any) => LootFunction> = {
set_item: ({ item: newId }) => (item, ctx) => {
if (typeof newId !== 'string') return
item.id = Identifier.parse(newId)
item.base = ctx.getBaseComponents(item.id.toString())
item.base = ctx.getItemComponents(item.id)
},
set_loot_table: ({ name, seed }) => (item) => {
item.set('container_loot', new NbtCompound()

View File

@@ -1,4 +1,3 @@
import { Identifier } from 'deepslate'
import { useMemo, useRef, useState } from 'preact/hooks'
import { useLocale, useVersion } from '../../contexts/index.js'
import { useAsync } from '../../hooks/useAsync.js'
@@ -58,7 +57,7 @@ export const LootTablePreview = ({ docAndNode }: PreviewProps) => {
getPredicate: () => undefined,
getEnchantments: () => enchantments ?? new Map(),
getEnchantmentTag: (id) => (enchantmentTags?.get(id.replace(/^minecraft:/, '')) as any)?.values ?? [],
getBaseComponents: (id) => new Map([...(itemComponents?.get(Identifier.parse(id).toString()) ?? new Map()).entries()].map(([k, v]) => [k, jsonToNbt(v)])),
getItemComponents: (id) => new Map([...(itemComponents?.get(id.toString()) ?? new Map()).entries()].map(([k, v]) => [k, jsonToNbt(v)])),
})
}, [version, seed, luck, daytime, weather, mixItems, text, dependencies, loading])

View File

@@ -19,7 +19,7 @@ export const ModelPreview = ({ docAndNode, shown }: PreviewProps) => {
const { value: resources } = useAsync(async () => {
if (!shown) return AsyncCancel
const resources = await getResources(version)
const resources = await getResources(version, new Map())
const blockModel = BlockModel.fromJson(safeJsonParse(text) ?? {})
blockModel.flatten(resources)
const wrapper = new ResourceWrapper(resources, {

View File

@@ -52,7 +52,7 @@ export const StructureSetPreview = ({ docAndNode, shown }: PreviewProps) => {
iterateWorld2D(imageData.current, transform, (x, y) => {
const pos = ChunkPos.create(x, y)
const structure = computeIfAbsent(chunkStructures, `${pos[0]} ${pos[1]}`, () => structureSet?.getStructureInChunk(pos[0], pos[1], context))
const structure = computeIfAbsent(chunkStructures, `${pos[0]} ${pos[1]}`, () => structureSet?.getStructureInChunk(pos[0], pos[1], context)?.id)
return { structure, pos }
}, ({ structure, pos }) => {
if (structure !== undefined) {