diff --git a/common/src/main/java/top/r3944realms/lib39/Lib39.java b/common/src/main/java/top/r3944realms/lib39/Lib39.java index 13641a9..aedca1b 100644 --- a/common/src/main/java/top/r3944realms/lib39/Lib39.java +++ b/common/src/main/java/top/r3944realms/lib39/Lib39.java @@ -1,6 +1,6 @@ package top.r3944realms.lib39; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -48,8 +48,8 @@ public class Lib39 { * @return the resource location */ @Contract("_ -> new") - public static @NotNull ResourceLocation rl(String path) { - return ResourceLocation.fromNamespaceAndPath(Lib39.MOD_ID, path); + public static @NotNull Identifier rl(String path) { + return Identifier.fromNamespaceAndPath(Lib39.MOD_ID, path); } /** @@ -60,8 +60,8 @@ public class Lib39 { * @return the resource location */ @Contract("_, _ -> new") - public static @NotNull ResourceLocation rl(String modId, String path) { - return ResourceLocation.fromNamespaceAndPath(modId, path); + public static @NotNull Identifier rl(String modId, String path) { + return Identifier.fromNamespaceAndPath(modId, path); } /** @@ -71,8 +71,8 @@ public class Lib39 { * @return the resource location */ @Contract("_ -> new") - public static @NotNull ResourceLocation mrl(String path) { - return ResourceLocation.withDefaultNamespace(path); + public static @NotNull Identifier mrl(String path) { + return Identifier.withDefaultNamespace(path); } /** diff --git a/common/src/main/java/top/r3944realms/lib39/base/command/Lib39CommandHelpManager.java b/common/src/main/java/top/r3944realms/lib39/base/command/Lib39CommandHelpManager.java index 9474c90..0d18b43 100644 --- a/common/src/main/java/top/r3944realms/lib39/base/command/Lib39CommandHelpManager.java +++ b/common/src/main/java/top/r3944realms/lib39/base/command/Lib39CommandHelpManager.java @@ -1,6 +1,6 @@ package top.r3944realms.lib39.base.command; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import top.r3944realms.lib39.Lib39; import top.r3944realms.lib39.core.command.SimpleCommandHelpManager; @@ -18,7 +18,7 @@ public class Lib39CommandHelpManager extends SimpleCommandHelpManager { /** * 作为唯一标识符 */ - ResourceLocation ID = Lib39.rl("command_helper"); + Identifier ID = Lib39.rl("command_helper"); /** *
@@ -31,7 +31,7 @@ public class Lib39CommandHelpManager extends SimpleCommandHelpManager {
}
@Override
- public ResourceLocation getID() {
+ public Identifier getID() {
return ID;
}
diff --git a/common/src/main/java/top/r3944realms/lib39/base/command/Lib39HelpCommand.java b/common/src/main/java/top/r3944realms/lib39/base/command/Lib39HelpCommand.java
index 9cea4f9..c77e945 100644
--- a/common/src/main/java/top/r3944realms/lib39/base/command/Lib39HelpCommand.java
+++ b/common/src/main/java/top/r3944realms/lib39/base/command/Lib39HelpCommand.java
@@ -11,7 +11,7 @@ import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.network.chat.Component;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerPlayer;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.Lib39;
@@ -19,6 +19,7 @@ import top.r3944realms.lib39.core.command.ICommandHelpManager;
import top.r3944realms.lib39.core.command.SimpleHelpCommand;
import java.util.Map;
+import java.util.Set;
/**
*
@@ -92,7 +93,7 @@ public class Lib39HelpCommand extends SimpleHelpCommand {
.executes(this::executeCalculate)))
)
.then(Commands.literal("teleport")
- .requires(source -> source.hasPermission(2)) // 需要OP權限
+ .requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)) // 需要游戏管理员權限
.then(Commands.argument("target", EntityArgument.player())
.executes(this::executeTeleport))
)
@@ -284,12 +285,14 @@ public class Lib39HelpCommand extends SimpleHelpCommand {
if (source.getEntity() instanceof ServerPlayer player) {
player.teleportTo(
- target.serverLevel(),
+ target.level(),
target.getX(),
target.getY(),
target.getZ(),
+ Set.of(),
target.getYRot(),
- target.getXRot()
+ target.getXRot(),
+ true
);
source.sendSuccess(() ->
@@ -304,7 +307,7 @@ public class Lib39HelpCommand extends SimpleHelpCommand {
private int executeInfo(CommandContext context) {
CommandSourceStack source = context.getSource();
- ResourceLocation dimension = source.getLevel().dimension().location();
+ Identifier dimension = source.getLevel().dimension().identifier();
source.sendSuccess(() ->
Component.translatable("commands.lib39.info.message")
diff --git a/common/src/main/java/top/r3944realms/lib39/base/datagen/provider/Lib39RecipeProvider.java b/common/src/main/java/top/r3944realms/lib39/base/datagen/provider/Lib39RecipeProvider.java
index a55a507..ba711d1 100644
--- a/common/src/main/java/top/r3944realms/lib39/base/datagen/provider/Lib39RecipeProvider.java
+++ b/common/src/main/java/top/r3944realms/lib39/base/datagen/provider/Lib39RecipeProvider.java
@@ -19,16 +19,16 @@ public class Lib39RecipeProvider extends RecipeProvider {
* @param output the output
* @param registries the registries
*/
- public Lib39RecipeProvider(PackOutput output, CompletableFuture registries) {
- super(output, registries);
+ public Lib39RecipeProvider(HolderLookup.Provider output, RecipeOutput recipeOutput) {
+ super(output, recipeOutput);
}
@Override
- public void buildRecipes(RecipeOutput recipeOutput) {
- ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, Lib39Items.DOLL.get())
+ protected void buildRecipes() {
+ this.shapeless(RecipeCategory.MISC, Lib39Items.DOLL.get())
.requires(ItemTags.WOOL)
.requires(Items.ARMOR_STAND)
.unlockedBy("has_armor_stand",has(Items.ARMOR_STAND))
- .save(recipeOutput);
+ .save(this.output);
}
}
diff --git a/common/src/main/java/top/r3944realms/lib39/client/gui/component/WheelWidget.java b/common/src/main/java/top/r3944realms/lib39/client/gui/component/WheelWidget.java
index f33acb9..abe6558 100644
--- a/common/src/main/java/top/r3944realms/lib39/client/gui/component/WheelWidget.java
+++ b/common/src/main/java/top/r3944realms/lib39/client/gui/component/WheelWidget.java
@@ -3,7 +3,6 @@ package top.r3944realms.lib39.client.gui.component;
import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
-import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;
@@ -12,6 +11,7 @@ import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.network.chat.Component;
import org.joml.Matrix4f;
import org.joml.Vector2f;
+import org.jspecify.annotations.NonNull;
import top.r3944realms.lib39.client.shader.Lib39Shaders;
import top.r3944realms.lib39.util.MathUtil;
import top.r3944realms.lib39.util.lang.FourConsumer;
@@ -681,7 +681,7 @@ public class WheelWidget extends AbstractWidget {
* @param radius the radius
*/
public static void renderSelectionEffect(
- GuiGraphics guiGraphics,
+ @NonNull GuiGraphics guiGraphics,
float centerX,
float centerY,
int color,
diff --git a/common/src/main/java/top/r3944realms/lib39/client/model/DollPoses.java b/common/src/main/java/top/r3944realms/lib39/client/model/DollPoses.java
index 98b2eeb..6856862 100644
--- a/common/src/main/java/top/r3944realms/lib39/client/model/DollPoses.java
+++ b/common/src/main/java/top/r3944realms/lib39/client/model/DollPoses.java
@@ -1,7 +1,7 @@
package top.r3944realms.lib39.client.model;
import net.minecraft.client.model.geom.PartPose;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.Lib39;
@@ -23,7 +23,7 @@ public enum DollPoses implements IDollPose{
PartPose.offsetAndRotation(2.0F, 19.0F, -2.0F, -1.5708F, -0.3927F, 0.0F)
);
// 注册全局?
- private final ResourceLocation id;
+ private final Identifier id;
private final Vec3 offset;
private final PartPose headPose;
private final PartPose bodyPose;
@@ -52,7 +52,7 @@ public enum DollPoses implements IDollPose{
}
@Override
- public @NotNull ResourceLocation getId() {
+ public @NotNull Identifier getId() {
return id;
}
diff --git a/common/src/main/java/top/r3944realms/lib39/client/model/IDollPose.java b/common/src/main/java/top/r3944realms/lib39/client/model/IDollPose.java
index dfaf12a..f3be245 100644
--- a/common/src/main/java/top/r3944realms/lib39/client/model/IDollPose.java
+++ b/common/src/main/java/top/r3944realms/lib39/client/model/IDollPose.java
@@ -1,7 +1,7 @@
package top.r3944realms.lib39.client.model;
import net.minecraft.client.model.geom.PartPose;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
@@ -14,7 +14,7 @@ public interface IDollPose {
*
* @return the id
*/
- @NotNull ResourceLocation getId();
+ @NotNull Identifier getId();
/**
* Gets total offset.
diff --git a/common/src/main/java/top/r3944realms/lib39/client/renderer/block/DollBlockEntityRenderer.java b/common/src/main/java/top/r3944realms/lib39/client/renderer/block/DollBlockEntityRenderer.java
index 78cae75..79ee0bf 100644
--- a/common/src/main/java/top/r3944realms/lib39/client/renderer/block/DollBlockEntityRenderer.java
+++ b/common/src/main/java/top/r3944realms/lib39/client/renderer/block/DollBlockEntityRenderer.java
@@ -14,7 +14,7 @@ import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.client.resources.PlayerSkin;
import net.minecraft.client.resources.SkinManager;
import net.minecraft.core.Direction;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.item.component.ResolvableProfile;
import net.minecraft.world.level.block.SkullBlock;
import net.minecraft.world.level.block.WallSkullBlock;
diff --git a/common/src/main/java/top/r3944realms/lib39/client/renderer/item/DollItemRenderer.java b/common/src/main/java/top/r3944realms/lib39/client/renderer/item/DollItemRenderer.java
index ee3c9a8..27c3503 100644
--- a/common/src/main/java/top/r3944realms/lib39/client/renderer/item/DollItemRenderer.java
+++ b/common/src/main/java/top/r3944realms/lib39/client/renderer/item/DollItemRenderer.java
@@ -12,7 +12,7 @@ import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.client.resources.PlayerSkin;
import net.minecraft.client.resources.SkinManager;
import net.minecraft.core.component.DataComponents;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ResolvableProfile;
@@ -75,7 +75,7 @@ public class DollItemRenderer extends BlockEntityWithoutLevelRenderer {
// 直接从 DataComponents.PROFILE 获取 ResolvableProfile
ResolvableProfile profile = stack.get(DataComponents.PROFILE);
- Pair skinInfo = getSkinInfo(profile);
+ Pair skinInfo = getSkinInfo(profile);
poseStack.pushPose();
VertexConsumer vertexConsumer = buffer.getBuffer(RenderType.entityTranslucent(skinInfo.first));
@@ -93,7 +93,7 @@ public class DollItemRenderer extends BlockEntityWithoutLevelRenderer {
/**
* 获取皮肤纹理和模型类型(1.21+ 版本)
*/
- public static @NotNull Pair getSkinInfo(@NotNull ResolvableProfile profile) {
+ public static @NotNull Pair getSkinInfo(@NotNull ResolvableProfile profile) {
SkinManager skinManager = Minecraft.getInstance().getSkinManager();
if (profile != null && profile.gameProfile() != null) {
diff --git a/common/src/main/java/top/r3944realms/lib39/core/command/ICommandHelpManager.java b/common/src/main/java/top/r3944realms/lib39/core/command/ICommandHelpManager.java
index 7c6b1de..41d2ea1 100644
--- a/common/src/main/java/top/r3944realms/lib39/core/command/ICommandHelpManager.java
+++ b/common/src/main/java/top/r3944realms/lib39/core/command/ICommandHelpManager.java
@@ -3,7 +3,7 @@ package top.r3944realms.lib39.core.command;
import net.minecraft.ChatFormatting;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.*;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.r3944realms.lib39.base.datagen.value.Lib39LangKey;
@@ -31,7 +31,7 @@ public interface ICommandHelpManager {
*
* @return the id
*/
- ResourceLocation getID();
+ Identifier getID();
/**
* Gets head key.
diff --git a/common/src/main/java/top/r3944realms/lib39/core/command/SimpleCommandHelpManager.java b/common/src/main/java/top/r3944realms/lib39/core/command/SimpleCommandHelpManager.java
index bd0fd05..f1a29fe 100644
--- a/common/src/main/java/top/r3944realms/lib39/core/command/SimpleCommandHelpManager.java
+++ b/common/src/main/java/top/r3944realms/lib39/core/command/SimpleCommandHelpManager.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.command;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.core.command.model.CommandNode;
import top.r3944realms.lib39.core.command.model.Parameter;
@@ -28,7 +28,7 @@ public abstract class SimpleCommandHelpManager implements ICommandHelpManager {
public void initialize() {
if (root == null) {
// 現在子類的字段已經初始化完成
- ResourceLocation id = getID();
+ Identifier id = getID();
if (id == null) {
throw new IllegalStateException("getID() must return non-null");
}
diff --git a/common/src/main/java/top/r3944realms/lib39/core/compat/CompatManager.java b/common/src/main/java/top/r3944realms/lib39/core/compat/CompatManager.java
index 12e9129..cbbe27a 100644
--- a/common/src/main/java/top/r3944realms/lib39/core/compat/CompatManager.java
+++ b/common/src/main/java/top/r3944realms/lib39/core/compat/CompatManager.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.compat;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -22,7 +22,7 @@ public abstract class CompatManager implements ICompatManager
* @return the id
*/
@Override
- public ResourceLocation getId() {
+ public Identifier getId() {
return id;
}
@@ -33,7 +33,7 @@ public abstract class CompatManager implements ICompatManager
/**
* The Id.
*/
- protected final ResourceLocation id;
+ protected final Identifier id;
/**
* The Initialized.
@@ -58,7 +58,7 @@ public abstract class CompatManager implements ICompatManager
*
* @param id the id
*/
- public CompatManager(@NotNull ResourceLocation id) {
+ public CompatManager(@NotNull Identifier id) {
this.id = id;
this.logger = LoggerFactory.getLogger(id.toString());
}
@@ -70,7 +70,7 @@ public abstract class CompatManager implements ICompatManager
* @param compat the compat
*/
@Override
- public void registerCompat(ResourceLocation id, C compat) {
+ public void registerCompat(Identifier id, C compat) {
if (initialized) {
// 已初始化,直接注册
doRegisterCompat(id, compat);
@@ -87,7 +87,7 @@ public abstract class CompatManager implements ICompatManager
* @param id the id
* @param compat the compat
*/
- protected void doRegisterCompat(ResourceLocation id, C compat) {
+ protected void doRegisterCompat(Identifier id, C compat) {
if (getCompatMap().containsKey(id)) {
logger.warn("Compat with id {} is already registered!", id);
return;
@@ -122,7 +122,7 @@ public abstract class CompatManager implements ICompatManager
pendingTasks.clear();
// 初始化所有兼容模块
- for (Map.Entry entry : getCompatMap().entrySet()) {
+ for (Map.Entry entry : getCompatMap().entrySet()) {
if (!entry.getValue().isInitialized() && entry.getValue().isModLoaded()) {
try {
entry.getValue().initialize();
@@ -143,7 +143,7 @@ public abstract class CompatManager implements ICompatManager
* @return the compat
*/
@Override
- public Optional getCompat(ResourceLocation id) {
+ public Optional getCompat(Identifier id) {
return Optional.ofNullable(getCompatMap().get(id));
}
@@ -154,7 +154,7 @@ public abstract class CompatManager implements ICompatManager
* @return the boolean
*/
@Override
- public boolean hasCompat(ResourceLocation id) {
+ public boolean hasCompat(Identifier id) {
return getCompatMap().containsKey(id);
}
@@ -164,7 +164,7 @@ public abstract class CompatManager implements ICompatManager
* @param id the id
*/
@Override
- public void unregisterCompat(ResourceLocation id) {
+ public void unregisterCompat(Identifier id) {
C removed = getCompatMap().remove(id);
if (removed != null) {
logger.debug("Unregistered compat: {}", id);
@@ -187,7 +187,7 @@ public abstract class CompatManager implements ICompatManager
*/
public void onLoadComplete() {
logger.info("Calling onLoadComplete for {} compatibility modules", getCompatMap().size());
- for (Map.Entry entry : getCompatMap().entrySet()) {
+ for (Map.Entry entry : getCompatMap().entrySet()) {
try {
entry.getValue().onLoadComplete();
} catch (Exception e) {
diff --git a/common/src/main/java/top/r3944realms/lib39/core/compat/ICompat.java b/common/src/main/java/top/r3944realms/lib39/core/compat/ICompat.java
index bf8d344..d54f294 100644
--- a/common/src/main/java/top/r3944realms/lib39/core/compat/ICompat.java
+++ b/common/src/main/java/top/r3944realms/lib39/core/compat/ICompat.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.compat;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import java.util.concurrent.Callable;
@@ -27,7 +27,7 @@ public interface ICompat {
*
* @return the resource location
*/
- ResourceLocation id();
+ Identifier id();
/**
* Initialize.
diff --git a/common/src/main/java/top/r3944realms/lib39/core/compat/ICompatManager.java b/common/src/main/java/top/r3944realms/lib39/core/compat/ICompatManager.java
index f4ce505..ca8e322 100644
--- a/common/src/main/java/top/r3944realms/lib39/core/compat/ICompatManager.java
+++ b/common/src/main/java/top/r3944realms/lib39/core/compat/ICompatManager.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.compat;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import java.util.Map;
import java.util.Optional;
@@ -16,14 +16,14 @@ public interface ICompatManager {
*
* @return the id
*/
- ResourceLocation getId();
+ Identifier getId();
/**
* Gets compat map.
*
* @return the compat map
*/
- Map getCompatMap();
+ Map getCompatMap();
/**
* Initialize.
@@ -36,7 +36,7 @@ public interface ICompatManager {
* @param id the id
* @param compat the compat
*/
- void registerCompat(ResourceLocation id, C compat);
+ void registerCompat(Identifier id, C compat);
/**
* Register compat.
@@ -53,7 +53,7 @@ public interface ICompatManager {
* @param id the id
* @return the compat
*/
- Optional getCompat(ResourceLocation id);
+ Optional getCompat(Identifier id);
/**
* Has compat boolean.
@@ -61,12 +61,12 @@ public interface ICompatManager {
* @param id the id
* @return the boolean
*/
- boolean hasCompat(ResourceLocation id);
+ boolean hasCompat(Identifier id);
/**
* Unregister compat.
*
* @param id the id
*/
- void unregisterCompat(ResourceLocation id);
+ void unregisterCompat(Identifier id);
}
diff --git a/common/src/main/java/top/r3944realms/lib39/core/compat/SimpleCompatManager.java b/common/src/main/java/top/r3944realms/lib39/core/compat/SimpleCompatManager.java
index ea97988..6e1dd30 100644
--- a/common/src/main/java/top/r3944realms/lib39/core/compat/SimpleCompatManager.java
+++ b/common/src/main/java/top/r3944realms/lib39/core/compat/SimpleCompatManager.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.compat;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
@@ -13,19 +13,19 @@ public class SimpleCompatManager extends CompatManager {
/**
* The Compats.
*/
- Map compats = new HashMap<>();
+ Map compats = new HashMap<>();
/**
* Instantiates a new Compat manager.
*
* @param id the id
*/
- public SimpleCompatManager(@NotNull ResourceLocation id) {
+ public SimpleCompatManager(@NotNull Identifier id) {
super(id);
}
@Override
- public Map getCompatMap() {
+ public Map getCompatMap() {
return compats;
}
}
diff --git a/common/src/main/java/top/r3944realms/lib39/core/register/Lib39SoundEvents.java b/common/src/main/java/top/r3944realms/lib39/core/register/Lib39SoundEvents.java
index 9116dbe..80bbe7e 100644
--- a/common/src/main/java/top/r3944realms/lib39/core/register/Lib39SoundEvents.java
+++ b/common/src/main/java/top/r3944realms/lib39/core/register/Lib39SoundEvents.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.register;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.sounds.SoundEvent;
import top.r3944realms.lib39.Lib39;
@@ -13,7 +13,7 @@ public class Lib39SoundEvents {
/**
* The constant RL_DUCK_TOY.
*/
- public static final ResourceLocation RL_DUCK_TOY = Lib39.rl("duck_toy");
+ public static final Identifier RL_DUCK_TOY = Lib39.rl("duck_toy");
/**
* The constant DUCK_TOY.
*/
diff --git a/common/src/main/java/top/r3944realms/lib39/core/sync/ISyncData.java b/common/src/main/java/top/r3944realms/lib39/core/sync/ISyncData.java
index 30f82b5..c0ad8de 100644
--- a/common/src/main/java/top/r3944realms/lib39/core/sync/ISyncData.java
+++ b/common/src/main/java/top/r3944realms/lib39/core/sync/ISyncData.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.sync;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
/**
* The interface Sync data.
@@ -13,7 +13,7 @@ public interface ISyncData {
*
* @return the resource location
*/
- ResourceLocation id();
+ Identifier id();
/**
* Is dirty boolean.
diff --git a/common/src/main/java/top/r3944realms/lib39/core/sync/NBTEntitySyncData.java b/common/src/main/java/top/r3944realms/lib39/core/sync/NBTEntitySyncData.java
index 4d7f29f..922cefc 100644
--- a/common/src/main/java/top/r3944realms/lib39/core/sync/NBTEntitySyncData.java
+++ b/common/src/main/java/top/r3944realms/lib39/core/sync/NBTEntitySyncData.java
@@ -1,7 +1,7 @@
package top.r3944realms.lib39.core.sync;
import net.minecraft.nbt.CompoundTag;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
/**
@@ -15,19 +15,19 @@ public abstract class NBTEntitySyncData implements IEntity, ISyncData getTypedEntries();
+ protected abstract Map getTypedEntries();
/**
* 数据提供者接口 - 用于通过键获取数据
@@ -86,11 +86,11 @@ public abstract class SyncData2Manager> void registerManagerWithProvider(
- ResourceLocation key,
+ Identifier key,
ISyncManager manager,
DataProvider dataProvider
) {
- Objects.requireNonNull(key, "ResourceLocation key cannot be null");
+ Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(manager, "Sync manager cannot be null");
Objects.requireNonNull(dataProvider, "Data provider cannot be null");
@@ -108,11 +108,11 @@ public abstract class SyncData2Manager> void registerManager(
- ResourceLocation key,
+ Identifier key,
ISyncManager manager,
Function> getter
) {
- Objects.requireNonNull(key, "ResourceLocation key cannot be null");
+ Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(manager, "Sync manager cannot be null");
Objects.requireNonNull(getter, "Data getter function cannot be null");
@@ -126,8 +126,8 @@ public abstract class SyncData2Manager> manager) {
- Objects.requireNonNull(key, "ResourceLocation key cannot be null");
+ public void registerManager(Identifier key, ISyncManager, ? extends ISyncData>> manager) {
+ Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(manager, "Sync manager cannot be null");
// 创建一个没有数据提供者的 TypedSyncEntry
@@ -146,7 +146,7 @@ public abstract class SyncData2Manager> Optional> getManager(ResourceLocation key) {
+ public > Optional> getManager(Identifier key) {
TypedSyncEntry,?> entry = getTypedEntries().get(key);
return entry != null ? Optional.of((ISyncManager) entry.manager) : Optional.empty();
}
@@ -159,7 +159,7 @@ public abstract class SyncData2Manager> Optional> getDataProvider(ResourceLocation key) {
+ public > Optional> getDataProvider(Identifier key) {
TypedSyncEntry, ?> entry = getTypedEntries().get(key);
if (entry != null && entry.dataProvider != null) {
return Optional.of((DataProvider) entry.dataProvider);
@@ -176,7 +176,7 @@ public abstract class SyncData2Manager> Optional getEntityData(ResourceLocation key, Entity entity) {
+ public > Optional getEntityData(Identifier key, Entity entity) {
return getDataProvider(key)
.flatMap(provider -> {
Optional> result = provider.getData(entity);
@@ -190,8 +190,8 @@ public abstract class SyncData2Manager... classes) {
- Objects.requireNonNull(key, "ResourceLocation key cannot be null");
+ public final void allowEntityClass(Identifier key, Class>... classes) {
+ Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(classes, "Classes array cannot be null");
if (classes.length == 0) {
@@ -210,8 +210,8 @@ public abstract class SyncData2Manager... classes) {
- Objects.requireNonNull(key, "ResourceLocation key cannot be null");
+ public final void disallowEntityClass(Identifier key, Class>... classes) {
+ Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(classes, "Classes array cannot be null");
TypedSyncEntry, ?> entry = getTypedEntries().get(key);
@@ -227,8 +227,8 @@ public abstract class SyncData2Manager> void bindDataProvider(ResourceLocation key, DataProvider dataProvider) {
- Objects.requireNonNull(key, "ResourceLocation key cannot be null");
+ public > void bindDataProvider(Identifier key, DataProvider dataProvider) {
+ Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(dataProvider, "Data provider cannot be null");
TypedSyncEntry, ?> entry = getTypedEntries().get(key);
@@ -247,7 +247,7 @@ public abstract class SyncData2Manager> void bindDataGetter(ResourceLocation key, @NotNull Function> getter) {
+ public > void bindDataGetter(Identifier key, @NotNull Function> getter) {
bindDataProvider(key, getter::apply);
}
@@ -256,8 +256,8 @@ public abstract class SyncData2Manager entry = getTypedEntries().get(key);
if (entry != null) {
@@ -271,8 +271,8 @@ public abstract class SyncData2Manager entry = getTypedEntries().get(key);
if (entry != null) {
@@ -287,8 +287,8 @@ public abstract class SyncData2Manager entityClass) {
- Objects.requireNonNull(key, "ResourceLocation key cannot be null");
+ public boolean isEntityClassAllowed(Identifier key, Class> entityClass) {
+ Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(entityClass, "Entity class cannot be null");
TypedSyncEntry, ?> entry = getTypedEntries().get(key);
@@ -311,7 +311,7 @@ public abstract class SyncData2Manager entry = (TypedSyncEntry) getTypedEntries().get(managerId);
if (entry != null) {
trackEntityWithTypedEntry(entity, entry);
@@ -332,7 +332,7 @@ public abstract class SyncData2Manager entry = (TypedSyncEntry) getTypedEntries().get(managerId);
if (entry != null) {
untrackEntityWithTypedEntry(entity, entry);
@@ -352,7 +352,7 @@ public abstract class SyncData2Manager entities, ResourceLocation managerId) {
+ public void untrackEntitiesForManager(@NotNull Iterable entities, Identifier managerId) {
for (Entity entity : entities) {
untrackEntityForManager(entity, managerId);
}
@@ -387,7 +387,7 @@ public abstract class SyncData2Manager entry = getTypedEntries().get(managerId);
if (entry != null) {
clearTrackedDataForEntry(entry);
@@ -405,7 +405,7 @@ public abstract class SyncData2Manager> void updateDataProviderInEntry(
- ResourceLocation id,
+ Identifier id,
TypedSyncEntry,?> entry,
DataProvider newDataProvider
) {
@@ -441,7 +441,7 @@ public abstract class SyncData2Manager getRegisteredKeys() {
+ public Set getRegisteredKeys() {
return Collections.unmodifiableSet(getTypedEntries().keySet());
}
@@ -450,7 +450,7 @@ public abstract class SyncData2Manager> consumer) {
+ public void forEach(BiConsumer> consumer) {
Objects.requireNonNull(consumer, "Consumer cannot be null");
getTypedEntries().forEach((key, entry) -> consumer.accept(key, entry.manager));
}
@@ -476,8 +476,8 @@ public abstract class SyncData2Manager gameProfileAtomicReference = new AtomicReference<>();
- NBTReader.of(compound).gameProfile("profile", gameProfileAtomicReference::set);
- if (gameProfileAtomicReference.get() != null) {
- GameProfileHelper.saveProfileToItemStack(stack, new ResolvableProfile(gameProfileAtomicReference.get()));
+ private static ItemStack modifyRenderStack(ItemStack renderStack, @Local(argsOnly = true) Player player) {
+ if (renderStack.getItem() instanceof DollItem) {
+ CarryOnData carry = CarryOnDataManager.getCarryData(player);
+ if (carry != null) {
+ var compound = carry.getNbt().getCompound("tile");
+ var profileHolder = new AtomicReference();
+ NBTReader.ofOpt(compound).gameProfile("profile", profileHolder::set);
+ if (profileHolder.get() != null) {
+ GameProfileHelper.saveProfileToItemStack(renderStack, new ResolvableProfile(profileHolder.get()));
+ }
}
}
- return stack;
- }
- @ModifyVariable(
- method = "drawThirdPerson",
- at = @At(
- value = "LOAD",
- target = "Ltschipp/carryon/client/render/CarryRenderHelper;renderBakedModel(Lnet/minecraft/world/item/ItemStack;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/resources/model/BakedModel;)V"
- )
- )
- private static ItemStack warpDollItem$2(ItemStack tileItem, @Local(ordinal = 0) Player player) {
- if (tileItem.getItem() instanceof DollItem) {
- CompoundTag compound = CarryOnDataManager.getCarryData(player).getNbt().getCompound("tile");
- AtomicReference gameProfileAtomicReference = new AtomicReference<>();
- NBTReader.of(compound).gameProfile("profile", gameProfileAtomicReference::set);
- if (gameProfileAtomicReference.get() != null) {
- GameProfileHelper.saveProfileToItemStack(tileItem, new ResolvableProfile(gameProfileAtomicReference.get()));
- }
- }
- return tileItem;
+ return renderStack;
}
}
diff --git a/common/src/main/java/top/r3944realms/lib39/util/GameProfileHelper.java b/common/src/main/java/top/r3944realms/lib39/util/GameProfileHelper.java
index 6eb2c20..2717706 100644
--- a/common/src/main/java/top/r3944realms/lib39/util/GameProfileHelper.java
+++ b/common/src/main/java/top/r3944realms/lib39/util/GameProfileHelper.java
@@ -7,12 +7,8 @@ import com.mojang.authlib.properties.Property;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.client.player.AbstractClientPlayer;
-import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.core.component.DataComponents;
-import net.minecraft.nbt.CompoundTag;
-import net.minecraft.nbt.NbtUtils;
-import net.minecraft.resources.ResourceLocation;
-import net.minecraft.server.Services;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ResolvableProfile;
@@ -20,33 +16,28 @@ import net.minecraft.world.level.block.entity.SkullBlockEntity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.r3944realms.lib39.Lib39;
-import top.r3944realms.lib39.util.nbt.NBTReader;
-import top.r3944realms.lib39.util.nbt.NBTWriter;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Executor;
-import java.util.concurrent.atomic.AtomicReference;
/**
* The type GameProfile helper.
*/
public class GameProfileHelper {
/**
- * 异步获取 GameProfile(通过玩家名)
- * 直接复用 SkullBlockEntity 的实现
+ * 获取 GameProfile(通过玩家名)
*/
- public static CompletableFuture> fetchGameProfileByName(String name) {
- return SkullBlockEntity.fetchGameProfile(name);
+ public static ResolvableProfile fetchGameProfileByName(String name) {
+ return ResolvableProfile.createUnresolved(name);
}
/**
- * 异步获取 GameProfile(通过 UUID)
+ * 获取 GameProfile(通过 UUID)
* 直接复用 SkullBlockEntity 的实现
*/
- public static CompletableFuture> fetchGameProfileByUUID(UUID uuid) {
- return SkullBlockEntity.fetchGameProfile(uuid);
+ public static ResolvableProfile fetchGameProfileByUUID(UUID uuid) {
+ return ResolvableProfile.createUnresolved(uuid);
}
/**
@@ -93,7 +84,7 @@ public class GameProfileHelper {
* @param gameProfile the game profile
* @return the resource location
*/
- public static @NotNull ResourceLocation resolveSkinTexture(@NotNull GameProfile gameProfile) {
+ public static @NotNull Identifier resolveSkinTexture(@NotNull GameProfile gameProfile) {
return IClientOnly.check(() ->
Minecraft.getInstance().getSkinManager()
.getInsecureSkin(gameProfile)).texture();
@@ -105,7 +96,7 @@ public class GameProfileHelper {
* @param gameProfile the game profile
* @return the skin texture
*/
- public static ResourceLocation getSkinTexture(@Nullable GameProfile gameProfile) {
+ public static Identifier getSkinTexture(@Nullable GameProfile gameProfile) {
return IClientOnly.check(() -> {
if (gameProfile == null) {
return Lib39.mrl("textures/entity/player/wide/steve.png");
@@ -162,7 +153,7 @@ public class GameProfileHelper {
* @param gameProfile the game profile
* @return the skin texture
*/
- public static ResourceLocation getSkinTexture(@Nullable GameProfile gameProfile) {
+ public static Identifier getSkinTexture(@Nullable GameProfile gameProfile) {
return ClientOpt.getSkinTexture(gameProfile);
}
@@ -173,7 +164,7 @@ public class GameProfileHelper {
* @param gameProfile the game profile
* @return the resource location
*/
- public static @NotNull ResourceLocation resolveSkinTexture(@NotNull GameProfile gameProfile) {
+ public static @NotNull Identifier resolveSkinTexture(@NotNull GameProfile gameProfile) {
return ClientOpt.resolveSkinTexture(gameProfile);
}
diff --git a/common/src/main/java/top/r3944realms/lib39/util/MathUtil.java b/common/src/main/java/top/r3944realms/lib39/util/MathUtil.java
index 35a5580..f584729 100644
--- a/common/src/main/java/top/r3944realms/lib39/util/MathUtil.java
+++ b/common/src/main/java/top/r3944realms/lib39/util/MathUtil.java
@@ -145,7 +145,10 @@ public class MathUtil {
* @return the direction
*/
public static Direction getDirection(BlockPos from, BlockPos to) {
- return Direction.fromDelta(from.getX() - to.getX(), from.getY() - to.getY(), from.getZ() - to.getZ());
+ int dx = from.getX() - to.getX();
+ int dy = from.getY() - to.getY();
+ int dz = from.getZ() - to.getZ();
+ return Direction.getNearest(dx, dy, dz, null);
}
private static final Int2DoubleMap FACTORIAL_CACHE = new Int2DoubleOpenHashMap();
diff --git a/common/src/main/java/top/r3944realms/lib39/util/PlantHelper.java b/common/src/main/java/top/r3944realms/lib39/util/PlantHelper.java
index 0134d5e..6a88682 100644
--- a/common/src/main/java/top/r3944realms/lib39/util/PlantHelper.java
+++ b/common/src/main/java/top/r3944realms/lib39/util/PlantHelper.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.util;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
@@ -268,7 +268,7 @@ public class PlantHelper {
* @return the texture rl
*/
@Contract("_ -> new")
- public static @NotNull ResourceLocation getTextureRL(@NotNull Plant plant) {
+ public static @NotNull Identifier getTextureRL(@NotNull Plant plant) {
return Lib39.mrl("block/" + plant.name);
}
@@ -279,7 +279,7 @@ public class PlantHelper {
* @return the directly texture rl
*/
@Contract("_ -> new")
- public static @NotNull ResourceLocation getDirectlyTextureRL(@NotNull Plant plant) {
+ public static @NotNull Identifier getDirectlyTextureRL(@NotNull Plant plant) {
return Lib39.mrl("textures/block/" + plant.name + ".png");
}
}
diff --git a/common/src/main/java/top/r3944realms/lib39/util/nbt/NBTReader.java b/common/src/main/java/top/r3944realms/lib39/util/nbt/NBTReader.java
index 4939fca..d98365e 100644
--- a/common/src/main/java/top/r3944realms/lib39/util/nbt/NBTReader.java
+++ b/common/src/main/java/top/r3944realms/lib39/util/nbt/NBTReader.java
@@ -20,9 +20,12 @@ import com.mojang.authlib.properties.Property;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.world.phys.Vec3;
+import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import org.jspecify.annotations.NonNull;
+import java.util.Optional;
import java.util.UUID;
import java.util.function.Consumer;
@@ -47,24 +50,33 @@ public class NBTReader {
public static NBTReader of(@NotNull CompoundTag nbt) {
return new NBTReader(nbt);
}
-
/**
- * String nbt reader.
+ * 从CompoundTag创建读取器
*
- * @param key the key
- * @param setter the setter
+ * @param nbt the nbt opt
* @return the nbt reader
*/
-// 基本读取方法 - 直接赋值给成员变量
- public NBTReader string(String key, Consumer setter) {
- if (nbt.contains(key)) {
- setter.accept(nbt.getString(key));
+ @NotNull
+ public static NBTReader ofOpt(@NotNull Optional nbt) {
+ return new NBTReader(nbt.orElse(new CompoundTag()));
+ }
+ @Contract(pure = true)
+ private static boolean checkOpt(@NonNull Optional> nbt) {
+ return nbt.isPresent();
+ }
+ @Contract(pure = true)
+ private static boolean checkOpt(Optional> @NonNull ... nbts) {
+ for (Optional> nbt : nbts) {
+ if (nbt.isEmpty()) {
+ return false;
+ }
}
- return this;
+ return true;
}
+
/**
- * String nbt reader.
+ * String nbt reader with default value.
*
* @param key the key
* @param setter the setter
@@ -72,7 +84,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader string(String key, @NotNull Consumer setter, String defaultValue) {
- setter.accept(nbt.contains(key) ? nbt.getString(key) : defaultValue);
+ if (nbt.contains(key)) {
+ Optional value = nbt.getString(key);
+ if (checkOpt(value)) {
+ setter.accept(value.get());
+ return this;
+ }
+ }
+ setter.accept(defaultValue);
return this;
}
@@ -85,13 +104,14 @@ public class NBTReader {
*/
public NBTReader byteValue(String key, Consumer setter) {
if (nbt.contains(key)) {
- setter.accept(nbt.getByte(key));
+ Optional value = nbt.getByte(key);
+ if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
- * Byte value nbt reader.
+ * Byte value nbt reader with default value.
*
* @param key the key
* @param setter the setter
@@ -99,7 +119,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader byteValue(String key, @NotNull Consumer setter, byte defaultValue) {
- setter.accept(nbt.contains(key) ? nbt.getByte(key) : defaultValue);
+ if (nbt.contains(key)) {
+ Optional value = nbt.getByte(key);
+ if (checkOpt(value)) {
+ setter.accept(value.get());
+ return this;
+ }
+ }
+ setter.accept(defaultValue);
return this;
}
@@ -112,13 +139,14 @@ public class NBTReader {
*/
public NBTReader shortValue(String key, Consumer setter) {
if (nbt.contains(key)) {
- setter.accept(nbt.getShort(key));
+ Optional value = nbt.getShort(key);
+ if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
- * Short value nbt reader.
+ * Short value nbt reader with default value.
*
* @param key the key
* @param setter the setter
@@ -126,7 +154,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader shortValue(String key, @NotNull Consumer setter, short defaultValue) {
- setter.accept(nbt.contains(key) ? nbt.getShort(key) : defaultValue);
+ if (nbt.contains(key)) {
+ Optional value = nbt.getShort(key);
+ if (checkOpt(value)) {
+ setter.accept(value.get());
+ return this;
+ }
+ }
+ setter.accept(defaultValue);
return this;
}
@@ -139,13 +174,14 @@ public class NBTReader {
*/
public NBTReader intValue(String key, Consumer setter) {
if (nbt.contains(key)) {
- setter.accept(nbt.getInt(key));
+ Optional value = nbt.getInt(key);
+ if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
- * Int value nbt reader.
+ * Int value nbt reader with default value.
*
* @param key the key
* @param setter the setter
@@ -153,7 +189,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader intValue(String key, @NotNull Consumer setter, int defaultValue) {
- setter.accept(nbt.contains(key) ? nbt.getInt(key) : defaultValue);
+ if (nbt.contains(key)) {
+ Optional value = nbt.getInt(key);
+ if (checkOpt(value)) {
+ setter.accept(value.get());
+ return this;
+ }
+ }
+ setter.accept(defaultValue);
return this;
}
@@ -166,13 +209,14 @@ public class NBTReader {
*/
public NBTReader longValue(String key, Consumer setter) {
if (nbt.contains(key)) {
- setter.accept(nbt.getLong(key));
+ Optional value = nbt.getLong(key);
+ if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
- * Long value nbt reader.
+ * Long value nbt reader with default value.
*
* @param key the key
* @param setter the setter
@@ -180,7 +224,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader longValue(String key, @NotNull Consumer setter, long defaultValue) {
- setter.accept(nbt.contains(key) ? nbt.getLong(key) : defaultValue);
+ if (nbt.contains(key)) {
+ Optional value = nbt.getLong(key);
+ if (checkOpt(value)) {
+ setter.accept(value.get());
+ return this;
+ }
+ }
+ setter.accept(defaultValue);
return this;
}
@@ -193,13 +244,14 @@ public class NBTReader {
*/
public NBTReader floatValue(String key, Consumer setter) {
if (nbt.contains(key)) {
- setter.accept(nbt.getFloat(key));
+ Optional value = nbt.getFloat(key);
+ if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
- * Float value nbt reader.
+ * Float value nbt reader with default value.
*
* @param key the key
* @param setter the setter
@@ -207,7 +259,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader floatValue(String key, @NotNull Consumer setter, float defaultValue) {
- setter.accept(nbt.contains(key) ? nbt.getFloat(key) : defaultValue);
+ if (nbt.contains(key)) {
+ Optional value = nbt.getFloat(key);
+ if (checkOpt(value)) {
+ setter.accept(value.get());
+ return this;
+ }
+ }
+ setter.accept(defaultValue);
return this;
}
@@ -220,13 +279,14 @@ public class NBTReader {
*/
public NBTReader doubleValue(String key, Consumer setter) {
if (nbt.contains(key)) {
- setter.accept(nbt.getDouble(key));
+ Optional value = nbt.getDouble(key);
+ if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
- * Double value nbt reader.
+ * Double value nbt reader with default value.
*
* @param key the key
* @param setter the setter
@@ -234,7 +294,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader doubleValue(String key, @NotNull Consumer setter, double defaultValue) {
- setter.accept(nbt.contains(key) ? nbt.getDouble(key) : defaultValue);
+ if (nbt.contains(key)) {
+ Optional value = nbt.getDouble(key);
+ if (checkOpt(value)) {
+ setter.accept(value.get());
+ return this;
+ }
+ }
+ setter.accept(defaultValue);
return this;
}
@@ -247,13 +314,14 @@ public class NBTReader {
*/
public NBTReader booleanValue(String key, Consumer setter) {
if (nbt.contains(key)) {
- setter.accept(nbt.getBoolean(key));
+ Optional value = nbt.getBoolean(key);
+ if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
- * Boolean value nbt reader.
+ * Boolean value nbt reader with default value.
*
* @param key the key
* @param setter the setter
@@ -261,7 +329,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader booleanValue(String key, @NotNull Consumer setter, boolean defaultValue) {
- setter.accept(nbt.contains(key) ? nbt.getBoolean(key) : defaultValue);
+ if (nbt.contains(key)) {
+ Optional value = nbt.getBoolean(key);
+ if (checkOpt(value)) {
+ setter.accept(value.get());
+ return this;
+ }
+ }
+ setter.accept(defaultValue);
return this;
}
@@ -272,10 +347,10 @@ public class NBTReader {
* @param setter the setter
* @return the nbt reader
*/
-// 数组类型
public NBTReader byteArray(String key, Consumer setter) {
if (nbt.contains(key)) {
- setter.accept(nbt.getByteArray(key));
+ Optional value = nbt.getByteArray(key);
+ if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
@@ -289,7 +364,8 @@ public class NBTReader {
*/
public NBTReader intArray(String key, Consumer setter) {
if (nbt.contains(key)) {
- setter.accept(nbt.getIntArray(key));
+ Optional value = nbt.getIntArray(key);
+ if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
@@ -303,39 +379,12 @@ public class NBTReader {
*/
public NBTReader longArray(String key, Consumer setter) {
if (nbt.contains(key)) {
- setter.accept(nbt.getLongArray(key));
+ Optional value = nbt.getLongArray(key);
+ if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
- /**
- * Uuid nbt reader.
- *
- * @param key the key
- * @param setter the setter
- * @return the nbt reader
- */
-// UUID
- public NBTReader uuid(String key, Consumer setter) {
- if (nbt.hasUUID(key)) {
- setter.accept(nbt.getUUID(key));
- }
- return this;
- }
-
- /**
- * Uuid nbt reader.
- *
- * @param key the key
- * @param setter the setter
- * @param defaultValue the default value
- * @return the nbt reader
- */
- public NBTReader uuid(String key, @NotNull Consumer setter, UUID defaultValue) {
- setter.accept(nbt.hasUUID(key) ? nbt.getUUID(key) : defaultValue);
- return this;
- }
-
/**
* Compound nbt reader.
*
@@ -343,16 +392,16 @@ public class NBTReader {
* @param setter the setter
* @return the nbt reader
*/
-// CompoundTag
public NBTReader compound(String key, Consumer setter) {
if (nbt.contains(key)) {
- setter.accept(nbt.getCompound(key));
+ Optional value = nbt.getCompound(key);
+ if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
- * Compound nbt reader.
+ * Compound nbt reader with default value.
*
* @param key the key
* @param setter the setter
@@ -360,58 +409,10 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader compound(String key, @NotNull Consumer setter, CompoundTag defaultValue) {
- setter.accept(nbt.contains(key) ? nbt.getCompound(key) : defaultValue);
- return this;
- }
-
- /**
- * List nbt reader.
- *
- * @param key the key
- * @param type the type
- * @param setter the setter
- * @return the nbt reader
- */
-// ListTag
- public NBTReader list(String key, int type, Consumer setter) {
if (nbt.contains(key)) {
- setter.accept(nbt.getList(key, type));
- }
- return this;
- }
-
- /**
- * Game profile nbt reader.
- *
- * @param key the key
- * @param setter the setter
- * @return the nbt reader
- */
- public NBTReader gameProfile(String key, Consumer setter) {
- if (nbt.contains(key, CompoundTag.TAG_COMPOUND)) {
- CompoundTag tag = nbt.getCompound(key);
- GameProfile profile = readGameProfileFromTag(tag);
- if (profile != null) {
- setter.accept(profile);
- }
- }
- return this;
- }
-
- /**
- * Game profile nbt reader with default value.
- *
- * @param key the key
- * @param setter the setter
- * @param defaultValue the default value
- * @return the nbt reader
- */
- public NBTReader gameProfile(String key, Consumer setter, GameProfile defaultValue) {
- if (nbt.contains(key, CompoundTag.TAG_COMPOUND)) {
- CompoundTag tag = nbt.getCompound(key);
- GameProfile profile = readGameProfileFromTag(tag);
- if (profile != null) {
- setter.accept(profile);
+ Optional value = nbt.getCompound(key);
+ if (checkOpt(value)) {
+ setter.accept(value.get());
return this;
}
}
@@ -420,83 +421,19 @@ public class NBTReader {
}
/**
- * Read GameProfile from CompoundTag.
+ * List nbt reader.
*
- * @param tag the tag
- * @return the game profile, or null if invalid
+ * @param key the key
+ * @param setter the setter
+ * @return the nbt reader
*/
- @Nullable
- private static GameProfile readGameProfileFromTag(@NotNull CompoundTag tag) {
- String name = null;
- UUID uuid = null;
-
- // 支持 "Name" 或 "name"
- if (tag.contains("Name", CompoundTag.TAG_STRING)) {
- name = tag.getString("Name");
- } else if (tag.contains("name", CompoundTag.TAG_STRING)) {
- name = tag.getString("name");
- }
-
- // 支持 "Id" 或 "id"
- if (tag.hasUUID("Id")) {
- uuid = tag.getUUID("Id");
- } else if (tag.hasUUID("id")) {
- uuid = tag.getUUID("id");
- }
-
- try {
- GameProfile profile = new GameProfile(uuid, name);
-
- // 支持 "Properties" 或 "properties",支持 COMPOUND 或 LIST 格式
- String propertiesKey = tag.contains("Properties", CompoundTag.TAG_COMPOUND) ? "Properties"
- : (tag.contains("properties", CompoundTag.TAG_COMPOUND) ? "properties" : null);
-
- // 如果没有 COMPOUND,尝试 LIST 格式
- if (propertiesKey == null) {
- String listKey = tag.contains("Properties", CompoundTag.TAG_LIST) ? "Properties"
- : (tag.contains("properties", CompoundTag.TAG_LIST) ? "properties" : null);
- if (listKey != null) {
- ListTag propertiesList = tag.getList(listKey, CompoundTag.TAG_COMPOUND);
- for (int i = 0; i < propertiesList.size(); i++) {
- CompoundTag propTag = propertiesList.getCompound(i);
- String propName = propTag.getString("name");
- String value = propTag.getString("value");
- String signature = propTag.contains("signature") ? propTag.getString("signature") : null;
-
- if (signature != null) {
- profile.getProperties().put(propName, new Property(propName, value, signature));
- } else {
- profile.getProperties().put(propName, new Property(propName, value));
- }
- }
- return profile;
- }
- }
-
- // COMPOUND 格式处理
- if (propertiesKey != null && tag.contains(propertiesKey, CompoundTag.TAG_COMPOUND)) {
- CompoundTag propertiesTag = tag.getCompound(propertiesKey);
- for (String key : propertiesTag.getAllKeys()) {
- ListTag listTag = propertiesTag.getList(key, CompoundTag.TAG_COMPOUND);
- for (int i = 0; i < listTag.size(); i++) {
- CompoundTag propTag = listTag.getCompound(i);
- String value = propTag.getString("Value");
- String signature = propTag.contains("Signature") ? propTag.getString("Signature") : null;
- if (signature != null) {
- profile.getProperties().put(key, new Property(key, value, signature));
- } else {
- profile.getProperties().put(key, new Property(key, value));
- }
- }
- }
- }
-
- return profile;
- } catch (Throwable e) {
- return null;
+ public NBTReader list(String key, Consumer setter) {
+ if (nbt.contains(key)) {
+ Optional value = nbt.getList(key);
+ if (checkOpt(value)) setter.accept(value.get());
}
+ return this;
}
-
/**
* Vec 3 nbt reader.
*
@@ -504,23 +441,31 @@ public class NBTReader {
* @param setter the setter
* @return the nbt reader
*/
-// Vec3支持
public NBTReader vec3(String key, Consumer setter) {
if (nbt.contains(key)) {
- CompoundTag vecTag = nbt.getCompound(key);
- if (vecTag.contains("X") && vecTag.contains("Y") && vecTag.contains("Z")) {
- setter.accept(new Vec3(
- vecTag.getDouble("X"),
- vecTag.getDouble("Y"),
- vecTag.getDouble("Z")
- ));
+ Optional vecTag = nbt.getCompound(key);
+ if (checkOpt(vecTag)) {
+ CompoundTag vec = vecTag.get();
+ if (vec.contains("X") && vec.contains("Y") && vec.contains("Z")) {
+ Optional x = vec.getDouble("X");
+ Optional y = vec.getDouble("Y");
+ Optional z = vec.getDouble("Z");
+ if (checkOpt(x, y, z)) {
+ Vec3 value = new Vec3(
+ x.get(),
+ y.get(),
+ z.get()
+ );
+ setter.accept(value);
+ }
+ }
}
}
return this;
}
/**
- * Vec 3 nbt reader.
+ * Vec 3 nbt reader with default value.
*
* @param key the key
* @param setter the setter
@@ -529,14 +474,23 @@ public class NBTReader {
*/
public NBTReader vec3(String key, Consumer setter, Vec3 defaultValue) {
if (nbt.contains(key)) {
- CompoundTag vecTag = nbt.getCompound(key);
- if (vecTag.contains("X") && vecTag.contains("Y") && vecTag.contains("Z")) {
- setter.accept(new Vec3(
- vecTag.getDouble("X"),
- vecTag.getDouble("Y"),
- vecTag.getDouble("Z")
- ));
- return this;
+ Optional vecTag = nbt.getCompound(key);
+ if (checkOpt(vecTag)) {
+ CompoundTag vec = vecTag.get();
+ if (vec.contains("X") && vec.contains("Y") && vec.contains("Z")) {
+ Optional x = vec.getDouble("X");
+ Optional y = vec.getDouble("Y");
+ Optional z = vec.getDouble("Z");
+ if (checkOpt(x, y, z)) {
+ Vec3 value = new Vec3(
+ x.get(),
+ y.get(),
+ z.get()
+ );
+ setter.accept(value);
+ return this;
+ }
+ }
}
}
setter.accept(defaultValue);
@@ -552,21 +506,24 @@ public class NBTReader {
* @param setter the setter
* @return the nbt reader
*/
-// 枚举支持
public > NBTReader enumValue(String key, Class enumClass, Consumer setter) {
if (nbt.contains(key)) {
- String value = nbt.getString(key);
- try {
- setter.accept(Enum.valueOf(enumClass, value.toUpperCase()));
- } catch (IllegalArgumentException ignored) {
- // 保持setter的当前值
+ Optional value = nbt.getString(key);
+ if(checkOpt(value)) {
+ try {
+ T enumValue = Enum.valueOf(enumClass, value.get().toUpperCase());
+ setter.accept(enumValue);
+ } catch (IllegalArgumentException ignored) {
+ // 保持setter的当前值
+ }
}
+
}
return this;
}
/**
- * Enum value nbt reader.
+ * Enum value nbt reader with default value.
*
* @param the type parameter
* @param key the key
@@ -577,18 +534,21 @@ public class NBTReader {
*/
public > NBTReader enumValue(String key, Class enumClass, Consumer setter, T defaultValue) {
if (nbt.contains(key)) {
- String value = nbt.getString(key);
- try {
- setter.accept(Enum.valueOf(enumClass, value.toUpperCase()));
- return this;
- } catch (IllegalArgumentException ignored) {
+ Optional value = nbt.getString(key);
+ if (checkOpt(value)) {
+ try {
+ T enumValue = Enum.valueOf(enumClass, value.get().toUpperCase());
+ setter.accept(enumValue);
+ return this;
+ } catch (IllegalArgumentException ignored) {
+ // 保持setter的当前值
+ }
}
}
setter.accept(defaultValue);
return this;
}
-
/**
* Nested nbt reader.
*
@@ -596,16 +556,18 @@ public class NBTReader {
* @param consumer the consumer
* @return the nbt reader
*/
-// 嵌套读取支持
public NBTReader nested(String key, Consumer consumer) {
if (nbt.contains(key)) {
- consumer.accept(new NBTReader(nbt.getCompound(key)));
+ Optional compound = nbt.getCompound(key);
+ if (checkOpt(compound)) {
+ consumer.accept(new NBTReader(compound.get()));
+ }
}
return this;
}
/**
- * Nested nbt reader.
+ * Nested nbt reader with orElse.
*
* @param key the key
* @param consumer the consumer
@@ -614,7 +576,10 @@ public class NBTReader {
*/
public NBTReader nested(String key, Consumer consumer, Runnable orElse) {
if (nbt.contains(key)) {
- consumer.accept(new NBTReader(nbt.getCompound(key)));
+ Optional compound = nbt.getCompound(key);
+ if (checkOpt(compound)) {
+ consumer.accept(new NBTReader(compound.get()));
+ }
} else {
orElse.run();
}
@@ -628,7 +593,6 @@ public class NBTReader {
* @param action the action
* @return the nbt reader
*/
-// 条件读取
public NBTReader ifPresent(String key, Runnable action) {
if (nbt.contains(key)) {
action.run();
@@ -655,7 +619,6 @@ public class NBTReader {
*
* @return the raw
*/
-// 获取原始NBT
@NotNull
public CompoundTag getRaw() {
return nbt;
@@ -667,14 +630,20 @@ public class NBTReader {
* @param nbt the nbt
* @return the vec 3
*/
-// 便捷的静态方法(保持原有功能)
@NotNull
public static Vec3 readVec3(@NotNull CompoundTag nbt) {
if (nbt.contains("X") && nbt.contains("Y") && nbt.contains("Z")) {
- return new Vec3(
- nbt.getDouble("X"),
- nbt.getDouble("Y"),
- nbt.getDouble("Z")
+ Optional x = nbt.getDouble("X");
+ Optional y = nbt.getDouble("Y");
+ Optional z = nbt.getDouble("Z");
+ if (checkOpt(x, y, z)) {
+ return new Vec3(
+ x.get(),
+ y.get(),
+ z.get()
+ );
+ } else throw new IllegalArgumentException(
+ "XYZ is null."
);
} else {
throw new IllegalArgumentException("NBT is missing X, Y, or Z value for Vec3");
@@ -690,11 +659,16 @@ public class NBTReader {
@Nullable
public static Vec3 readVec3Safe(@NotNull CompoundTag nbt) {
if (nbt.contains("X") && nbt.contains("Y") && nbt.contains("Z")) {
- return new Vec3(
- nbt.getDouble("X"),
- nbt.getDouble("Y"),
- nbt.getDouble("Z")
- );
+ Optional x = nbt.getDouble("X");
+ Optional y = nbt.getDouble("Y");
+ Optional z = nbt.getDouble("Z");
+ if (checkOpt(x, y, z)) {
+ return new Vec3(
+ x.get(),
+ y.get(),
+ z.get()
+ );
+ }
}
return null;
}
diff --git a/common/src/main/java/top/r3944realms/lib39/util/nbt/NBTWriter.java b/common/src/main/java/top/r3944realms/lib39/util/nbt/NBTWriter.java
index 071d717..ec97619 100644
--- a/common/src/main/java/top/r3944realms/lib39/util/nbt/NBTWriter.java
+++ b/common/src/main/java/top/r3944realms/lib39/util/nbt/NBTWriter.java
@@ -397,47 +397,15 @@ public class NBTWriter {
}
return this;
}
-
- /**
- * Uuid nbt writer.
- *
- * @param key the key
- * @param value the value
- * @return the nbt writer
- */
-// UUID支持
- public NBTWriter uuid(String key, UUID value) {
- if (value != null) {
- root.putUUID(key, value);
- }
- return this;
- }
-
- /**
- * Uuid nbt writer.
- *
- * @param key the key
- * @param value the value
- * @param defaultValue the default value
- * @return the nbt writer
- */
- public NBTWriter uuid(String key, UUID value, UUID defaultValue) {
- if (value != null) {
- root.putUUID(key, value);
- } else if (defaultValue != null) {
- root.putUUID(key, defaultValue);
- }
- return this;
- }
-
/**
* Compound nbt writer.
+ * 嵌套CompoundTag
*
* @param key the key
* @param consumer the consumer
* @return the nbt writer
*/
-// 嵌套CompoundTag
+
public NBTWriter compound(String key, Consumer consumer) {
if (consumer != null) {
NBTWriter nestedBuilder = new NBTWriter();
@@ -496,12 +464,12 @@ public class NBTWriter {
/**
* List nbt writer.
+ * ListTag支持
*
* @param key the key
* @param consumer the consumer
* @return the nbt writer
*/
-// ListTag支持
public NBTWriter list(String key, Consumer consumer) {
if (consumer != null) {
ListNBTBuilder listBuilder = new ListNBTBuilder();
@@ -572,60 +540,6 @@ public class NBTWriter {
return this;
}
- /**
- * Game profile nbt writer.
- *
- * @param key the key
- * @param profile the profile
- * @return the nbt writer
- */
- public NBTWriter gameProfile(String key, @NotNull GameProfile profile) {
- root.put(key, writeGameProfile(profile));
- return this;
- }
-
- private CompoundTag writeGameProfile(@NotNull GameProfile profile) {
- CompoundTag tag = new CompoundTag();
- if (!StringUtil.isNullOrEmpty(profile.getName())) {
- tag.putString("Name", profile.getName());
- }
- if (profile.getId() != null) {
- tag.putUUID("Id", profile.getId());
- }
- if (!profile.getProperties().isEmpty()) {
- CompoundTag compoundTag = new CompoundTag();
- for(String keySet : profile.getProperties().keySet()) {
- ListTag propListTag = new ListTag();
- for(Property property : profile.getProperties().get(keySet)) {
- CompoundTag propTag = new CompoundTag();
- propTag.putString("Value", property.value());
- if (property.hasSignature()) {
- propTag.putString("Signature", property.signature());
- }
- propListTag.add(propTag);
- }
- compoundTag.put(keySet, propListTag);
- }
- tag.put("Properties", compoundTag);
- }
- return tag;
- }
-
- /**
- * GameProfile if nbt writer.
- *
- * @param key the key
- * @param condition the condition
- * @param value the value
- * @return the nbt writer
- */
- public NBTWriter gameProfileIf(String key, boolean condition, Supplier value) {
- if (condition && value != null) {
- root.put(key, writeGameProfile(value.get()));
- }
- return this;
- }
-
/**
* String if nbt writer.
*
@@ -671,21 +585,6 @@ public class NBTWriter {
return this;
}
- /**
- * Uuid value if nbt writer.
- *
- * @param key the key
- * @param condition the condition
- * @param value the value
- * @return the nbt writer
- */
- public NBTWriter uuidValueIf(String key, boolean condition, Supplier value) {
- if (condition && value != null) {
- root.putUUID(key, value.get());
- }
- return this;
- }
-
/**
* Boolean value if nbt writer.
*
@@ -1162,7 +1061,7 @@ public class NBTWriter {
* @return the all keys
*/
public java.util.Set getAllKeys() {
- return root.getAllKeys();
+ return root.keySet();
}
/**
diff --git a/common/src/main/java/top/r3944realms/lib39/util/resolve/EntityListResolve.java b/common/src/main/java/top/r3944realms/lib39/util/resolve/EntityListResolve.java
index 9867d5d..c6bcfbd 100644
--- a/common/src/main/java/top/r3944realms/lib39/util/resolve/EntityListResolve.java
+++ b/common/src/main/java/top/r3944realms/lib39/util/resolve/EntityListResolve.java
@@ -1,7 +1,7 @@
package top.r3944realms.lib39.util.resolve;
import net.minecraft.core.registries.Registries;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.EntityType;
import org.jetbrains.annotations.NotNull;
@@ -141,14 +141,14 @@ public abstract class EntityListResolve {
*/
@SuppressWarnings("deprecation")
public boolean isEntityInList(EntityType> type) {
- String entityId = type.builtInRegistryHolder().key().location().toString();
+ String entityId = type.builtInRegistryHolder().key().identifier().toString();
String modId = entityId.split(":")[0];
for (String rs : result.entityList) {
if (rs.equals(entityId)) return true;
}
for(String rs : result.tagList) {
String body = rs.substring(1);
- ResourceLocation tagId = Lib39.rl(body);
+ Identifier tagId = Lib39.rl(body);
TagKey> tag = TagKey.create(Registries.ENTITY_TYPE, tagId);
if (type.builtInRegistryHolder().is(tag)) return true;
}
diff --git a/common/src/main/java/top/r3944realms/lib39/util/resolve/EntityMapResolve.java b/common/src/main/java/top/r3944realms/lib39/util/resolve/EntityMapResolve.java
index 8bdf7cc..873f389 100644
--- a/common/src/main/java/top/r3944realms/lib39/util/resolve/EntityMapResolve.java
+++ b/common/src/main/java/top/r3944realms/lib39/util/resolve/EntityMapResolve.java
@@ -1,7 +1,7 @@
package top.r3944realms.lib39.util.resolve;
import net.minecraft.core.registries.Registries;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.EntityType;
import org.jetbrains.annotations.NotNull;
@@ -153,7 +153,7 @@ public abstract class EntityMapResolve {
*/
@SuppressWarnings("deprecation")
private EntityMatchResult findEntityMatch(EntityType> type) {
- String entityId = type.builtInRegistryHolder().key().location().toString();
+ String entityId = type.builtInRegistryHolder().key().identifier().toString();
String modId = entityId.split(":")[0];
// 检查实体ID匹配
@@ -166,7 +166,7 @@ public abstract class EntityMapResolve {
// 检查标签匹配
for (String rs : result.tagMap.keySet()) {
String body = rs.startsWith("#") ? rs.substring(1) : rs;
- ResourceLocation tagId = Lib39.rl(body);
+ Identifier tagId = Lib39.rl(body);
TagKey> tag = TagKey.create(Registries.ENTITY_TYPE, tagId);
if (type.builtInRegistryHolder().is(tag)) {
return new EntityMatchResult<>(EntityResolveResult.Type.TAG, rs, result.tagMap.get(rs));
diff --git a/common/src/main/java/top/r3944realms/lib39/util/riding/RidingApplier.java b/common/src/main/java/top/r3944realms/lib39/util/riding/RidingApplier.java
index 9611659..d9502e7 100644
--- a/common/src/main/java/top/r3944realms/lib39/util/riding/RidingApplier.java
+++ b/common/src/main/java/top/r3944realms/lib39/util/riding/RidingApplier.java
@@ -75,7 +75,7 @@ public class RidingApplier {
if (RidingValidator.wouldCreateCycle(entity, vehicle)) {
throw new RidingCycleException(entityId, vehicleId);
}
- boolean success = entity.startRiding(vehicle, true);
+ boolean success = entity.startRiding(vehicle, true, true);
if (!success) {
Lib39.LOGGER.error("Failed to mount entity {} to vehicle {}", entityId, vehicleId);
}
diff --git a/common/src/main/java/top/r3944realms/lib39/util/villager/TradeBuilder.java b/common/src/main/java/top/r3944realms/lib39/util/villager/TradeBuilder.java
index bb4d25a..3ca4c79 100644
--- a/common/src/main/java/top/r3944realms/lib39/util/villager/TradeBuilder.java
+++ b/common/src/main/java/top/r3944realms/lib39/util/villager/TradeBuilder.java
@@ -16,12 +16,11 @@ import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.Entity;
-import net.minecraft.world.entity.npc.VillagerDataHolder;
-import net.minecraft.world.entity.npc.VillagerTrades;
-import net.minecraft.world.entity.npc.VillagerType;
+import net.minecraft.world.entity.npc.villager.VillagerDataHolder;
+import net.minecraft.world.entity.npc.villager.VillagerTrades;
+import net.minecraft.world.entity.npc.villager.VillagerType;
import net.minecraft.world.item.*;
import net.minecraft.world.item.alchemy.Potion;
-import net.minecraft.world.item.alchemy.PotionBrewing;
import net.minecraft.world.item.alchemy.PotionContents;
import net.minecraft.world.item.component.DyedItemColor;
import net.minecraft.world.item.component.SuspiciousStewEffects;
@@ -42,7 +41,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.stream.Collectors;
/**
* 村民交易构建器
diff --git a/fabric/src/main/java/top/r3944realms/lib39/api/callback/RegisterCommandHelpCallback.java b/fabric/src/main/java/top/r3944realms/lib39/api/callback/RegisterCommandHelpCallback.java
index 27cd51e..a0de896 100644
--- a/fabric/src/main/java/top/r3944realms/lib39/api/callback/RegisterCommandHelpCallback.java
+++ b/fabric/src/main/java/top/r3944realms/lib39/api/callback/RegisterCommandHelpCallback.java
@@ -6,7 +6,7 @@ import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.MutableComponent;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import top.r3944realms.lib39.core.command.ICommandHelpManager;
import top.r3944realms.lib39.core.command.model.CommandNode;
import top.r3944realms.lib39.core.command.model.CommandPath;
@@ -50,7 +50,7 @@ public interface RegisterCommandHelpCallback {
*
* @return the id
*/
- ResourceLocation getID();
+ Identifier getID();
/**
* Add child.
@@ -103,7 +103,7 @@ public interface RegisterCommandHelpCallback {
*/
record CommandHelpRegistrar(LiteralArgumentBuilder builder, ICommandHelpManager helpManager, CommandBuildContext context) implements Registrar {
@Override
- public ResourceLocation getID() {
+ public Identifier getID() {
return helpManager.getID();
}
diff --git a/fabric/src/main/java/top/r3944realms/lib39/api/callback/SyncManagerRegisterCallback.java b/fabric/src/main/java/top/r3944realms/lib39/api/callback/SyncManagerRegisterCallback.java
index 87bffc4..453385e 100644
--- a/fabric/src/main/java/top/r3944realms/lib39/api/callback/SyncManagerRegisterCallback.java
+++ b/fabric/src/main/java/top/r3944realms/lib39/api/callback/SyncManagerRegisterCallback.java
@@ -3,7 +3,7 @@ package top.r3944realms.lib39.api.callback;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.core.sync.ISyncData;
@@ -62,7 +62,7 @@ public interface SyncManagerRegisterCallback {
* @param dataClass the data class
*/
> void register(
- ResourceLocation id,
+ Identifier id,
ISyncManager syncManager,
Class dataClass
);
@@ -73,7 +73,7 @@ public interface SyncManagerRegisterCallback {
* @param id the id
* @param entityClasses the entity classes
*/
- void allowEntityClass(ResourceLocation id, Class>... entityClasses);
+ void allowEntityClass(Identifier id, Class>... entityClasses);
/**
* 移除允许的实体类
@@ -81,7 +81,7 @@ public interface SyncManagerRegisterCallback {
* @param id the id
* @param entityClasses the entity classes
*/
- void disallowEntityClass(ResourceLocation id, Class>... entityClasses);
+ void disallowEntityClass(Identifier id, Class>... entityClasses);
/**
* 绑定 EntityApiLookup(用于分离注册的情况)
@@ -91,7 +91,7 @@ public interface SyncManagerRegisterCallback {
* @param apiLookup the EntityApiLookup
*/
> void bindApiLookup(
- ResourceLocation id,
+ Identifier id,
net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup apiLookup
);
@@ -100,7 +100,7 @@ public interface SyncManagerRegisterCallback {
*
* @param id the id
*/
- void unbindApiLookup(ResourceLocation id);
+ void unbindApiLookup(Identifier id);
/**
* 完整的类型安全注册
@@ -112,7 +112,7 @@ public interface SyncManagerRegisterCallback {
* @param allowedEntityClasses the allowed entity classes
*/
default > void registerComplete(
- ResourceLocation id,
+ Identifier id,
ISyncManager syncManager,
Class dataClass,
Class>... allowedEntityClasses
@@ -132,7 +132,7 @@ public interface SyncManagerRegisterCallback {
@Override
public > void register(
- @NotNull ResourceLocation id,
+ @NotNull Identifier id,
@NotNull ISyncManager syncManager,
@NotNull Class dataClass
) {
@@ -140,25 +140,25 @@ public interface SyncManagerRegisterCallback {
}
@Override
- public void allowEntityClass(@NotNull ResourceLocation id, @NotNull Class>... entityClasses) {
+ public void allowEntityClass(@NotNull Identifier id, @NotNull Class>... entityClasses) {
manager.allowEntityClass(id, entityClasses);
}
@Override
- public void disallowEntityClass(@NotNull ResourceLocation id, @NotNull Class>... entityClasses) {
+ public void disallowEntityClass(@NotNull Identifier id, @NotNull Class>... entityClasses) {
manager.disallowEntityClass(id, entityClasses);
}
@Override
public > void bindApiLookup(
- @NotNull ResourceLocation id,
+ @NotNull Identifier id,
@NotNull EntityApiLookup apiLookup
) {
manager.bindApiLookup(id, apiLookup);
}
@Override
- public void unbindApiLookup(@NotNull ResourceLocation id) {
+ public void unbindApiLookup(@NotNull Identifier id) {
manager.unbindApiLookup(id);
}
}
diff --git a/fabric/src/main/java/top/r3944realms/lib39/base/compat/jade/FabricJadePlugin.java b/fabric/src/main/java/top/r3944realms/lib39/base/compat/jade/FabricJadePlugin.java
index b142b24..b2df7e8 100644
--- a/fabric/src/main/java/top/r3944realms/lib39/base/compat/jade/FabricJadePlugin.java
+++ b/fabric/src/main/java/top/r3944realms/lib39/base/compat/jade/FabricJadePlugin.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.base.compat.jade;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import snownee.jade.api.IWailaClientRegistration;
import snownee.jade.api.IWailaPlugin;
@@ -18,7 +18,7 @@ public class FabricJadePlugin implements IWailaPlugin {
/**
* The constant UID.
*/
- public static final ResourceLocation UID = Lib39.rl("lib39");
+ public static final Identifier UID = Lib39.rl("lib39");
@Override
public void registerClient(@NotNull IWailaClientRegistration registration) {
diff --git a/fabric/src/main/java/top/r3944realms/lib39/base/compat/jade/provider/FabricDollComponentProvider.java b/fabric/src/main/java/top/r3944realms/lib39/base/compat/jade/provider/FabricDollComponentProvider.java
index 13135fb..6eda182 100644
--- a/fabric/src/main/java/top/r3944realms/lib39/base/compat/jade/provider/FabricDollComponentProvider.java
+++ b/fabric/src/main/java/top/r3944realms/lib39/base/compat/jade/provider/FabricDollComponentProvider.java
@@ -2,7 +2,7 @@ package top.r3944realms.lib39.base.compat.jade.provider;
import com.mojang.authlib.GameProfile;
import net.minecraft.network.chat.Component;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import snownee.jade.api.BlockAccessor;
import snownee.jade.api.IBlockComponentProvider;
@@ -16,7 +16,7 @@ import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
*/
public class FabricDollComponentProvider implements IBlockComponentProvider {
@Override
- public ResourceLocation getUid() {
+ public Identifier getUid() {
return FabricJadePlugin.UID;
}
diff --git a/fabric/src/main/java/top/r3944realms/lib39/core/event/FabricCommonEventHandler.java b/fabric/src/main/java/top/r3944realms/lib39/core/event/FabricCommonEventHandler.java
index aa448c6..82d166e 100644
--- a/fabric/src/main/java/top/r3944realms/lib39/core/event/FabricCommonEventHandler.java
+++ b/fabric/src/main/java/top/r3944realms/lib39/core/event/FabricCommonEventHandler.java
@@ -12,7 +12,7 @@ import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.Services;
import net.minecraft.server.level.ServerLevel;
@@ -122,8 +122,8 @@ public class FabricCommonEventHandler {
public static void onServerTick(MinecraftServer server) {
if (syncData2Manager == null) return;
if (server.getTickCount() % 10 == 0)
- syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
- syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
+ syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
+ syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
}
/**
@@ -135,7 +135,7 @@ public class FabricCommonEventHandler {
public static void onEntityJoinWorld(@NotNull Entity entity, ServerLevel level) {
if (entity.level().isClientSide) return;
- for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
+ for (Identifier id : syncData2Manager.getRegisteredKeys()) {
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
syncData2Manager.trackEntityForManager(entity, id);
}
@@ -151,7 +151,7 @@ public class FabricCommonEventHandler {
public static void onEntityLeaveWorld(@NotNull Entity entity, ServerLevel level) {
if (entity.level().isClientSide) return;
- for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
+ for (Identifier id : syncData2Manager.getRegisteredKeys()) {
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
syncData2Manager.untrackEntityForManager(entity, id);
}
diff --git a/fabric/src/main/java/top/r3944realms/lib39/core/network/toClient/SyncNBTLookupDataEntityS2CPayload.java b/fabric/src/main/java/top/r3944realms/lib39/core/network/toClient/SyncNBTLookupDataEntityS2CPayload.java
index 81f2c45..5be285b 100644
--- a/fabric/src/main/java/top/r3944realms/lib39/core/network/toClient/SyncNBTLookupDataEntityS2CPayload.java
+++ b/fabric/src/main/java/top/r3944realms/lib39/core/network/toClient/SyncNBTLookupDataEntityS2CPayload.java
@@ -7,7 +7,7 @@ import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
@@ -22,11 +22,11 @@ import java.util.Optional;
/**
* The type Sync nbt lookup data entity s 2 c payload.
*/
-public record SyncNBTLookupDataEntityS2CPayload(int entityId, ResourceLocation id, CompoundTag data) implements CustomPacketPayload {
+public record SyncNBTLookupDataEntityS2CPayload(int entityId, Identifier id, CompoundTag data) implements CustomPacketPayload {
/**
* The constant SYNC_NBT_LOOKUP_PACKET_ID.
*/
- public static final ResourceLocation SYNC_NBT_LOOKUP_PACKET_ID =
+ public static final Identifier SYNC_NBT_LOOKUP_PACKET_ID =
Lib39.rl("sync_nbt_lookup_data_entity");
/**
* The constant TYPE.
@@ -56,7 +56,7 @@ public record SyncNBTLookupDataEntityS2CPayload(int entityId, ResourceLocation i
* @param buf the buffer
*/
public SyncNBTLookupDataEntityS2CPayload(RegistryFriendlyByteBuf buf) {
- this(buf.readInt(), buf.readResourceLocation(), buf.readNbt());
+ this(buf.readInt(), buf.readIdentifier(), buf.readNbt());
}
/**
@@ -66,7 +66,7 @@ public record SyncNBTLookupDataEntityS2CPayload(int entityId, ResourceLocation i
*/
public void write(@NotNull FriendlyByteBuf friendlyByteBuf) {
friendlyByteBuf.writeInt(entityId);
- friendlyByteBuf.writeResourceLocation(id);
+ friendlyByteBuf.writeIdentifier(id);
friendlyByteBuf.writeNbt(data);
}
diff --git a/fabric/src/main/java/top/r3944realms/lib39/core/sync/SyncData2LookupManager.java b/fabric/src/main/java/top/r3944realms/lib39/core/sync/SyncData2LookupManager.java
index 6461f1e..2ae4d92 100644
--- a/fabric/src/main/java/top/r3944realms/lib39/core/sync/SyncData2LookupManager.java
+++ b/fabric/src/main/java/top/r3944realms/lib39/core/sync/SyncData2LookupManager.java
@@ -2,7 +2,7 @@ package top.r3944realms.lib39.core.sync;
import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.Nullable;
@@ -17,10 +17,10 @@ public class SyncData2LookupManager extends SyncData2Manager> typedEntries = Maps.newConcurrentMap();
+ protected final Map> typedEntries = Maps.newConcurrentMap();
@Override
- protected Map> getTypedEntries() {
+ protected Map> getTypedEntries() {
return typedEntries;
}
@@ -57,11 +57,11 @@ public class SyncData2LookupManager extends SyncData2Manager> void registerManager(
- ResourceLocation key,
+ Identifier key,
ISyncManager manager,
Class dataClass
) {
- Objects.requireNonNull(key, "ResourceLocation key cannot be null");
+ Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(manager, "Sync manager cannot be null");
Objects.requireNonNull(dataClass, "Data class cannot be null");
@@ -77,8 +77,8 @@ public class SyncData2LookupManager extends SyncData2Manager> void bindApiLookup(ResourceLocation key, EntityApiLookup apiLookup) {
- Objects.requireNonNull(key, "ResourceLocation key cannot be null");
+ public > void bindApiLookup(Identifier key, EntityApiLookup apiLookup) {
+ Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(apiLookup, "EntityApiLookup cannot be null");
TypedSyncEntry> entry = typedEntries.get(key);
@@ -94,8 +94,8 @@ public class SyncData2LookupManager extends SyncData2Manager entry = typedEntries.get(key);
if (entry != null) {
@@ -112,7 +112,7 @@ public class SyncData2LookupManager extends SyncData2Manager> void updateApiLookupInEntry(
- ResourceLocation id,
+ Identifier id,
TypedSyncEntry> entry,
EntityApiLookup newApiLookup
) {
diff --git a/fabric/src/main/java/top/r3944realms/lib39/core/sync/SyncLookupProvider.java b/fabric/src/main/java/top/r3944realms/lib39/core/sync/SyncLookupProvider.java
index fc6240e..65749b2 100644
--- a/fabric/src/main/java/top/r3944realms/lib39/core/sync/SyncLookupProvider.java
+++ b/fabric/src/main/java/top/r3944realms/lib39/core/sync/SyncLookupProvider.java
@@ -1,7 +1,7 @@
package top.r3944realms.lib39.core.sync;
import net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.Nullable;
import top.r3944realms.lib39.core.event.FabricCommonEventHandler;
@@ -25,7 +25,7 @@ public abstract class SyncLookupProvider implements
*
* @return the id
*/
- protected abstract ResourceLocation getId();
+ protected abstract Identifier getId();
@SuppressWarnings("unchecked")
@Override
public @Nullable T find(Entity entity, Void context) {
diff --git a/fabric/src/main/java/top/r3944realms/lib39/example/content/data/FabricTestSyncData.java b/fabric/src/main/java/top/r3944realms/lib39/example/content/data/FabricTestSyncData.java
index a6006ce..a888364 100644
--- a/fabric/src/main/java/top/r3944realms/lib39/example/content/data/FabricTestSyncData.java
+++ b/fabric/src/main/java/top/r3944realms/lib39/example/content/data/FabricTestSyncData.java
@@ -2,7 +2,7 @@ package top.r3944realms.lib39.example.content.data;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
@@ -23,7 +23,7 @@ public class FabricTestSyncData extends AbstractedTestSyncData implements IFabri
/**
* The constant ID.
*/
- public static final ResourceLocation ID = Lib39.rl(Lib39.MOD_ID, "test_sync_data");
+ public static final Identifier ID = Lib39.rl(Lib39.MOD_ID, "test_sync_data");
// NBT 键常量
private static final String NBT_KEY_STRING = "test_string";
diff --git a/fabric/src/main/java/top/r3944realms/lib39/example/content/data/FabricTestSyncLookupProvider.java b/fabric/src/main/java/top/r3944realms/lib39/example/content/data/FabricTestSyncLookupProvider.java
index 0a8155c..974295d 100644
--- a/fabric/src/main/java/top/r3944realms/lib39/example/content/data/FabricTestSyncLookupProvider.java
+++ b/fabric/src/main/java/top/r3944realms/lib39/example/content/data/FabricTestSyncLookupProvider.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.example.content.data;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import top.r3944realms.lib39.core.sync.SyncLookupProvider;
@@ -19,7 +19,7 @@ public class FabricTestSyncLookupProvider extends SyncLookupProvider> void registerSyncManager(
- ResourceLocation id,
+ Identifier id,
ISyncManager, T> syncManager,
EntityCapability capability
) {
@@ -57,7 +57,7 @@ public class SyncManagerRegisterEvent extends Event {
*
* @param id the id
*/
- public void unregisterSyncManager(ResourceLocation id) {
+ public void unregisterSyncManager(Identifier id) {
syncs2Manager.removeManager(id);
}
@@ -67,7 +67,7 @@ public class SyncManagerRegisterEvent extends Event {
* @param id the id
* @param entityClasses the entity classes
*/
- public final void addAllowEntityClass(ResourceLocation id, Class>... entityClasses) {
+ public final void addAllowEntityClass(Identifier id, Class>... entityClasses) {
syncs2Manager.allowEntityClass(id, entityClasses);
}
@@ -77,7 +77,7 @@ public class SyncManagerRegisterEvent extends Event {
* @param id the id
* @param entityClasses the entity classes
*/
- public final void removeAllowEntityClass(ResourceLocation id, Class>... entityClasses) {
+ public final void removeAllowEntityClass(Identifier id, Class>... entityClasses) {
syncs2Manager.disallowEntityClass(id, entityClasses);
}
@@ -88,7 +88,7 @@ public class SyncManagerRegisterEvent extends Event {
* @param id 必须先注册安全同步管理器,再绑定Cap,否则会抛出{@link IllegalStateException 未找到对应安全同步管理器}
* @param capability the capability
*/
- public > void bindCapability(ResourceLocation id, EntityCapability capability) {
+ public > void bindCapability(Identifier id, EntityCapability capability) {
syncs2Manager.bindCapability(id, capability);
}
@@ -97,7 +97,7 @@ public class SyncManagerRegisterEvent extends Event {
*
* @param id the id
*/
- public void unbindCapability(ResourceLocation id) {
+ public void unbindCapability(Identifier id) {
syncs2Manager.unbindCapability(id);
}
@@ -112,7 +112,7 @@ public class SyncManagerRegisterEvent extends Event {
* @param allowedEntityClasses the allowed entity classes
*/
public > void registerComplete(
- ResourceLocation id,
+ Identifier id,
ISyncManager, T> syncManager,
EntityCapability capability,
Class>... allowedEntityClasses
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/base/compat/jade/NeoForgeJadePlugin.java b/neoforge/src/main/java/top/r3944realms/lib39/base/compat/jade/NeoForgeJadePlugin.java
index 3580305..8982def 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/base/compat/jade/NeoForgeJadePlugin.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/base/compat/jade/NeoForgeJadePlugin.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.base.compat.jade;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import snownee.jade.api.IWailaClientRegistration;
import snownee.jade.api.IWailaPlugin;
@@ -17,7 +17,7 @@ public class NeoForgeJadePlugin implements IWailaPlugin {
/**
* The constant UID.
*/
- public static final ResourceLocation UID = Lib39.rl("lib39");
+ public static final Identifier UID = Lib39.rl("lib39");
@Override
public void registerClient(@NotNull IWailaClientRegistration registration) {
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/base/compat/jade/provider/NeoForgeDollComponentProvider.java b/neoforge/src/main/java/top/r3944realms/lib39/base/compat/jade/provider/NeoForgeDollComponentProvider.java
index 212722f..29dd23a 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/base/compat/jade/provider/NeoForgeDollComponentProvider.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/base/compat/jade/provider/NeoForgeDollComponentProvider.java
@@ -2,7 +2,7 @@ package top.r3944realms.lib39.base.compat.jade.provider;
import com.mojang.authlib.GameProfile;
import net.minecraft.network.chat.Component;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import snownee.jade.api.BlockAccessor;
import snownee.jade.api.IBlockComponentProvider;
@@ -17,7 +17,7 @@ import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
*/
public class NeoForgeDollComponentProvider implements IBlockComponentProvider {
@Override
- public ResourceLocation getUid() {
+ public Identifier getUid() {
return NeoForgeJadePlugin.UID;
}
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/base/datagen/Lib39BaseDataGenEvent.java b/neoforge/src/main/java/top/r3944realms/lib39/base/datagen/Lib39BaseDataGenEvent.java
index aa5cb62..d4fa740 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/base/datagen/Lib39BaseDataGenEvent.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/base/datagen/Lib39BaseDataGenEvent.java
@@ -44,37 +44,37 @@ public class Lib39BaseDataGenEvent {
}
private static void LanguageGenerator(@NotNull GatherDataEvent event, McLocale language) {
event.getGenerator().addProvider(
- event.includeClient(),
+ true,
(DataProvider.Factory) pOutput -> new SimpleLanguageProvider(pOutput, Lib39.MOD_ID ,language , Lib39LangKey.INSTANCE)
);
}
private static void ItemModelDataGenerate(@NotNull GatherDataEvent event) {
event.getGenerator().addProvider(
- event.includeClient(),
+ true,
(DataProvider.Factory) pOutput -> new Lib39ItemModelProvider(pOutput, event.getExistingFileHelper())
);
}
private static void BlockModelDataGenerate(@NotNull GatherDataEvent event) {
event.getGenerator().addProvider(
- event.includeClient(),
+ true,
(DataProvider.Factory) pOutput -> new Lib39BlockModelProvider(pOutput, event.getExistingFileHelper())
);
}
private static void BlockStateDataGenerate(@NotNull GatherDataEvent event) {
event.getGenerator().addProvider(
- event.includeClient(),
+ true,
(DataProvider.Factory) pOutput -> new Lib39BlockStatesProvider(pOutput, event.getExistingFileHelper())
);
}
private static void SoundDefinitionDataGenerate(@NotNull GatherDataEvent event) {
event.getGenerator().addProvider(
- event.includeClient(),
+ true,
(DataProvider.Factory) pOutput -> new Lib39SoundDefinitionsProvider(pOutput, event.getExistingFileHelper())
);
}
private static void LootTableDataGenerate(@NotNull GatherDataEvent event) {
event.getGenerator().addProvider(
- event.includeServer(),
+ true,
(DataProvider.Factory) pOutput -> {
try {
return new SimpleLootTableProvider(pOutput, new SubProvidersWrapper().addBlockEntry(new Lib39BlockLootTable(event.getLookupProvider())), event.getLookupProvider());
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/base/datagen/provider/Lib39BlockModelProvider.java b/neoforge/src/main/java/top/r3944realms/lib39/base/datagen/provider/Lib39BlockModelProvider.java
index b9b0650..cf3b4c7 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/base/datagen/provider/Lib39BlockModelProvider.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/base/datagen/provider/Lib39BlockModelProvider.java
@@ -1,7 +1,7 @@
package top.r3944realms.lib39.base.datagen.provider;
import net.minecraft.data.PackOutput;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.neoforged.neoforge.client.model.generators.BlockModelProvider;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import top.r3944realms.lib39.Lib39;
@@ -35,7 +35,7 @@ public class Lib39BlockModelProvider extends BlockModelProvider {
}
}
private void createPlantsModel(PlantHelper.Plant plant) {
- ResourceLocation rl = PlantHelper.getTextureRL(plant);
+ Identifier rl = PlantHelper.getTextureRL(plant);
getBuilder("block/doll_item/" + plant)
.parent(getExistingFile(Lib39.rl("block/base_doll_item")))
.texture("item", rl)
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/base/datagen/provider/Lib39ItemModelProvider.java b/neoforge/src/main/java/top/r3944realms/lib39/base/datagen/provider/Lib39ItemModelProvider.java
index f05c634..f1bc5fb 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/base/datagen/provider/Lib39ItemModelProvider.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/base/datagen/provider/Lib39ItemModelProvider.java
@@ -17,10 +17,8 @@ package top.r3944realms.lib39.base.datagen.provider;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.PackOutput;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.item.Item;
-import net.neoforged.neoforge.client.model.generators.ItemModelProvider;
-import net.neoforged.neoforge.common.data.ExistingFileHelper;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.base.datagen.value.Lib39LangKey;
import top.r3944realms.lib39.datagen.value.LangKeyValue;
@@ -80,7 +78,7 @@ public class Lib39ItemModelProvider extends ItemModelProvider {
* @param item the item
* @param location the location
*/
- public void itemGenerateModel(Item item, ResourceLocation location){
+ public void itemGenerateModel(Item item, Identifier location){
withExistingParent(itemName(item), GENERATED).texture("layer0", location);
}
@@ -90,7 +88,7 @@ public class Lib39ItemModelProvider extends ItemModelProvider {
* @param item the item
* @param location the location
*/
- public void itemHandHeldModel(Item item, ResourceLocation location){
+ public void itemHandHeldModel(Item item, Identifier location){
withExistingParent(itemName(item), HANDHELD).texture("layer0", location);
}
@@ -118,7 +116,7 @@ public class Lib39ItemModelProvider extends ItemModelProvider {
* @param path the path
* @return the resource location
*/
- public ResourceLocation resourceItem(String path){
+ public Identifier resourceItem(String path){
return modLoc("item/" + path);
}
}
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/core/compat/NeoForgeCompatManager.java b/neoforge/src/main/java/top/r3944realms/lib39/core/compat/NeoForgeCompatManager.java
index db2ae86..68f710a 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/core/compat/NeoForgeCompatManager.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/core/compat/NeoForgeCompatManager.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.compat;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.EventBusSubscriber;
@@ -30,7 +30,7 @@ public abstract class NeoForgeCompatManager extends CompatManager compats = new HashMap<>();
+ protected final Map compats = new HashMap<>();
/**
*
* 存储事件监听器配置
@@ -40,7 +40,7 @@ public abstract class NeoForgeCompatManager extends CompatManager listenerConfigs = new ArrayList<>();
@Override
- public Map getCompatMap() {
+ public Map getCompatMap() {
return compats;
}
@@ -51,14 +51,14 @@ public abstract class NeoForgeCompatManager extends CompatManager entry : compats.entrySet()) {
+ for (Map.Entry entry : compats.entrySet()) {
if (!entry.getValue().isInitialized() && entry.getValue().isModLoaded()) {
try {
entry.getValue().initialize();
@@ -178,7 +178,7 @@ public abstract class NeoForgeCompatManager extends CompatManager iSyncManager.foreach(ISyncData::markDirty)));
- syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
+ syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
+ syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
}
/**
@@ -206,7 +206,7 @@ public class CommonEventHandler {
Entity entity = event.getEntity();
if (entity.level().isClientSide) return;
- for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
+ for (Identifier id : syncData2Manager.getRegisteredKeys()) {
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
syncData2Manager.trackEntityForManager(entity, id);
}
@@ -223,7 +223,7 @@ public class CommonEventHandler {
Entity entity = event.getEntity();
if (entity.level().isClientSide) return;
- for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
+ for (Identifier id : syncData2Manager.getRegisteredKeys()) {
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
syncData2Manager.untrackEntityForManager(entity, id);
}
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/core/network/toClient/SyncNBTCapDataEntityS2CPayload.java b/neoforge/src/main/java/top/r3944realms/lib39/core/network/toClient/SyncNBTCapDataEntityS2CPayload.java
index e6b6283..b753b06 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/core/network/toClient/SyncNBTCapDataEntityS2CPayload.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/core/network/toClient/SyncNBTCapDataEntityS2CPayload.java
@@ -7,7 +7,7 @@ import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import net.neoforged.neoforge.network.handling.IPayloadContext;
import org.jetbrains.annotations.Contract;
@@ -25,11 +25,11 @@ import java.util.function.Supplier;
* The type Sync nbt data s 2 c payload.
*/
@SuppressWarnings("unused")
-public record SyncNBTCapDataEntityS2CPayload(int entityId, ResourceLocation id, CompoundTag data) implements CustomPacketPayload {
+public record SyncNBTCapDataEntityS2CPayload(int entityId, Identifier id, CompoundTag data) implements CustomPacketPayload {
/**
* The constant SYNC_NBT_CAP_PACKET_ID.
*/
- public static final ResourceLocation SYNC_NBT_CAP_PACKET_ID =
+ public static final Identifier SYNC_NBT_CAP_PACKET_ID =
Lib39.rl("sync_nbt_cap_data_entity");
/**
* The constant TYPE.
@@ -60,7 +60,7 @@ public record SyncNBTCapDataEntityS2CPayload(int entityId, ResourceLocation id,
*/
public static void encode(@NotNull SyncNBTCapDataEntityS2CPayload msg, @NotNull FriendlyByteBuf buffer) {
buffer.writeInt(msg.entityId);
- buffer.writeResourceLocation(msg.id);
+ buffer.writeIdentifier(msg.id);
buffer.writeNbt(msg.data);
}
@@ -72,7 +72,7 @@ public record SyncNBTCapDataEntityS2CPayload(int entityId, ResourceLocation id,
*/
@Contract("_ -> new")
public static @NotNull SyncNBTCapDataEntityS2CPayload decode(@NotNull FriendlyByteBuf buffer) {
- return new SyncNBTCapDataEntityS2CPayload(buffer.readInt(), buffer.readResourceLocation(), buffer.readNbt());
+ return new SyncNBTCapDataEntityS2CPayload(buffer.readInt(), buffer.readIdentifier(), buffer.readNbt());
}
/**
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/core/sync/SyncCapProvider.java b/neoforge/src/main/java/top/r3944realms/lib39/core/sync/SyncCapProvider.java
index e69dcf8..3e07411 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/core/sync/SyncCapProvider.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/core/sync/SyncCapProvider.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.sync;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import net.neoforged.neoforge.capabilities.ICapabilityProvider;
import org.jetbrains.annotations.Nullable;
@@ -26,7 +26,7 @@ public abstract class SyncCapProvider implements IC
*
* @return 能力 ID
*/
- protected abstract ResourceLocation getId();
+ protected abstract Identifier getId();
@SuppressWarnings("unchecked")
@Override
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/core/sync/SyncData2CapManager.java b/neoforge/src/main/java/top/r3944realms/lib39/core/sync/SyncData2CapManager.java
index 781f1d4..2e32a93 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/core/sync/SyncData2CapManager.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/core/sync/SyncData2CapManager.java
@@ -1,7 +1,7 @@
package top.r3944realms.lib39.core.sync;
import com.google.common.collect.Maps;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.neoforged.neoforge.capabilities.EntityCapability;
import org.jetbrains.annotations.Nullable;
@@ -17,10 +17,10 @@ public class SyncData2CapManager extends SyncData2Manager> typedEntries = Maps.newConcurrentMap();
+ protected final Map> typedEntries = Maps.newConcurrentMap();
@Override
- protected Map> getTypedEntries() {
+ protected Map> getTypedEntries() {
return typedEntries;
}
@@ -50,11 +50,11 @@ public class SyncData2CapManager extends SyncData2Manager> void registerManager(
- ResourceLocation key,
+ Identifier key,
ISyncManager, T> manager,
EntityCapability capability
) {
- Objects.requireNonNull(key, "ResourceLocation key cannot be null");
+ Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(manager, "Sync manager cannot be null");
Objects.requireNonNull(capability, "Capability cannot be null");
@@ -69,8 +69,8 @@ public class SyncData2CapManager extends SyncData2Manager> void bindCapability(ResourceLocation key, EntityCapability capability) {
- Objects.requireNonNull(key, "ResourceLocation key cannot be null");
+ public > void bindCapability(Identifier key, EntityCapability capability) {
+ Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(capability, "Capability cannot be null");
TypedSyncEntry> entry = typedEntries.get(key);
@@ -85,8 +85,8 @@ public class SyncData2CapManager extends SyncData2Manager entry = typedEntries.get(key);
if (entry != null) {
@@ -103,7 +103,7 @@ public class SyncData2CapManager extends SyncData2Manager> void updateCapabilityInEntry(ResourceLocation id, TypedSyncEntry> entry, EntityCapability newCapability) {
+ protected > void updateCapabilityInEntry(Identifier id, TypedSyncEntry> entry, EntityCapability newCapability) {
updateDataProviderInEntry(id, entry, key -> newCapability != null ? Optional.ofNullable(key.getCapability(newCapability)) : Optional.empty());
}
}
\ No newline at end of file
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/datagen/provider/SimpleLootTableProvider.java b/neoforge/src/main/java/top/r3944realms/lib39/datagen/provider/SimpleLootTableProvider.java
index 87e112d..22f950b 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/datagen/provider/SimpleLootTableProvider.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/datagen/provider/SimpleLootTableProvider.java
@@ -5,7 +5,7 @@ import net.minecraft.core.WritableRegistry;
import net.minecraft.data.PackOutput;
import net.minecraft.data.loot.LootTableProvider;
import net.minecraft.resources.ResourceKey;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.util.ProblemReporter;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.ValidationContext;
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/example/compat/Lib39Compat.java b/neoforge/src/main/java/top/r3944realms/lib39/example/compat/Lib39Compat.java
index ff58f97..c695f02 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/example/compat/Lib39Compat.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/example/compat/Lib39Compat.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.example.compat;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModList;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
@@ -23,7 +23,7 @@ public class Lib39Compat implements INeoForgeCompat {
/**
* The constant ID.
*/
- public static ResourceLocation ID = Lib39.rl("lib39");
+ public static Identifier ID = Lib39.rl("lib39");
@Override
public void setInitialize(boolean initialize) {
@@ -36,7 +36,7 @@ public class Lib39Compat implements INeoForgeCompat {
}
@Override
- public ResourceLocation id() {
+ public Identifier id() {
return ID;
}
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/example/content/data/TestSyncCapProvider.java b/neoforge/src/main/java/top/r3944realms/lib39/example/content/data/TestSyncCapProvider.java
index cddef07..5c79342 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/example/content/data/TestSyncCapProvider.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/example/content/data/TestSyncCapProvider.java
@@ -1,6 +1,6 @@
package top.r3944realms.lib39.example.content.data;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.core.sync.SyncCapProvider;
@@ -13,7 +13,7 @@ public class TestSyncCapProvider extends SyncCapProvider
}
@Override
- protected ResourceLocation getId() {
+ protected Identifier getId() {
return Lib39.rl("test_data");
}
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/example/content/data/TestSyncData.java b/neoforge/src/main/java/top/r3944realms/lib39/example/content/data/TestSyncData.java
index 3feee00..6c01baf 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/example/content/data/TestSyncData.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/example/content/data/TestSyncData.java
@@ -2,7 +2,7 @@ package top.r3944realms.lib39.example.content.data;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.Lib39;
@@ -22,7 +22,7 @@ public class TestSyncData extends AbstractedTestSyncData implements INeoForgeUpd
/**
* The constant ID.
*/
- public static final ResourceLocation ID = Lib39.rl(Lib39.MOD_ID, "test_sync_data");
+ public static final Identifier ID = Lib39.rl(Lib39.MOD_ID, "test_sync_data");
// NBT 键常量
private static final String NBT_KEY_STRING = "test_string";
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/example/core/network/toServer/ClientDataPayload.java b/neoforge/src/main/java/top/r3944realms/lib39/example/core/network/toServer/ClientDataPayload.java
index 9ad99bf..a00586c 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/example/core/network/toServer/ClientDataPayload.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/example/core/network/toServer/ClientDataPayload.java
@@ -4,7 +4,7 @@ import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.neoforged.neoforge.network.handling.IPayloadContext;
@@ -21,7 +21,7 @@ public record ClientDataPayload(AbstractedTestSyncData clientData, int targetEnt
/**
* The constant CLIENT_DATA_PACKET_ID.
*/
- public static final ResourceLocation CLIENT_DATA_PACKET_ID =
+ public static final Identifier CLIENT_DATA_PACKET_ID =
Lib39.rl("client_data");
/**
* The constant TYPE.
diff --git a/neoforge/src/main/java/top/r3944realms/lib39/util/EntityCapabilityHelper.java b/neoforge/src/main/java/top/r3944realms/lib39/util/EntityCapabilityHelper.java
index 3c968c2..cb712ee 100644
--- a/neoforge/src/main/java/top/r3944realms/lib39/util/EntityCapabilityHelper.java
+++ b/neoforge/src/main/java/top/r3944realms/lib39/util/EntityCapabilityHelper.java
@@ -1,7 +1,7 @@
package top.r3944realms.lib39.util;
import net.minecraft.core.registries.BuiltInRegistries;
-import net.minecraft.resources.ResourceLocation;
+import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.monster.Monster;
@@ -85,7 +85,7 @@ public class EntityCapabilityHelper {
BuiltInRegistries.ENTITY_TYPE.stream()
.filter(entityType -> {
- ResourceLocation key = BuiltInRegistries.ENTITY_TYPE.getKey(entityType);
+ Identifier key = BuiltInRegistries.ENTITY_TYPE.getKey(entityType);
return namespace.equals(key.getNamespace());
})
.forEach(entityType -> event.registerEntity(capability, entityType, provider));