Update cargo crate block entity

This commit is contained in:
DBotThePony 2024-08-23 20:07:47 +07:00
parent d24cf38b17
commit 350c1cc0a9
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -3,10 +3,12 @@ package ru.dbotthepony.mc.otm.block.entity.decorative
import net.minecraft.advancements.CriteriaTriggers
import net.minecraft.core.BlockPos
import net.minecraft.core.HolderLookup
import net.minecraft.core.registries.Registries
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.LongTag
import net.minecraft.nbt.StringTag
import net.minecraft.network.chat.Component
import net.minecraft.resources.ResourceKey
import net.minecraft.resources.ResourceLocation
import net.minecraft.server.level.ServerLevel
import net.minecraft.server.level.ServerPlayer
@ -21,6 +23,7 @@ import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.gameevent.GameEvent
import net.minecraft.world.level.storage.loot.LootParams
import net.minecraft.world.level.storage.loot.LootTable
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets
import net.minecraft.world.level.storage.loot.parameters.LootContextParams
import net.minecraft.world.phys.Vec3
@ -62,7 +65,7 @@ class CargoCrateBlockEntity(
unpackLootTable(player)
}
var lootTable: ResourceLocation? = null
var lootTable: ResourceKey<LootTable>? = null
var lootTableSeed: Long? = null
fun onPlayerOpen() {
@ -97,7 +100,7 @@ class CargoCrateBlockEntity(
override fun loadAdditional(nbt: CompoundTag, registry: HolderLookup.Provider) {
super.loadAdditional(nbt, registry)
lootTable = nbt.map(LOOT_TABLE_KEY) { it: StringTag -> ResourceLocation.tryParse(it.asString) }
lootTable = nbt.map(LOOT_TABLE_KEY) { it: StringTag -> ResourceLocation.tryParse(it.asString)?.let { ResourceKey.create(Registries.LOOT_TABLE, it) } }
lootTableSeed = (nbt[LOOT_TABLE_SEED_KEY] as LongTag?)?.asLong
}
@ -106,7 +109,7 @@ class CargoCrateBlockEntity(
val lootTableSeed = lootTableSeed ?: 0L
val server = level?.server ?: return
val loot = server.loot.getLootTable(lootTable)
val loot = server.reloadableRegistries().getLootTable(lootTable)
if (ply is ServerPlayer) {
CriteriaTriggers.GENERATE_LOOT.trigger(ply, lootTable)