i would like to introduce you to saveShared

This commit is contained in:
DBotThePony 2023-05-30 09:50:23 +07:00
parent e82d7b74a7
commit e373512a61
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -14,6 +14,7 @@ import net.minecraft.world.level.storage.loot.Serializer
import net.minecraft.world.level.storage.loot.functions.LootItemFunction import net.minecraft.world.level.storage.loot.functions.LootItemFunction
import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType
import net.minecraft.world.level.storage.loot.parameters.LootContextParams import net.minecraft.world.level.storage.loot.parameters.LootContextParams
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity
import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.nbt.set
import ru.dbotthepony.mc.otm.core.set import ru.dbotthepony.mc.otm.core.set
import ru.dbotthepony.mc.otm.core.stream import ru.dbotthepony.mc.otm.core.stream
@ -34,7 +35,14 @@ class CopyTileNbtFunction(filter: Stream<out String> = Stream.empty()) : LootIte
val blockEntity = u.getParamOrNull(LootContextParams.BLOCK_ENTITY) ?: return t val blockEntity = u.getParamOrNull(LootContextParams.BLOCK_ENTITY) ?: return t
val result = t.tagNotNull[BlockItem.BLOCK_ENTITY_TAG] as? CompoundTag val result = t.tagNotNull[BlockItem.BLOCK_ENTITY_TAG] as? CompoundTag
val data = blockEntity.saveWithoutMetadata() val data: CompoundTag
if (blockEntity is MatteryBlockEntity) {
data = CompoundTag()
blockEntity.saveShared(data)
} else {
data = blockEntity.saveWithoutMetadata()
}
for (k in filter) { for (k in filter) {
data.remove(k) data.remove(k)