it compiles \o/

This commit is contained in:
granny
2025-06-01 17:27:04 -07:00
parent 503c6f4641
commit 9f6cbee8e0
16 changed files with 160 additions and 113 deletions

View File

@@ -1,23 +1,29 @@
package org.purpurmc.purpur.entity;
import com.mojang.logging.LogUtils;
import io.papermc.paper.adventure.PaperAdventure;
import net.kyori.adventure.text.Component;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.ProblemReporter;
import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.storage.TagValueInput;
import net.minecraft.world.level.storage.ValueInput;
import org.bukkit.block.EntityBlockStorage;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.entity.Bee;
import org.bukkit.entity.EntityType;
import org.bukkit.persistence.PersistentDataContainer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import java.util.Locale;
public class PurpurStoredBee implements StoredEntity<Bee> {
static final Logger LOGGER = LogUtils.getLogger();
private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
private final EntityBlockStorage<Bee> blockStorage;
@@ -26,16 +32,21 @@ public class PurpurStoredBee implements StoredEntity<Bee> {
private Component customName;
public PurpurStoredBee(BeehiveBlockEntity.BeeData data, EntityBlockStorage<Bee> blockStorage) {
public PurpurStoredBee(BeehiveBlockEntity.BeeData data, EntityBlockStorage<Bee> blockStorage, final BeehiveBlockEntity blockEntity) {
this.handle = data;
this.blockStorage = blockStorage;
CompoundTag customData = handle.occupant.entityData().copyTag();
net.minecraft.network.chat.Component customNameMinecraft = BlockEntity.parseCustomNameSafe(customData.get("CustomName"), ((CraftWorld) blockStorage.getWorld()).getHandle().registryAccess());
this.customName = customNameMinecraft == null ? null : PaperAdventure.asAdventure(customNameMinecraft);
if (customData.get("BukkitValues") instanceof CompoundTag compoundTag) {
this.persistentDataContainer.putAll(compoundTag);
try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(blockEntity.problemPath(), LOGGER)) {
ValueInput valueInput = TagValueInput.create(scopedCollector, blockEntity.getLevel().registryAccess(), customData);
net.minecraft.network.chat.Component customNameMinecraft = BlockEntity.parseCustomNameSafe(valueInput, "CustomName");
this.customName = customNameMinecraft == null ? null : PaperAdventure.asAdventure(customNameMinecraft);
if (customData.get("BukkitValues") instanceof CompoundTag compoundTag) {
this.persistentDataContainer.putAll(compoundTag);
}
}
}
@@ -98,7 +109,7 @@ public class PurpurStoredBee implements StoredEntity<Bee> {
if(customName == null) {
handle.occupant.entityData().copyTag().remove("CustomName");
} else {
handle.occupant.entityData().copyTag().putString("CustomName", net.minecraft.network.chat.Component.Serializer.toJson(PaperAdventure.asVanilla(customName), ((CraftWorld) blockStorage.getWorld()).getHandle().registryAccess()));
handle.occupant.entityData().copyTag().putString("CustomName", CraftChatMessage.toJSON(PaperAdventure.asVanilla(customName)));
}
}
}