Compare commits
2 Commits
fe3d3478a9
...
15ab233b04
| Author | SHA1 | Date | |
|---|---|---|---|
| 15ab233b04 | |||
| fe186cd36b |
18
AITask.md
Normal file
18
AITask.md
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# 任务:多平台模组项目迁移(1.21.1 → 26.1.2)
|
||||||
|
|
||||||
|
## 背景
|
||||||
|
我的 Minecraft 模组当前基于 **MultiLoader 1.21.1**(对应 Minecraft 1.21.1)。
|
||||||
|
目标版本为 **26.1.2**(对应 Minecraft 26.1.2)。
|
||||||
|
从 1.21.1 升级到 26.1.x,期间 API 发生了破坏性变更。
|
||||||
|
|
||||||
|
# 请只关注 common、fabric、neoforge文件下的src文件里的java部分
|
||||||
|
其它以外的文件已经配置好了
|
||||||
|
|
||||||
|
## 核心变更参考
|
||||||
|
请参考 项目里的中的迁移指南(Primers):[Doc](/primers-doc)
|
||||||
|
|
||||||
|
特别关注以下版本的变更(按从低到高依次应用):
|
||||||
|
- 1.21 → 1.21.1
|
||||||
|
- 1.21.1 → 1.21.2
|
||||||
|
- 1.21.2 → 1.21.3
|
||||||
|
- 依此类推,直到 26.1.2 对应的版本
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39;
|
package top.r3944realms.lib39;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
@ -48,8 +48,8 @@ public class Lib39 {
|
||||||
* @return the resource location
|
* @return the resource location
|
||||||
*/
|
*/
|
||||||
@Contract("_ -> new")
|
@Contract("_ -> new")
|
||||||
public static @NotNull ResourceLocation rl(String path) {
|
public static @NotNull Identifier rl(String path) {
|
||||||
return ResourceLocation.fromNamespaceAndPath(Lib39.MOD_ID, path);
|
return Identifier.fromNamespaceAndPath(Lib39.MOD_ID, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -60,8 +60,8 @@ public class Lib39 {
|
||||||
* @return the resource location
|
* @return the resource location
|
||||||
*/
|
*/
|
||||||
@Contract("_, _ -> new")
|
@Contract("_, _ -> new")
|
||||||
public static @NotNull ResourceLocation rl(String modId, String path) {
|
public static @NotNull Identifier rl(String modId, String path) {
|
||||||
return ResourceLocation.fromNamespaceAndPath(modId, path);
|
return Identifier.fromNamespaceAndPath(modId, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -71,8 +71,8 @@ public class Lib39 {
|
||||||
* @return the resource location
|
* @return the resource location
|
||||||
*/
|
*/
|
||||||
@Contract("_ -> new")
|
@Contract("_ -> new")
|
||||||
public static @NotNull ResourceLocation mrl(String path) {
|
public static @NotNull Identifier mrl(String path) {
|
||||||
return ResourceLocation.withDefaultNamespace(path);
|
return Identifier.withDefaultNamespace(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.base.command;
|
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.Lib39;
|
||||||
import top.r3944realms.lib39.core.command.SimpleCommandHelpManager;
|
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");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
|
|
@ -31,7 +31,7 @@ public class Lib39CommandHelpManager extends SimpleCommandHelpManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getID() {
|
public Identifier getID() {
|
||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.commands.arguments.EntityArgument;
|
import net.minecraft.commands.arguments.EntityArgument;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import top.r3944realms.lib39.Lib39;
|
import top.r3944realms.lib39.Lib39;
|
||||||
|
|
@ -19,6 +19,7 @@ import top.r3944realms.lib39.core.command.ICommandHelpManager;
|
||||||
import top.r3944realms.lib39.core.command.SimpleHelpCommand;
|
import top.r3944realms.lib39.core.command.SimpleHelpCommand;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
|
|
@ -92,7 +93,7 @@ public class Lib39HelpCommand extends SimpleHelpCommand {
|
||||||
.executes(this::executeCalculate)))
|
.executes(this::executeCalculate)))
|
||||||
)
|
)
|
||||||
.then(Commands.literal("teleport")
|
.then(Commands.literal("teleport")
|
||||||
.requires(source -> source.hasPermission(2)) // 需要OP權限
|
.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)) // 需要游戏管理员權限
|
||||||
.then(Commands.argument("target", EntityArgument.player())
|
.then(Commands.argument("target", EntityArgument.player())
|
||||||
.executes(this::executeTeleport))
|
.executes(this::executeTeleport))
|
||||||
)
|
)
|
||||||
|
|
@ -284,12 +285,14 @@ public class Lib39HelpCommand extends SimpleHelpCommand {
|
||||||
|
|
||||||
if (source.getEntity() instanceof ServerPlayer player) {
|
if (source.getEntity() instanceof ServerPlayer player) {
|
||||||
player.teleportTo(
|
player.teleportTo(
|
||||||
target.serverLevel(),
|
target.level(),
|
||||||
target.getX(),
|
target.getX(),
|
||||||
target.getY(),
|
target.getY(),
|
||||||
target.getZ(),
|
target.getZ(),
|
||||||
|
Set.of(),
|
||||||
target.getYRot(),
|
target.getYRot(),
|
||||||
target.getXRot()
|
target.getXRot(),
|
||||||
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
source.sendSuccess(() ->
|
source.sendSuccess(() ->
|
||||||
|
|
@ -304,7 +307,7 @@ public class Lib39HelpCommand extends SimpleHelpCommand {
|
||||||
|
|
||||||
private int executeInfo(CommandContext<CommandSourceStack> context) {
|
private int executeInfo(CommandContext<CommandSourceStack> context) {
|
||||||
CommandSourceStack source = context.getSource();
|
CommandSourceStack source = context.getSource();
|
||||||
ResourceLocation dimension = source.getLevel().dimension().location();
|
Identifier dimension = source.getLevel().dimension().identifier();
|
||||||
|
|
||||||
source.sendSuccess(() ->
|
source.sendSuccess(() ->
|
||||||
Component.translatable("commands.lib39.info.message")
|
Component.translatable("commands.lib39.info.message")
|
||||||
|
|
|
||||||
|
|
@ -19,16 +19,16 @@ public class Lib39RecipeProvider extends RecipeProvider {
|
||||||
* @param output the output
|
* @param output the output
|
||||||
* @param registries the registries
|
* @param registries the registries
|
||||||
*/
|
*/
|
||||||
public Lib39RecipeProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) {
|
public Lib39RecipeProvider(HolderLookup.Provider output, RecipeOutput recipeOutput) {
|
||||||
super(output, registries);
|
super(output, recipeOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buildRecipes(RecipeOutput recipeOutput) {
|
protected void buildRecipes() {
|
||||||
ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, Lib39Items.DOLL.get())
|
this.shapeless(RecipeCategory.MISC, Lib39Items.DOLL.get())
|
||||||
.requires(ItemTags.WOOL)
|
.requires(ItemTags.WOOL)
|
||||||
.requires(Items.ARMOR_STAND)
|
.requires(Items.ARMOR_STAND)
|
||||||
.unlockedBy("has_armor_stand",has(Items.ARMOR_STAND))
|
.unlockedBy("has_armor_stand",has(Items.ARMOR_STAND))
|
||||||
.save(recipeOutput);
|
.save(this.output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package top.r3944realms.lib39.client.gui.component;
|
||||||
import com.mojang.blaze3d.platform.Window;
|
import com.mojang.blaze3d.platform.Window;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.*;
|
import com.mojang.blaze3d.vertex.*;
|
||||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.components.AbstractWidget;
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
|
|
@ -12,6 +11,7 @@ import net.minecraft.client.renderer.ShaderInstance;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2f;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
import top.r3944realms.lib39.client.shader.Lib39Shaders;
|
import top.r3944realms.lib39.client.shader.Lib39Shaders;
|
||||||
import top.r3944realms.lib39.util.MathUtil;
|
import top.r3944realms.lib39.util.MathUtil;
|
||||||
import top.r3944realms.lib39.util.lang.FourConsumer;
|
import top.r3944realms.lib39.util.lang.FourConsumer;
|
||||||
|
|
@ -681,7 +681,7 @@ public class WheelWidget extends AbstractWidget {
|
||||||
* @param radius the radius
|
* @param radius the radius
|
||||||
*/
|
*/
|
||||||
public static void renderSelectionEffect(
|
public static void renderSelectionEffect(
|
||||||
GuiGraphics guiGraphics,
|
@NonNull GuiGraphics guiGraphics,
|
||||||
float centerX,
|
float centerX,
|
||||||
float centerY,
|
float centerY,
|
||||||
int color,
|
int color,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package top.r3944realms.lib39.client.model;
|
package top.r3944realms.lib39.client.model;
|
||||||
|
|
||||||
import net.minecraft.client.model.geom.PartPose;
|
import net.minecraft.client.model.geom.PartPose;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import top.r3944realms.lib39.Lib39;
|
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)
|
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 Vec3 offset;
|
||||||
private final PartPose headPose;
|
private final PartPose headPose;
|
||||||
private final PartPose bodyPose;
|
private final PartPose bodyPose;
|
||||||
|
|
@ -52,7 +52,7 @@ public enum DollPoses implements IDollPose{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ResourceLocation getId() {
|
public @NotNull Identifier getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package top.r3944realms.lib39.client.model;
|
package top.r3944realms.lib39.client.model;
|
||||||
|
|
||||||
import net.minecraft.client.model.geom.PartPose;
|
import net.minecraft.client.model.geom.PartPose;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@ public interface IDollPose {
|
||||||
*
|
*
|
||||||
* @return the id
|
* @return the id
|
||||||
*/
|
*/
|
||||||
@NotNull ResourceLocation getId();
|
@NotNull Identifier getId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets total offset.
|
* Gets total offset.
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||||
import net.minecraft.client.resources.PlayerSkin;
|
import net.minecraft.client.resources.PlayerSkin;
|
||||||
import net.minecraft.client.resources.SkinManager;
|
import net.minecraft.client.resources.SkinManager;
|
||||||
import net.minecraft.core.Direction;
|
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.item.component.ResolvableProfile;
|
||||||
import net.minecraft.world.level.block.SkullBlock;
|
import net.minecraft.world.level.block.SkullBlock;
|
||||||
import net.minecraft.world.level.block.WallSkullBlock;
|
import net.minecraft.world.level.block.WallSkullBlock;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||||
import net.minecraft.client.resources.PlayerSkin;
|
import net.minecraft.client.resources.PlayerSkin;
|
||||||
import net.minecraft.client.resources.SkinManager;
|
import net.minecraft.client.resources.SkinManager;
|
||||||
import net.minecraft.core.component.DataComponents;
|
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.ItemDisplayContext;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.component.ResolvableProfile;
|
import net.minecraft.world.item.component.ResolvableProfile;
|
||||||
|
|
@ -75,7 +75,7 @@ public class DollItemRenderer extends BlockEntityWithoutLevelRenderer {
|
||||||
|
|
||||||
// 直接从 DataComponents.PROFILE 获取 ResolvableProfile
|
// 直接从 DataComponents.PROFILE 获取 ResolvableProfile
|
||||||
ResolvableProfile profile = stack.get(DataComponents.PROFILE);
|
ResolvableProfile profile = stack.get(DataComponents.PROFILE);
|
||||||
Pair<ResourceLocation, PlayerSkin.Model> skinInfo = getSkinInfo(profile);
|
Pair<Identifier, PlayerSkin.Model> skinInfo = getSkinInfo(profile);
|
||||||
|
|
||||||
poseStack.pushPose();
|
poseStack.pushPose();
|
||||||
VertexConsumer vertexConsumer = buffer.getBuffer(RenderType.entityTranslucent(skinInfo.first));
|
VertexConsumer vertexConsumer = buffer.getBuffer(RenderType.entityTranslucent(skinInfo.first));
|
||||||
|
|
@ -93,7 +93,7 @@ public class DollItemRenderer extends BlockEntityWithoutLevelRenderer {
|
||||||
/**
|
/**
|
||||||
* 获取皮肤纹理和模型类型(1.21+ 版本)
|
* 获取皮肤纹理和模型类型(1.21+ 版本)
|
||||||
*/
|
*/
|
||||||
public static @NotNull Pair<ResourceLocation, PlayerSkin.Model> getSkinInfo(@NotNull ResolvableProfile profile) {
|
public static @NotNull Pair<Identifier, PlayerSkin.Model> getSkinInfo(@NotNull ResolvableProfile profile) {
|
||||||
SkinManager skinManager = Minecraft.getInstance().getSkinManager();
|
SkinManager skinManager = Minecraft.getInstance().getSkinManager();
|
||||||
|
|
||||||
if (profile != null && profile.gameProfile() != null) {
|
if (profile != null && profile.gameProfile() != null) {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package top.r3944realms.lib39.core.command;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.network.chat.*;
|
import net.minecraft.network.chat.*;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import top.r3944realms.lib39.base.datagen.value.Lib39LangKey;
|
import top.r3944realms.lib39.base.datagen.value.Lib39LangKey;
|
||||||
|
|
@ -31,7 +31,7 @@ public interface ICommandHelpManager {
|
||||||
*
|
*
|
||||||
* @return the id
|
* @return the id
|
||||||
*/
|
*/
|
||||||
ResourceLocation getID();
|
Identifier getID();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets head key.
|
* Gets head key.
|
||||||
|
|
@ -291,12 +291,10 @@ public interface ICommandHelpManager {
|
||||||
return Component.literal(rootCommand)
|
return Component.literal(rootCommand)
|
||||||
.withStyle(ChatFormatting.AQUA)
|
.withStyle(ChatFormatting.AQUA)
|
||||||
.withStyle(Style.EMPTY
|
.withStyle(Style.EMPTY
|
||||||
.withClickEvent(new ClickEvent(
|
.withClickEvent(new ClickEvent.SuggestCommand(
|
||||||
ClickEvent.Action.SUGGEST_COMMAND,
|
|
||||||
rootCommand + " "
|
rootCommand + " "
|
||||||
))
|
))
|
||||||
.withHoverEvent(new HoverEvent(
|
.withHoverEvent(new HoverEvent.ShowText(
|
||||||
HoverEvent.Action.SHOW_TEXT,
|
|
||||||
Component.translatable(Lib39LangKey.Message.HELP_HOVER_COPY_TIP.getKey())
|
Component.translatable(Lib39LangKey.Message.HELP_HOVER_COPY_TIP.getKey())
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
|
|
@ -316,12 +314,10 @@ public interface ICommandHelpManager {
|
||||||
MutableComponent commandName = Component.literal(node.getName())
|
MutableComponent commandName = Component.literal(node.getName())
|
||||||
.withStyle(ChatFormatting.DARK_AQUA)
|
.withStyle(ChatFormatting.DARK_AQUA)
|
||||||
.withStyle(Style.EMPTY
|
.withStyle(Style.EMPTY
|
||||||
.withClickEvent(new ClickEvent(
|
.withClickEvent(new ClickEvent.SuggestCommand(
|
||||||
ClickEvent.Action.SUGGEST_COMMAND,
|
|
||||||
suggestedCommand
|
suggestedCommand
|
||||||
))
|
))
|
||||||
.withHoverEvent(new HoverEvent(
|
.withHoverEvent(new HoverEvent.ShowText(
|
||||||
HoverEvent.Action.SHOW_TEXT,
|
|
||||||
Component.translatable(Lib39LangKey.Message.HELP_HOVER_COPY_TIP.getKey(), suggestedCommand)
|
Component.translatable(Lib39LangKey.Message.HELP_HOVER_COPY_TIP.getKey(), suggestedCommand)
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
|
|
@ -370,12 +366,10 @@ public interface ICommandHelpManager {
|
||||||
|
|
||||||
// 为按钮添加点击事件
|
// 为按钮添加点击事件
|
||||||
toggleButton.withStyle(Style.EMPTY
|
toggleButton.withStyle(Style.EMPTY
|
||||||
.withClickEvent(new ClickEvent(
|
.withClickEvent(new ClickEvent.RunCommand(
|
||||||
ClickEvent.Action.RUN_COMMAND,
|
|
||||||
"/" + getCommandHead() + " help toggle " + node.hashCode()
|
"/" + getCommandHead() + " help toggle " + node.hashCode()
|
||||||
))
|
))
|
||||||
.withHoverEvent(new HoverEvent(
|
.withHoverEvent(new HoverEvent.ShowText(
|
||||||
HoverEvent.Action.SHOW_TEXT,
|
|
||||||
Component.translatable(Lib39LangKey.Message.HELP_CLICK_EXPAND.getKey())
|
Component.translatable(Lib39LangKey.Message.HELP_CLICK_EXPAND.getKey())
|
||||||
.withStyle(ChatFormatting.GRAY)
|
.withStyle(ChatFormatting.GRAY)
|
||||||
))
|
))
|
||||||
|
|
@ -467,11 +461,12 @@ public interface ICommandHelpManager {
|
||||||
).withStyle(ChatFormatting.GRAY));
|
).withStyle(ChatFormatting.GRAY));
|
||||||
|
|
||||||
collapsedInfo.withStyle(Style.EMPTY
|
collapsedInfo.withStyle(Style.EMPTY
|
||||||
.withClickEvent(new ClickEvent(
|
.withClickEvent(new ClickEvent.RunCommand(
|
||||||
ClickEvent.Action.RUN_COMMAND,
|
|
||||||
"/" + getCommandHead() + " help toggle " + node.hashCode()
|
"/" + getCommandHead() + " help toggle " + node.hashCode()
|
||||||
))
|
))
|
||||||
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.translatable(Lib39LangKey.Message.HELP_CLICK_EXPAND.getKey())))
|
.withHoverEvent(new HoverEvent.ShowText(
|
||||||
|
Component.translatable(Lib39LangKey.Message.HELP_CLICK_EXPAND.getKey())
|
||||||
|
))
|
||||||
);
|
);
|
||||||
|
|
||||||
result.add(collapsedInfo.append(Component.literal(NEWLINE)));
|
result.add(collapsedInfo.append(Component.literal(NEWLINE)));
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.core.command;
|
package top.r3944realms.lib39.core.command;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import top.r3944realms.lib39.core.command.model.CommandNode;
|
import top.r3944realms.lib39.core.command.model.CommandNode;
|
||||||
import top.r3944realms.lib39.core.command.model.Parameter;
|
import top.r3944realms.lib39.core.command.model.Parameter;
|
||||||
|
|
@ -28,7 +28,7 @@ public abstract class SimpleCommandHelpManager implements ICommandHelpManager {
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
// 現在子類的字段已經初始化完成
|
// 現在子類的字段已經初始化完成
|
||||||
ResourceLocation id = getID();
|
Identifier id = getID();
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
throw new IllegalStateException("getID() must return non-null");
|
throw new IllegalStateException("getID() must return non-null");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.core.compat;
|
package top.r3944realms.lib39.core.compat;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
@ -22,7 +22,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
||||||
* @return the id
|
* @return the id
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getId() {
|
public Identifier getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,7 +33,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
||||||
/**
|
/**
|
||||||
* The Id.
|
* The Id.
|
||||||
*/
|
*/
|
||||||
protected final ResourceLocation id;
|
protected final Identifier id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Initialized.
|
* The Initialized.
|
||||||
|
|
@ -58,7 +58,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
||||||
*
|
*
|
||||||
* @param id the id
|
* @param id the id
|
||||||
*/
|
*/
|
||||||
public CompatManager(@NotNull ResourceLocation id) {
|
public CompatManager(@NotNull Identifier id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.logger = LoggerFactory.getLogger(id.toString());
|
this.logger = LoggerFactory.getLogger(id.toString());
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +70,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
||||||
* @param compat the compat
|
* @param compat the compat
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void registerCompat(ResourceLocation id, C compat) {
|
public void registerCompat(Identifier id, C compat) {
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
// 已初始化,直接注册
|
// 已初始化,直接注册
|
||||||
doRegisterCompat(id, compat);
|
doRegisterCompat(id, compat);
|
||||||
|
|
@ -87,7 +87,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
||||||
* @param id the id
|
* @param id the id
|
||||||
* @param compat the compat
|
* @param compat the compat
|
||||||
*/
|
*/
|
||||||
protected void doRegisterCompat(ResourceLocation id, C compat) {
|
protected void doRegisterCompat(Identifier id, C compat) {
|
||||||
if (getCompatMap().containsKey(id)) {
|
if (getCompatMap().containsKey(id)) {
|
||||||
logger.warn("Compat with id {} is already registered!", id);
|
logger.warn("Compat with id {} is already registered!", id);
|
||||||
return;
|
return;
|
||||||
|
|
@ -122,7 +122,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
||||||
pendingTasks.clear();
|
pendingTasks.clear();
|
||||||
|
|
||||||
// 初始化所有兼容模块
|
// 初始化所有兼容模块
|
||||||
for (Map.Entry<ResourceLocation, C> entry : getCompatMap().entrySet()) {
|
for (Map.Entry<Identifier, C> entry : getCompatMap().entrySet()) {
|
||||||
if (!entry.getValue().isInitialized() && entry.getValue().isModLoaded()) {
|
if (!entry.getValue().isInitialized() && entry.getValue().isModLoaded()) {
|
||||||
try {
|
try {
|
||||||
entry.getValue().initialize();
|
entry.getValue().initialize();
|
||||||
|
|
@ -143,7 +143,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
||||||
* @return the compat
|
* @return the compat
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Optional<C> getCompat(ResourceLocation id) {
|
public Optional<C> getCompat(Identifier id) {
|
||||||
return Optional.ofNullable(getCompatMap().get(id));
|
return Optional.ofNullable(getCompatMap().get(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,7 +154,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
||||||
* @return the boolean
|
* @return the boolean
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCompat(ResourceLocation id) {
|
public boolean hasCompat(Identifier id) {
|
||||||
return getCompatMap().containsKey(id);
|
return getCompatMap().containsKey(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,7 +164,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
||||||
* @param id the id
|
* @param id the id
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void unregisterCompat(ResourceLocation id) {
|
public void unregisterCompat(Identifier id) {
|
||||||
C removed = getCompatMap().remove(id);
|
C removed = getCompatMap().remove(id);
|
||||||
if (removed != null) {
|
if (removed != null) {
|
||||||
logger.debug("Unregistered compat: {}", id);
|
logger.debug("Unregistered compat: {}", id);
|
||||||
|
|
@ -187,7 +187,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
||||||
*/
|
*/
|
||||||
public void onLoadComplete() {
|
public void onLoadComplete() {
|
||||||
logger.info("Calling onLoadComplete for {} compatibility modules", getCompatMap().size());
|
logger.info("Calling onLoadComplete for {} compatibility modules", getCompatMap().size());
|
||||||
for (Map.Entry<ResourceLocation, C> entry : getCompatMap().entrySet()) {
|
for (Map.Entry<Identifier, C> entry : getCompatMap().entrySet()) {
|
||||||
try {
|
try {
|
||||||
entry.getValue().onLoadComplete();
|
entry.getValue().onLoadComplete();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.core.compat;
|
package top.r3944realms.lib39.core.compat;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
|
@ -27,7 +27,7 @@ public interface ICompat {
|
||||||
*
|
*
|
||||||
* @return the resource location
|
* @return the resource location
|
||||||
*/
|
*/
|
||||||
ResourceLocation id();
|
Identifier id();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize.
|
* Initialize.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.core.compat;
|
package top.r3944realms.lib39.core.compat;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -16,14 +16,14 @@ public interface ICompatManager<C extends ICompat> {
|
||||||
*
|
*
|
||||||
* @return the id
|
* @return the id
|
||||||
*/
|
*/
|
||||||
ResourceLocation getId();
|
Identifier getId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets compat map.
|
* Gets compat map.
|
||||||
*
|
*
|
||||||
* @return the compat map
|
* @return the compat map
|
||||||
*/
|
*/
|
||||||
Map<ResourceLocation, C> getCompatMap();
|
Map<Identifier, C> getCompatMap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize.
|
* Initialize.
|
||||||
|
|
@ -36,7 +36,7 @@ public interface ICompatManager<C extends ICompat> {
|
||||||
* @param id the id
|
* @param id the id
|
||||||
* @param compat the compat
|
* @param compat the compat
|
||||||
*/
|
*/
|
||||||
void registerCompat(ResourceLocation id, C compat);
|
void registerCompat(Identifier id, C compat);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register compat.
|
* Register compat.
|
||||||
|
|
@ -53,7 +53,7 @@ public interface ICompatManager<C extends ICompat> {
|
||||||
* @param id the id
|
* @param id the id
|
||||||
* @return the compat
|
* @return the compat
|
||||||
*/
|
*/
|
||||||
Optional<C> getCompat(ResourceLocation id);
|
Optional<C> getCompat(Identifier id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Has compat boolean.
|
* Has compat boolean.
|
||||||
|
|
@ -61,12 +61,12 @@ public interface ICompatManager<C extends ICompat> {
|
||||||
* @param id the id
|
* @param id the id
|
||||||
* @return the boolean
|
* @return the boolean
|
||||||
*/
|
*/
|
||||||
boolean hasCompat(ResourceLocation id);
|
boolean hasCompat(Identifier id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregister compat.
|
* Unregister compat.
|
||||||
*
|
*
|
||||||
* @param id the id
|
* @param id the id
|
||||||
*/
|
*/
|
||||||
void unregisterCompat(ResourceLocation id);
|
void unregisterCompat(Identifier id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.core.compat;
|
package top.r3944realms.lib39.core.compat;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -13,19 +13,19 @@ public class SimpleCompatManager extends CompatManager<ICompat> {
|
||||||
/**
|
/**
|
||||||
* The Compats.
|
* The Compats.
|
||||||
*/
|
*/
|
||||||
Map<ResourceLocation, ICompat> compats = new HashMap<>();
|
Map<Identifier, ICompat> compats = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Compat manager.
|
* Instantiates a new Compat manager.
|
||||||
*
|
*
|
||||||
* @param id the id
|
* @param id the id
|
||||||
*/
|
*/
|
||||||
public SimpleCompatManager(@NotNull ResourceLocation id) {
|
public SimpleCompatManager(@NotNull Identifier id) {
|
||||||
super(id);
|
super(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<ResourceLocation, ICompat> getCompatMap() {
|
public Map<Identifier, ICompat> getCompatMap() {
|
||||||
return compats;
|
return compats;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.core.register;
|
package top.r3944realms.lib39.core.register;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import top.r3944realms.lib39.Lib39;
|
import top.r3944realms.lib39.Lib39;
|
||||||
|
|
||||||
|
|
@ -13,7 +13,7 @@ public class Lib39SoundEvents {
|
||||||
/**
|
/**
|
||||||
* The constant RL_DUCK_TOY.
|
* 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.
|
* The constant DUCK_TOY.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,12 @@ package top.r3944realms.lib39.core.sync;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.level.storage.ValueInput;
|
||||||
|
import net.minecraft.world.level.storage.ValueOutput;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Lib 39 sync data holder.
|
* The interface Lib 39 sync data holder.
|
||||||
*/
|
*/
|
||||||
|
|
@ -26,24 +30,25 @@ public interface ILib39SyncDataHolder {
|
||||||
/**
|
/**
|
||||||
* Lib 39 inject save sync data compound tag.
|
* Lib 39 inject save sync data compound tag.
|
||||||
*
|
*
|
||||||
* @param tag the tag
|
* @param output the tag
|
||||||
* @return the compound tag
|
|
||||||
*/
|
*/
|
||||||
default CompoundTag lib39$injectSaveSyncData(CompoundTag tag) {
|
default void lib39$injectSaveSyncData(ValueOutput output) {
|
||||||
if (lib39$getSyncData() != null && !lib39$getSyncData().isEmpty()) {
|
if (lib39$getSyncData() != null && !lib39$getSyncData().isEmpty()) {
|
||||||
tag.put("Lib39Data", lib39$getSyncData());
|
output.store("Lib39Data", CompoundTag.CODEC, lib39$getSyncData());
|
||||||
}
|
}
|
||||||
return tag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lib 39 inject load sync data.
|
* Lib 39 inject load sync data.
|
||||||
*
|
*
|
||||||
* @param tag the tag
|
* @param input the input
|
||||||
*/
|
*/
|
||||||
default void lib39$injectLoadSyncData(@NotNull CompoundTag tag) {
|
default void lib39$injectLoadSyncData(@NotNull ValueInput input) {
|
||||||
if (tag.contains("Lib39Data", Tag.TAG_COMPOUND)) {
|
Optional<ValueInput> lib39DataOpt = input.child("Lib39Data");
|
||||||
lib39$setSyncData(tag.getCompound("Lib39Data"));
|
if (lib39DataOpt.isPresent()) {
|
||||||
|
ValueInput valueInput = lib39DataOpt.get();
|
||||||
|
Optional<CompoundTag> lib39Data = valueInput.read("Lib39Data", CompoundTag.CODEC);
|
||||||
|
lib39$setSyncData(lib39Data.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,7 +68,10 @@ public interface ILib39SyncDataHolder {
|
||||||
*/
|
*/
|
||||||
default void loadSyncData(NBTEntitySyncData syncData) {
|
default void loadSyncData(NBTEntitySyncData syncData) {
|
||||||
if (syncData != null && lib39$getSyncData().contains(syncData.id.toDebugFileName())) {
|
if (syncData != null && lib39$getSyncData().contains(syncData.id.toDebugFileName())) {
|
||||||
syncData.deserializeNBT(lib39$getSyncData().getCompound(syncData.id.toDebugFileName()));
|
Optional<CompoundTag> compound = lib39$getSyncData().getCompound(syncData.id.toDebugFileName());
|
||||||
|
if (compound.isPresent()) {
|
||||||
|
syncData.deserializeNBT(compound.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.core.sync;
|
package top.r3944realms.lib39.core.sync;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Sync data.
|
* The interface Sync data.
|
||||||
|
|
@ -13,7 +13,7 @@ public interface ISyncData<T> {
|
||||||
*
|
*
|
||||||
* @return the resource location
|
* @return the resource location
|
||||||
*/
|
*/
|
||||||
ResourceLocation id();
|
Identifier id();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is dirty boolean.
|
* Is dirty boolean.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package top.r3944realms.lib39.core.sync;
|
package top.r3944realms.lib39.core.sync;
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -15,19 +15,19 @@ public abstract class NBTEntitySyncData implements IEntity, ISyncData<NBTEntityS
|
||||||
/**
|
/**
|
||||||
* The Id.
|
* The Id.
|
||||||
*/
|
*/
|
||||||
protected final ResourceLocation id;
|
protected final Identifier id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Nbt sync data.
|
* Instantiates a new Nbt sync data.
|
||||||
*
|
*
|
||||||
* @param id the id
|
* @param id the id
|
||||||
*/
|
*/
|
||||||
protected NBTEntitySyncData(ResourceLocation id) {
|
protected NBTEntitySyncData(Identifier id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation id() {
|
public Identifier id() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package top.r3944realms.lib39.core.sync;
|
package top.r3944realms.lib39.core.sync;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
@ -22,7 +22,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
*
|
*
|
||||||
* @return the typed entries
|
* @return the typed entries
|
||||||
*/
|
*/
|
||||||
protected abstract Map<ResourceLocation, V> getTypedEntries();
|
protected abstract Map<Identifier, V> getTypedEntries();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据提供者接口 - 用于通过键获取数据
|
* 数据提供者接口 - 用于通过键获取数据
|
||||||
|
|
@ -86,11 +86,11 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <K, T extends ISyncData<?>> void registerManagerWithProvider(
|
public <K, T extends ISyncData<?>> void registerManagerWithProvider(
|
||||||
ResourceLocation key,
|
Identifier key,
|
||||||
ISyncManager<K, T> manager,
|
ISyncManager<K, T> manager,
|
||||||
DataProvider<Entity, T> dataProvider
|
DataProvider<Entity, T> 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(manager, "Sync manager cannot be null");
|
||||||
Objects.requireNonNull(dataProvider, "Data provider cannot be null");
|
Objects.requireNonNull(dataProvider, "Data provider cannot be null");
|
||||||
|
|
||||||
|
|
@ -108,11 +108,11 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <K, T extends ISyncData<?>> void registerManager(
|
public <K, T extends ISyncData<?>> void registerManager(
|
||||||
ResourceLocation key,
|
Identifier key,
|
||||||
ISyncManager<K, T> manager,
|
ISyncManager<K, T> manager,
|
||||||
Function<Entity, Optional<T>> getter
|
Function<Entity, Optional<T>> 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(manager, "Sync manager cannot be null");
|
||||||
Objects.requireNonNull(getter, "Data getter function cannot be null");
|
Objects.requireNonNull(getter, "Data getter function cannot be null");
|
||||||
|
|
||||||
|
|
@ -126,8 +126,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
* @param manager the manager
|
* @param manager the manager
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void registerManager(ResourceLocation key, ISyncManager<?, ? extends ISyncData<?>> manager) {
|
public void registerManager(Identifier key, ISyncManager<?, ? extends ISyncData<?>> manager) {
|
||||||
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(manager, "Sync manager cannot be null");
|
||||||
|
|
||||||
// 创建一个没有数据提供者的 TypedSyncEntry
|
// 创建一个没有数据提供者的 TypedSyncEntry
|
||||||
|
|
@ -146,7 +146,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
* @return the manager
|
* @return the manager
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <K, T extends ISyncData<?>> Optional<ISyncManager<K, T>> getManager(ResourceLocation key) {
|
public <K, T extends ISyncData<?>> Optional<ISyncManager<K, T>> getManager(Identifier key) {
|
||||||
TypedSyncEntry<?,?> entry = getTypedEntries().get(key);
|
TypedSyncEntry<?,?> entry = getTypedEntries().get(key);
|
||||||
return entry != null ? Optional.of((ISyncManager<K,T>) entry.manager) : Optional.empty();
|
return entry != null ? Optional.of((ISyncManager<K,T>) entry.manager) : Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
@ -159,7 +159,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
* @return the data provider
|
* @return the data provider
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends ISyncData<?>> Optional<DataProvider<Entity, T>> getDataProvider(ResourceLocation key) {
|
public <T extends ISyncData<?>> Optional<DataProvider<Entity, T>> getDataProvider(Identifier key) {
|
||||||
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
||||||
if (entry != null && entry.dataProvider != null) {
|
if (entry != null && entry.dataProvider != null) {
|
||||||
return Optional.of((DataProvider<Entity, T>) entry.dataProvider);
|
return Optional.of((DataProvider<Entity, T>) entry.dataProvider);
|
||||||
|
|
@ -176,7 +176,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
* @return the entity data
|
* @return the entity data
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends ISyncData<?>> Optional<T> getEntityData(ResourceLocation key, Entity entity) {
|
public <T extends ISyncData<?>> Optional<T> getEntityData(Identifier key, Entity entity) {
|
||||||
return getDataProvider(key)
|
return getDataProvider(key)
|
||||||
.flatMap(provider -> {
|
.flatMap(provider -> {
|
||||||
Optional<ISyncData<?>> result = provider.getData(entity);
|
Optional<ISyncData<?>> result = provider.getData(entity);
|
||||||
|
|
@ -190,8 +190,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param classes the classes
|
* @param classes the classes
|
||||||
*/
|
*/
|
||||||
public final void allowEntityClass(ResourceLocation key, Class<?>... classes) {
|
public final void allowEntityClass(Identifier key, Class<?>... classes) {
|
||||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||||
Objects.requireNonNull(classes, "Classes array cannot be null");
|
Objects.requireNonNull(classes, "Classes array cannot be null");
|
||||||
|
|
||||||
if (classes.length == 0) {
|
if (classes.length == 0) {
|
||||||
|
|
@ -210,8 +210,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param classes the classes
|
* @param classes the classes
|
||||||
*/
|
*/
|
||||||
public final void disallowEntityClass(ResourceLocation key, Class<?>... classes) {
|
public final void disallowEntityClass(Identifier key, Class<?>... classes) {
|
||||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||||
Objects.requireNonNull(classes, "Classes array cannot be null");
|
Objects.requireNonNull(classes, "Classes array cannot be null");
|
||||||
|
|
||||||
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
||||||
|
|
@ -227,8 +227,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param dataProvider the data provider
|
* @param dataProvider the data provider
|
||||||
*/
|
*/
|
||||||
public <T extends ISyncData<?>> void bindDataProvider(ResourceLocation key, DataProvider<Entity, T> dataProvider) {
|
public <T extends ISyncData<?>> void bindDataProvider(Identifier key, DataProvider<Entity, T> dataProvider) {
|
||||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||||
Objects.requireNonNull(dataProvider, "Data provider cannot be null");
|
Objects.requireNonNull(dataProvider, "Data provider cannot be null");
|
||||||
|
|
||||||
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
||||||
|
|
@ -247,7 +247,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param getter the data getter function
|
* @param getter the data getter function
|
||||||
*/
|
*/
|
||||||
public <T extends ISyncData<?>> void bindDataGetter(ResourceLocation key, @NotNull Function<Entity, Optional<T>> getter) {
|
public <T extends ISyncData<?>> void bindDataGetter(Identifier key, @NotNull Function<Entity, Optional<T>> getter) {
|
||||||
bindDataProvider(key, getter::apply);
|
bindDataProvider(key, getter::apply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -256,8 +256,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
*/
|
*/
|
||||||
public void unbindDataProvider(ResourceLocation key) {
|
public void unbindDataProvider(Identifier key) {
|
||||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||||
|
|
||||||
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
|
|
@ -271,8 +271,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
*/
|
*/
|
||||||
public void clearAllowedEntityClasses(ResourceLocation key) {
|
public void clearAllowedEntityClasses(Identifier key) {
|
||||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||||
|
|
||||||
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
|
|
@ -287,8 +287,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
* @param entityClass the entity class
|
* @param entityClass the entity class
|
||||||
* @return the boolean
|
* @return the boolean
|
||||||
*/
|
*/
|
||||||
public boolean isEntityClassAllowed(ResourceLocation key, Class<?> entityClass) {
|
public boolean isEntityClassAllowed(Identifier key, Class<?> entityClass) {
|
||||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||||
Objects.requireNonNull(entityClass, "Entity class cannot be null");
|
Objects.requireNonNull(entityClass, "Entity class cannot be null");
|
||||||
|
|
||||||
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
||||||
|
|
@ -311,7 +311,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
* @param managerId the manager id
|
* @param managerId the manager id
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void trackEntityForManager(Entity entity, ResourceLocation managerId) {
|
public void trackEntityForManager(Entity entity, Identifier managerId) {
|
||||||
TypedSyncEntry<UUID, ?> entry = (TypedSyncEntry<UUID, ?>) getTypedEntries().get(managerId);
|
TypedSyncEntry<UUID, ?> entry = (TypedSyncEntry<UUID, ?>) getTypedEntries().get(managerId);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
trackEntityWithTypedEntry(entity, entry);
|
trackEntityWithTypedEntry(entity, entry);
|
||||||
|
|
@ -332,7 +332,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
* @param managerId the manager id
|
* @param managerId the manager id
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void untrackEntityForManager(Entity entity, ResourceLocation managerId) {
|
public void untrackEntityForManager(Entity entity, Identifier managerId) {
|
||||||
TypedSyncEntry<UUID, ?> entry = (TypedSyncEntry<UUID, ?>) getTypedEntries().get(managerId);
|
TypedSyncEntry<UUID, ?> entry = (TypedSyncEntry<UUID, ?>) getTypedEntries().get(managerId);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
untrackEntityWithTypedEntry(entity, entry);
|
untrackEntityWithTypedEntry(entity, entry);
|
||||||
|
|
@ -352,7 +352,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
* @param entity the entity
|
* @param entity the entity
|
||||||
*/
|
*/
|
||||||
public void untrackEntityFromAllManagers(Entity entity) {
|
public void untrackEntityFromAllManagers(Entity entity) {
|
||||||
for (ResourceLocation id : getRegisteredKeys()) {
|
for (Identifier id : getRegisteredKeys()) {
|
||||||
if (isEntityClassAllowed(id, entity.getClass())) {
|
if (isEntityClassAllowed(id, entity.getClass())) {
|
||||||
untrackEntityForManager(entity, id);
|
untrackEntityForManager(entity, id);
|
||||||
}
|
}
|
||||||
|
|
@ -365,7 +365,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
* @param entities the entities
|
* @param entities the entities
|
||||||
* @param managerId the manager id
|
* @param managerId the manager id
|
||||||
*/
|
*/
|
||||||
public void untrackEntitiesForManager(@NotNull Iterable<Entity> entities, ResourceLocation managerId) {
|
public void untrackEntitiesForManager(@NotNull Iterable<Entity> entities, Identifier managerId) {
|
||||||
for (Entity entity : entities) {
|
for (Entity entity : entities) {
|
||||||
untrackEntityForManager(entity, managerId);
|
untrackEntityForManager(entity, managerId);
|
||||||
}
|
}
|
||||||
|
|
@ -387,7 +387,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
*
|
*
|
||||||
* @param managerId the manager id
|
* @param managerId the manager id
|
||||||
*/
|
*/
|
||||||
public void clearAllTrackedData(ResourceLocation managerId) {
|
public void clearAllTrackedData(Identifier managerId) {
|
||||||
TypedSyncEntry<?, ?> entry = getTypedEntries().get(managerId);
|
TypedSyncEntry<?, ?> entry = getTypedEntries().get(managerId);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
clearTrackedDataForEntry(entry);
|
clearTrackedDataForEntry(entry);
|
||||||
|
|
@ -405,7 +405,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
* 清理所有管理器的跟踪数据
|
* 清理所有管理器的跟踪数据
|
||||||
*/
|
*/
|
||||||
public void clearAllTrackedData() {
|
public void clearAllTrackedData() {
|
||||||
for (ResourceLocation id : getRegisteredKeys()) {
|
for (Identifier id : getRegisteredKeys()) {
|
||||||
clearAllTrackedData(id);
|
clearAllTrackedData(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -422,7 +422,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
// 辅助方法:更新条目的数据提供者
|
// 辅助方法:更新条目的数据提供者
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected <K, T extends ISyncData<?>> void updateDataProviderInEntry(
|
protected <K, T extends ISyncData<?>> void updateDataProviderInEntry(
|
||||||
ResourceLocation id,
|
Identifier id,
|
||||||
TypedSyncEntry<?,?> entry,
|
TypedSyncEntry<?,?> entry,
|
||||||
DataProvider<Entity, T> newDataProvider
|
DataProvider<Entity, T> newDataProvider
|
||||||
) {
|
) {
|
||||||
|
|
@ -441,7 +441,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
*
|
*
|
||||||
* @return the registered keys
|
* @return the registered keys
|
||||||
*/
|
*/
|
||||||
public Set<ResourceLocation> getRegisteredKeys() {
|
public Set<Identifier> getRegisteredKeys() {
|
||||||
return Collections.unmodifiableSet(getTypedEntries().keySet());
|
return Collections.unmodifiableSet(getTypedEntries().keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -450,7 +450,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
*
|
*
|
||||||
* @param consumer the consumer
|
* @param consumer the consumer
|
||||||
*/
|
*/
|
||||||
public void forEach(BiConsumer<ResourceLocation, ISyncManager<?,?>> consumer) {
|
public void forEach(BiConsumer<Identifier, ISyncManager<?,?>> consumer) {
|
||||||
Objects.requireNonNull(consumer, "Consumer cannot be null");
|
Objects.requireNonNull(consumer, "Consumer cannot be null");
|
||||||
getTypedEntries().forEach((key, entry) -> consumer.accept(key, entry.manager));
|
getTypedEntries().forEach((key, entry) -> consumer.accept(key, entry.manager));
|
||||||
}
|
}
|
||||||
|
|
@ -476,8 +476,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
*/
|
*/
|
||||||
public void removeManager(ResourceLocation key) {
|
public void removeManager(Identifier key) {
|
||||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||||
getTypedEntries().remove(key);
|
getTypedEntries().remove(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package top.r3944realms.lib39.example.content.data;
|
package top.r3944realms.lib39.example.content.data;
|
||||||
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import top.r3944realms.lib39.core.sync.NBTEntitySyncData;
|
import top.r3944realms.lib39.core.sync.NBTEntitySyncData;
|
||||||
|
|
||||||
|
|
@ -36,7 +36,7 @@ public abstract class AbstractedTestSyncData extends NBTEntitySyncData {
|
||||||
*
|
*
|
||||||
* @param id the id
|
* @param id the id
|
||||||
*/
|
*/
|
||||||
protected AbstractedTestSyncData(ResourceLocation id) {
|
protected AbstractedTestSyncData(Identifier id) {
|
||||||
super(id);
|
super(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package top.r3944realms.lib39.example.content.item;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResultHolder;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
@ -11,16 +11,16 @@ import net.minecraft.world.entity.projectile.ProjectileUtil;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.TooltipFlag;
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
|
import net.minecraft.world.item.component.TooltipDisplay;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.phys.EntityHitResult;
|
import net.minecraft.world.phys.EntityHitResult;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import top.r3944realms.lib39.Lib39;
|
import top.r3944realms.lib39.Lib39;
|
||||||
import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
|
import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用于执行数据查询并检查同步状态的物品
|
* 用于执行数据查询并检查同步状态的物品
|
||||||
|
|
@ -39,7 +39,7 @@ public abstract class AbstractFabricItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand hand) {
|
public InteractionResult use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand hand) {
|
||||||
ItemStack itemStack = player.getItemInHand(hand);
|
ItemStack itemStack = player.getItemInHand(hand);
|
||||||
|
|
||||||
if (level.isClientSide()) {
|
if (level.isClientSide()) {
|
||||||
|
|
@ -64,10 +64,10 @@ public abstract class AbstractFabricItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加冷却时间
|
// 添加冷却时间
|
||||||
player.getCooldowns().addCooldown(this, 20); // 1秒冷却
|
player.getCooldowns().addCooldown(itemStack, 20); // 1秒冷却
|
||||||
}
|
}
|
||||||
|
|
||||||
return InteractionResultHolder.sidedSuccess(itemStack, level.isClientSide());
|
return InteractionResult.SUCCESS.heldItemTransformedTo(itemStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -193,7 +193,7 @@ public abstract class AbstractFabricItem extends Item {
|
||||||
Thread.sleep(3000);
|
Thread.sleep(3000);
|
||||||
|
|
||||||
// 在服务器线程中执行结果处理
|
// 在服务器线程中执行结果处理
|
||||||
player.server.execute(() -> {
|
player.level().getServer().execute(() -> {
|
||||||
displayServerSingleEndResults(player, target);
|
displayServerSingleEndResults(player, target);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -203,7 +203,7 @@ public abstract class AbstractFabricItem extends Item {
|
||||||
player.sendSystemMessage(Component.literal("§c数据查询被中断"));
|
player.sendSystemMessage(Component.literal("§c数据查询被中断"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Lib39.LOGGER.error("[FabricItem] 数据查询出错", e);
|
Lib39.LOGGER.error("[FabricItem] 数据查询出错", e);
|
||||||
player.server.execute(() ->
|
player.level().getServer().execute(() ->
|
||||||
player.sendSystemMessage(Component.literal("§c数据查询出错: " + e.getMessage()))
|
player.sendSystemMessage(Component.literal("§c数据查询出错: " + e.getMessage()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -530,29 +530,28 @@ public abstract class AbstractFabricItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
public void appendHoverText(ItemStack itemStack, TooltipContext context, TooltipDisplay display, Consumer<Component> componentConsumer, TooltipFlag tooltipFlag) {
|
||||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
super.appendHoverText(itemStack, context, display, componentConsumer, tooltipFlag);
|
||||||
|
componentConsumer.accept(Component.literal("§7右键点击在 3 秒后执行"));
|
||||||
tooltipComponents.add(Component.literal("§7右键点击在 3 秒后执行"));
|
componentConsumer.accept(Component.literal("§7§e准星瞄准生物§7的数据查询"));
|
||||||
tooltipComponents.add(Component.literal("§7§e准星瞄准生物§7的数据查询"));
|
componentConsumer.accept(Component.literal("§7§oShift + 右键§7进行§e客户端-服务器双端同步检查§7"));
|
||||||
tooltipComponents.add(Component.literal("§7§oShift + 右键§7进行§e客户端-服务器双端同步检查§7"));
|
componentConsumer.accept(Component.literal(""));
|
||||||
tooltipComponents.add(Component.literal(""));
|
componentConsumer.accept(Component.literal("§6查询延迟: §e3秒"));
|
||||||
tooltipComponents.add(Component.literal("§6查询延迟: §e3秒"));
|
componentConsumer.accept(Component.literal("§6瞄准距离: §e20格"));
|
||||||
tooltipComponents.add(Component.literal("§6瞄准距离: §e20格"));
|
componentConsumer.accept(Component.literal("§6冷却时间: §e1秒"));
|
||||||
tooltipComponents.add(Component.literal("§6冷却时间: §e1秒"));
|
componentConsumer.accept(Component.literal(""));
|
||||||
tooltipComponents.add(Component.literal(""));
|
componentConsumer.accept(Component.literal("§a单端查询内容:"));
|
||||||
tooltipComponents.add(Component.literal("§a单端查询内容:"));
|
componentConsumer.accept(Component.literal("§7- 基础数据字段"));
|
||||||
tooltipComponents.add(Component.literal("§7- 基础数据字段"));
|
componentConsumer.accept(Component.literal("§7- 自定义数据结构"));
|
||||||
tooltipComponents.add(Component.literal("§7- 自定义数据结构"));
|
componentConsumer.accept(Component.literal("§7- 数据验证状态"));
|
||||||
tooltipComponents.add(Component.literal("§7- 数据验证状态"));
|
componentConsumer.accept(Component.literal("§7- 同步状态信息"));
|
||||||
tooltipComponents.add(Component.literal("§7- 同步状态信息"));
|
componentConsumer.accept(Component.literal(""));
|
||||||
tooltipComponents.add(Component.literal(""));
|
componentConsumer.accept(Component.literal("§e双端同步检查:"));
|
||||||
tooltipComponents.add(Component.literal("§e双端同步检查:"));
|
componentConsumer.accept(Component.literal("§7- 客户端和服务器同时查询"));
|
||||||
tooltipComponents.add(Component.literal("§7- 客户端和服务器同时查询"));
|
componentConsumer.accept(Component.literal("§7- 字段级同步状态对比"));
|
||||||
tooltipComponents.add(Component.literal("§7- 字段级同步状态对比"));
|
componentConsumer.accept(Component.literal("§7- 总体同步率计算"));
|
||||||
tooltipComponents.add(Component.literal("§7- 总体同步率计算"));
|
componentConsumer.accept(Component.literal("§7- 双端数据状态差异"));
|
||||||
tooltipComponents.add(Component.literal("§7- 双端数据状态差异"));
|
componentConsumer.accept(Component.literal("§7- 同步建议"));
|
||||||
tooltipComponents.add(Component.literal("§7- 同步建议"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -3,7 +3,7 @@ package top.r3944realms.lib39.example.content.item;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResultHolder;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
@ -11,16 +11,16 @@ import net.minecraft.world.entity.projectile.ProjectileUtil;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.TooltipFlag;
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
|
import net.minecraft.world.item.component.TooltipDisplay;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.phys.EntityHitResult;
|
import net.minecraft.world.phys.EntityHitResult;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import top.r3944realms.lib39.Lib39;
|
import top.r3944realms.lib39.Lib39;
|
||||||
import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
|
import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用于对准星生物触发 TestSyncData 随机变换的物品
|
* 用于对准星生物触发 TestSyncData 随机变换的物品
|
||||||
|
|
@ -40,7 +40,7 @@ public abstract class AbstractNeoForgeItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand hand) {
|
public InteractionResult use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand hand) {
|
||||||
ItemStack itemStack = player.getItemInHand(hand);
|
ItemStack itemStack = player.getItemInHand(hand);
|
||||||
|
|
||||||
if (!level.isClientSide()) {
|
if (!level.isClientSide()) {
|
||||||
|
|
@ -55,10 +55,10 @@ public abstract class AbstractNeoForgeItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加冷却时间
|
// 添加冷却时间
|
||||||
player.getCooldowns().addCooldown(this, 20); // 1秒冷却
|
player.getCooldowns().addCooldown(itemStack, 20); // 1秒冷却
|
||||||
}
|
}
|
||||||
|
|
||||||
return InteractionResultHolder.sidedSuccess(itemStack, level.isClientSide());
|
return InteractionResult.SUCCESS.heldItemTransformedTo(itemStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -268,27 +268,25 @@ public abstract class AbstractNeoForgeItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
public void appendHoverText(ItemStack itemStack, TooltipContext context, TooltipDisplay display, Consumer<Component> componentConsumer, TooltipFlag tooltipFlag) {
|
||||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
super.appendHoverText(itemStack, context, display, componentConsumer, tooltipFlag);
|
||||||
|
componentConsumer.accept(Component.literal("§7右键点击触发§e准星瞄准生物§7的"));
|
||||||
|
componentConsumer.accept(Component.literal("§7测试数据随机变换"));
|
||||||
tooltipComponents.add(Component.literal("§7右键点击触发§e准星瞄准生物§7的"));
|
componentConsumer.accept(Component.literal("§7§oShift + 右键§7操作§e自身§7数据"));
|
||||||
tooltipComponents.add(Component.literal("§7测试数据随机变换"));
|
componentConsumer.accept(Component.literal(""));
|
||||||
tooltipComponents.add(Component.literal("§7§oShift + 右键§7操作§e自身§7数据"));
|
componentConsumer.accept(Component.literal("§6冷却时间: §e1秒"));
|
||||||
tooltipComponents.add(Component.literal(""));
|
componentConsumer.accept(Component.literal("§6瞄准距离: §e20格"));
|
||||||
tooltipComponents.add(Component.literal("§6冷却时间: §e1秒"));
|
componentConsumer.accept(Component.literal(""));
|
||||||
tooltipComponents.add(Component.literal("§6瞄准距离: §e20格"));
|
componentConsumer.accept(Component.literal("§a变换类型:"));
|
||||||
tooltipComponents.add(Component.literal(""));
|
componentConsumer.accept(Component.literal("§7- 完全随机数据"));
|
||||||
tooltipComponents.add(Component.literal("§a变换类型:"));
|
componentConsumer.accept(Component.literal("§7- 字符串+计数器"));
|
||||||
tooltipComponents.add(Component.literal("§7- 完全随机数据"));
|
componentConsumer.accept(Component.literal("§7- 数值数据"));
|
||||||
tooltipComponents.add(Component.literal("§7- 字符串+计数器"));
|
componentConsumer.accept(Component.literal("§7- 自定义数据"));
|
||||||
tooltipComponents.add(Component.literal("§7- 数值数据"));
|
componentConsumer.accept(Component.literal("§7- 重置默认值"));
|
||||||
tooltipComponents.add(Component.literal("§7- 自定义数据"));
|
componentConsumer.accept(Component.literal("§7- 玩家专属数据"));
|
||||||
tooltipComponents.add(Component.literal("§7- 重置默认值"));
|
componentConsumer.accept(Component.literal(""));
|
||||||
tooltipComponents.add(Component.literal("§7- 玩家专属数据"));
|
componentConsumer.accept(Component.literal("§e自身操作特性:"));
|
||||||
tooltipComponents.add(Component.literal(""));
|
componentConsumer.accept(Component.literal("§7- 显示数据预览"));
|
||||||
tooltipComponents.add(Component.literal("§e自身操作特性:"));
|
componentConsumer.accept(Component.literal("§7- 玩家专属数据变换"));
|
||||||
tooltipComponents.add(Component.literal("§7- 显示数据预览"));
|
|
||||||
tooltipComponents.add(Component.literal("§7- 玩家专属数据变换"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,10 +2,10 @@ package top.r3944realms.lib39.example.content.item;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResultHolder;
|
|
||||||
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import top.r3944realms.lib39.example.client.screen.ForgeScreen;
|
import top.r3944realms.lib39.example.client.screen.ForgeScreen;
|
||||||
|
|
@ -25,7 +25,7 @@ public class ForgeItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand usedHand) {
|
public @NotNull InteractionResult use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand usedHand) {
|
||||||
if (level.isClientSide() && usedHand == InteractionHand.MAIN_HAND) {
|
if (level.isClientSide() && usedHand == InteractionHand.MAIN_HAND) {
|
||||||
ClientOpt.clientUse(usedHand);
|
ClientOpt.clientUse(usedHand);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package top.r3944realms.lib39.mixin.carryon;
|
package top.r3944realms.lib39.mixin.carryon;
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.sugar.Local;
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
@ -12,10 +11,12 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||||
import top.r3944realms.lib39.content.item.DollItem;
|
import top.r3944realms.lib39.content.item.DollItem;
|
||||||
import top.r3944realms.lib39.util.GameProfileHelper;
|
import top.r3944realms.lib39.util.GameProfileHelper;
|
||||||
import top.r3944realms.lib39.util.nbt.NBTReader;
|
import top.r3944realms.lib39.util.storage.nbt.NBTReader;
|
||||||
import tschipp.carryon.client.render.CarriedObjectRender;
|
import tschipp.carryon.client.render.CarriedObjectRender;
|
||||||
|
import tschipp.carryon.common.carry.CarryOnData;
|
||||||
import tschipp.carryon.common.carry.CarryOnDataManager;
|
import tschipp.carryon.common.carry.CarryOnDataManager;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -26,40 +27,27 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||||
@Mixin(value = CarriedObjectRender.class, remap = false)
|
@Mixin(value = CarriedObjectRender.class, remap = false)
|
||||||
public class MixinCarriedObjectRender {
|
public class MixinCarriedObjectRender {
|
||||||
@ModifyVariable(
|
@ModifyVariable(
|
||||||
method = "drawFirstPersonBlock",
|
method = "drawBlock",
|
||||||
at = @At(
|
at = @At(
|
||||||
value = "LOAD",
|
value = "INVOKE",
|
||||||
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"
|
target = "Lnet/minecraft/client/renderer/item/ItemStackRenderState;submit(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/SubmitNodeCollector;III)V",
|
||||||
)
|
shift = At.Shift.BEFORE
|
||||||
|
),
|
||||||
|
ordinal = 0
|
||||||
)
|
)
|
||||||
private static ItemStack warpDollItem$1(ItemStack stack, @Local(ordinal = 0, argsOnly = true) Player player) {
|
private static ItemStack modifyRenderStack(ItemStack renderStack, @Local(argsOnly = true) Player player) {
|
||||||
if (stack.getItem() instanceof DollItem) {
|
if (renderStack.getItem() instanceof DollItem) {
|
||||||
CompoundTag compound = CarryOnDataManager.getCarryData(player).getNbt().getCompound("tile");
|
CarryOnData carry = CarryOnDataManager.getCarryData(player);
|
||||||
AtomicReference<GameProfile> gameProfileAtomicReference = new AtomicReference<>();
|
if (carry != null) {
|
||||||
NBTReader.of(compound).gameProfile("profile", gameProfileAtomicReference::set);
|
Optional<CompoundTag> compound = carry.getNbt().getCompound("tile");
|
||||||
if (gameProfileAtomicReference.get() != null) {
|
AtomicReference<ResolvableProfile> profileHolder = new AtomicReference<>();
|
||||||
GameProfileHelper.saveProfileToItemStack(stack, new ResolvableProfile(gameProfileAtomicReference.get()));
|
NBTReader.ofOpt(compound).gameProfile("profile", profileHolder::set);
|
||||||
|
if (profileHolder.get() != null) {
|
||||||
|
GameProfileHelper.saveProfileToItemStack(renderStack,profileHolder.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return stack;
|
return renderStack;
|
||||||
}
|
|
||||||
@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<GameProfile> gameProfileAtomicReference = new AtomicReference<>();
|
|
||||||
NBTReader.of(compound).gameProfile("profile", gameProfileAtomicReference::set);
|
|
||||||
if (gameProfileAtomicReference.get() != null) {
|
|
||||||
GameProfileHelper.saveProfileToItemStack(tileItem, new ResolvableProfile(gameProfileAtomicReference.get()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tileItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,10 @@ import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
|
||||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.level.storage.ValueInput;
|
||||||
|
import net.minecraft.world.level.storage.ValueOutput;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
|
@ -43,19 +46,20 @@ public abstract class MixinEntity implements ILib39SyncDataHolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@WrapMethod(method = "saveWithoutId")
|
@WrapMethod(method = "saveWithoutId")
|
||||||
private CompoundTag wrapSave(CompoundTag compound, @NotNull Operation<CompoundTag> original) {
|
private void wrapSave(ValueOutput output, @NonNull Operation<Void> original) {
|
||||||
Services.PLATFORM.getUtilHelper().getSyncData2Manager().forEach((id, manager) -> {
|
Services.PLATFORM.getUtilHelper().getSyncData2Manager().forEach((id, manager) -> {
|
||||||
ISyncData<?> o = manager.getSyncMap().get(getUUID());
|
ISyncData<?> o = manager.getSyncMap().get(getUUID());
|
||||||
if (o instanceof NBTEntitySyncData syncData) {
|
if (o instanceof NBTEntitySyncData syncData) {
|
||||||
saveSyncData(syncData);
|
saveSyncData(syncData);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return lib39$injectSaveSyncData(original.call(compound));
|
original.call(output);
|
||||||
|
lib39$injectSaveSyncData(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@WrapMethod(method = "load")
|
@WrapMethod(method = "load")
|
||||||
private void warpLoad(CompoundTag compound, @NotNull Operation<Void> original) {
|
private void warpLoad(ValueInput input, @NonNull Operation<Void> original) {
|
||||||
original.call(compound);
|
original.call(input);
|
||||||
lib39$injectLoadSyncData(compound);
|
lib39$injectLoadSyncData(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,81 +7,68 @@ import com.mojang.authlib.properties.Property;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.multiplayer.PlayerInfo;
|
import net.minecraft.client.multiplayer.PlayerInfo;
|
||||||
import net.minecraft.client.player.AbstractClientPlayer;
|
import net.minecraft.client.player.AbstractClientPlayer;
|
||||||
import net.minecraft.client.resources.DefaultPlayerSkin;
|
|
||||||
import net.minecraft.core.component.DataComponents;
|
import net.minecraft.core.component.DataComponents;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.nbt.NbtUtils;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.server.Services;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.entity.player.PlayerModelType;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.component.ResolvableProfile;
|
import net.minecraft.world.item.component.ResolvableProfile;
|
||||||
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
import top.r3944realms.lib39.Lib39;
|
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.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type GameProfile helper.
|
* The type GameProfile helper.
|
||||||
*/
|
*/
|
||||||
public class GameProfileHelper {
|
public class GameProfileHelper {
|
||||||
/**
|
/**
|
||||||
* 异步获取 GameProfile(通过玩家名)
|
* 获取 GameProfile(通过玩家名)
|
||||||
* 直接复用 SkullBlockEntity 的实现
|
|
||||||
*/
|
*/
|
||||||
public static CompletableFuture<Optional<GameProfile>> fetchGameProfileByName(String name) {
|
@Contract("_ -> new")
|
||||||
return SkullBlockEntity.fetchGameProfile(name);
|
public static @NonNull ResolvableProfile fetchGameProfileByName(String name) {
|
||||||
|
return ResolvableProfile.createUnresolved(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步获取 GameProfile(通过 UUID)
|
* 获取 GameProfile(通过 UUID)
|
||||||
* 直接复用 SkullBlockEntity 的实现
|
* 直接复用 SkullBlockEntity 的实现
|
||||||
*/
|
*/
|
||||||
public static CompletableFuture<Optional<GameProfile>> fetchGameProfileByUUID(UUID uuid) {
|
@Contract("_ -> new")
|
||||||
return SkullBlockEntity.fetchGameProfile(uuid);
|
public static @NonNull ResolvableProfile fetchGameProfileByUUID(UUID uuid) {
|
||||||
|
return ResolvableProfile.createUnresolved(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步获取 GameProfile(自动识别类型)
|
* 获取 GameProfile(自动识别类型)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> CompletableFuture<Optional<GameProfile>> fetchGameProfile(T identifier) {
|
public static <T> ResolvableProfile fetchGameProfile(T identifier) {
|
||||||
if (identifier instanceof UUID uuid) {
|
if (identifier instanceof UUID uuid) {
|
||||||
return fetchGameProfileByUUID(uuid);
|
return fetchGameProfileByUUID(uuid);
|
||||||
} else if (identifier instanceof String name) {
|
} else if (identifier instanceof String name) {
|
||||||
return fetchGameProfileByName(name);
|
return fetchGameProfileByName(name);
|
||||||
|
} else if (identifier instanceof GameProfile gameProfile) {
|
||||||
|
return ResolvableProfile.createResolved(gameProfile);
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(Optional.empty());
|
throw new IllegalArgumentException("Identifier type not supported: " + identifier.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从 ItemStack 异步获取完整的 GameProfile
|
* 从 ItemStack 获取完整的 ResolvableProfile
|
||||||
* 需要配合 ResolvableProfile 使用
|
|
||||||
*/
|
*/
|
||||||
public static CompletableFuture<Optional<GameProfile>> fetchProfileFromItemStack(@NotNull ItemStack stack) {
|
public static ResolvableProfile fetchProfileFromItemStack(@NotNull ItemStack stack) {
|
||||||
ResolvableProfile resolvable = stack.get(DataComponents.PROFILE);
|
ResolvableProfile resolvable = stack.get(DataComponents.PROFILE);
|
||||||
if (resolvable == null) {
|
if (resolvable == null) {
|
||||||
return CompletableFuture.completedFuture(Optional.empty());
|
return ResolvableProfile.Static.EMPTY;
|
||||||
}
|
}
|
||||||
|
return resolvable;
|
||||||
// 如果已经有 UUID,直接用 SkullBlockEntity 的方法
|
|
||||||
GameProfile profile = resolvable.gameProfile();
|
|
||||||
if (profile != null && profile.getId() != null) {
|
|
||||||
return fetchGameProfileByUUID(profile.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 否则异步解析
|
|
||||||
return resolvable.resolve().thenApply(resolved ->
|
|
||||||
Optional.ofNullable(resolved.gameProfile())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Client Only Class
|
* Client Only Class
|
||||||
|
|
@ -93,10 +80,10 @@ public class GameProfileHelper {
|
||||||
* @param gameProfile the game profile
|
* @param gameProfile the game profile
|
||||||
* @return the resource location
|
* @return the resource location
|
||||||
*/
|
*/
|
||||||
public static @NotNull ResourceLocation resolveSkinTexture(@NotNull GameProfile gameProfile) {
|
public static @NotNull Identifier resolveSkinTexture(@NotNull GameProfile gameProfile) {
|
||||||
return IClientOnly.check(() ->
|
return IClientOnly.check(() ->
|
||||||
Minecraft.getInstance().getSkinManager()
|
Minecraft.getInstance().getSkinManager()
|
||||||
.getInsecureSkin(gameProfile)).texture();
|
.createLookup(gameProfile, true)).get().body().texturePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -105,7 +92,7 @@ public class GameProfileHelper {
|
||||||
* @param gameProfile the game profile
|
* @param gameProfile the game profile
|
||||||
* @return the skin texture
|
* @return the skin texture
|
||||||
*/
|
*/
|
||||||
public static ResourceLocation getSkinTexture(@Nullable GameProfile gameProfile) {
|
public static Identifier getSkinTexture(@Nullable GameProfile gameProfile) {
|
||||||
return IClientOnly.check(() -> {
|
return IClientOnly.check(() -> {
|
||||||
if (gameProfile == null) {
|
if (gameProfile == null) {
|
||||||
return Lib39.mrl("textures/entity/player/wide/steve.png");
|
return Lib39.mrl("textures/entity/player/wide/steve.png");
|
||||||
|
|
@ -126,7 +113,7 @@ public class GameProfileHelper {
|
||||||
PlayerInfo playerInfo = Objects.requireNonNull(Minecraft.getInstance()
|
PlayerInfo playerInfo = Objects.requireNonNull(Minecraft.getInstance()
|
||||||
.getConnection())
|
.getConnection())
|
||||||
.getPlayerInfo(clientPlayer.getUUID());
|
.getPlayerInfo(clientPlayer.getUUID());
|
||||||
return playerInfo != null && "slim".equals(playerInfo.getSkin().model().id());
|
return playerInfo != null && PlayerModelType.SLIM.equals(playerInfo.getSkin().model());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
@ -140,12 +127,12 @@ public class GameProfileHelper {
|
||||||
*/
|
*/
|
||||||
public static @NotNull String getSkinModelName(@NotNull Player player) {
|
public static @NotNull String getSkinModelName(@NotNull Player player) {
|
||||||
return IClientOnly.check(() -> {
|
return IClientOnly.check(() -> {
|
||||||
if (player.level().isClientSide && player instanceof AbstractClientPlayer) {
|
if (player.level().isClientSide() && player instanceof AbstractClientPlayer) {
|
||||||
PlayerInfo info = Objects.requireNonNull(Minecraft.getInstance().getConnection())
|
PlayerInfo info = Objects.requireNonNull(Minecraft.getInstance().getConnection())
|
||||||
.getPlayerInfo(player.getUUID());
|
.getPlayerInfo(player.getUUID());
|
||||||
return info != null ? info.getSkin().model().id() : "default";
|
return info != null ? info.getSkin().model().name() : PlayerModelType.WIDE.name();
|
||||||
}
|
}
|
||||||
return "default";
|
return PlayerModelType.WIDE.name();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,7 +149,7 @@ public class GameProfileHelper {
|
||||||
* @param gameProfile the game profile
|
* @param gameProfile the game profile
|
||||||
* @return the skin texture
|
* @return the skin texture
|
||||||
*/
|
*/
|
||||||
public static ResourceLocation getSkinTexture(@Nullable GameProfile gameProfile) {
|
public static Identifier getSkinTexture(@Nullable GameProfile gameProfile) {
|
||||||
return ClientOpt.getSkinTexture(gameProfile);
|
return ClientOpt.getSkinTexture(gameProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -173,7 +160,7 @@ public class GameProfileHelper {
|
||||||
* @param gameProfile the game profile
|
* @param gameProfile the game profile
|
||||||
* @return the resource location
|
* @return the resource location
|
||||||
*/
|
*/
|
||||||
public static @NotNull ResourceLocation resolveSkinTexture(@NotNull GameProfile gameProfile) {
|
public static @NotNull Identifier resolveSkinTexture(@NotNull GameProfile gameProfile) {
|
||||||
return ClientOpt.resolveSkinTexture(gameProfile);
|
return ClientOpt.resolveSkinTexture(gameProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,7 +171,7 @@ public class GameProfileHelper {
|
||||||
* @return the boolean
|
* @return the boolean
|
||||||
*/
|
*/
|
||||||
public static boolean hasSlimArms(@NotNull Player player) {
|
public static boolean hasSlimArms(@NotNull Player player) {
|
||||||
if (player.level().isClientSide) {
|
if (player.level().isClientSide()) {
|
||||||
return hasSlimArmsClient(player);
|
return hasSlimArmsClient(player);
|
||||||
} else {
|
} else {
|
||||||
return hasSlimArmsServer(player);
|
return hasSlimArmsServer(player);
|
||||||
|
|
@ -199,7 +186,7 @@ public class GameProfileHelper {
|
||||||
// 服务器端判断
|
// 服务器端判断
|
||||||
private static boolean hasSlimArmsServer(@NotNull Player player) {
|
private static boolean hasSlimArmsServer(@NotNull Player player) {
|
||||||
GameProfile profile = player.getGameProfile();
|
GameProfile profile = player.getGameProfile();
|
||||||
for (Property property : profile.getProperties().get("textures")) {
|
for (Property property : profile.properties().get("textures")) {
|
||||||
try {
|
try {
|
||||||
String json = new String(Base64.getDecoder().decode(property.value()));
|
String json = new String(Base64.getDecoder().decode(property.value()));
|
||||||
JsonObject obj = JsonParser.parseString(json).getAsJsonObject();
|
JsonObject obj = JsonParser.parseString(json).getAsJsonObject();
|
||||||
|
|
@ -241,7 +228,7 @@ public class GameProfileHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取textures属性
|
// 获取textures属性
|
||||||
Collection<Property> textures = profile.getProperties().get("textures");
|
Collection<Property> textures = profile.properties().get("textures");
|
||||||
if (textures.isEmpty()) {
|
if (textures.isEmpty()) {
|
||||||
return false; // 没有皮肤数据,使用默认
|
return false; // 没有皮肤数据,使用默认
|
||||||
}
|
}
|
||||||
|
|
@ -313,7 +300,7 @@ public class GameProfileHelper {
|
||||||
return "default";
|
return "default";
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<Property> textures = profile.getProperties().get("textures");
|
Collection<Property> textures = profile.properties().get("textures");
|
||||||
if (textures.isEmpty()) {
|
if (textures.isEmpty()) {
|
||||||
return "default";
|
return "default";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,10 @@ public class MathUtil {
|
||||||
* @return the direction
|
* @return the direction
|
||||||
*/
|
*/
|
||||||
public static Direction getDirection(BlockPos from, BlockPos to) {
|
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();
|
private static final Int2DoubleMap FACTORIAL_CACHE = new Int2DoubleOpenHashMap();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.util;
|
package top.r3944realms.lib39.util;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.util.StringRepresentable;
|
import net.minecraft.util.StringRepresentable;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.Items;
|
import net.minecraft.world.item.Items;
|
||||||
|
|
@ -11,6 +11,7 @@ import top.r3944realms.lib39.Lib39;
|
||||||
/**
|
/**
|
||||||
* The type Plant helper.
|
* The type Plant helper.
|
||||||
*/
|
*/
|
||||||
|
//todo: 需添加26.1.2的新的Plant,部分条目可能需要重命名
|
||||||
public class PlantHelper {
|
public class PlantHelper {
|
||||||
/**
|
/**
|
||||||
* The enum Plant.
|
* The enum Plant.
|
||||||
|
|
@ -268,7 +269,7 @@ public class PlantHelper {
|
||||||
* @return the texture rl
|
* @return the texture rl
|
||||||
*/
|
*/
|
||||||
@Contract("_ -> new")
|
@Contract("_ -> new")
|
||||||
public static @NotNull ResourceLocation getTextureRL(@NotNull Plant plant) {
|
public static @NotNull Identifier getTextureRL(@NotNull Plant plant) {
|
||||||
return Lib39.mrl("block/" + plant.name);
|
return Lib39.mrl("block/" + plant.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -279,7 +280,7 @@ public class PlantHelper {
|
||||||
* @return the directly texture rl
|
* @return the directly texture rl
|
||||||
*/
|
*/
|
||||||
@Contract("_ -> new")
|
@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");
|
return Lib39.mrl("textures/block/" + plant.name + ".png");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package top.r3944realms.lib39.util.resolve;
|
package top.r3944realms.lib39.util.resolve;
|
||||||
|
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
@ -141,14 +141,14 @@ public abstract class EntityListResolve {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public boolean isEntityInList(EntityType<?> type) {
|
public boolean isEntityInList(EntityType<?> type) {
|
||||||
String entityId = type.builtInRegistryHolder().key().location().toString();
|
String entityId = type.builtInRegistryHolder().key().identifier().toString();
|
||||||
String modId = entityId.split(":")[0];
|
String modId = entityId.split(":")[0];
|
||||||
for (String rs : result.entityList) {
|
for (String rs : result.entityList) {
|
||||||
if (rs.equals(entityId)) return true;
|
if (rs.equals(entityId)) return true;
|
||||||
}
|
}
|
||||||
for(String rs : result.tagList) {
|
for(String rs : result.tagList) {
|
||||||
String body = rs.substring(1);
|
String body = rs.substring(1);
|
||||||
ResourceLocation tagId = Lib39.rl(body);
|
Identifier tagId = Lib39.rl(body);
|
||||||
TagKey<EntityType<?>> tag = TagKey.create(Registries.ENTITY_TYPE, tagId);
|
TagKey<EntityType<?>> tag = TagKey.create(Registries.ENTITY_TYPE, tagId);
|
||||||
if (type.builtInRegistryHolder().is(tag)) return true;
|
if (type.builtInRegistryHolder().is(tag)) return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package top.r3944realms.lib39.util.resolve;
|
package top.r3944realms.lib39.util.resolve;
|
||||||
|
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
@ -153,7 +153,7 @@ public abstract class EntityMapResolve<T> {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private EntityMatchResult<T> findEntityMatch(EntityType<?> type) {
|
private EntityMatchResult<T> findEntityMatch(EntityType<?> type) {
|
||||||
String entityId = type.builtInRegistryHolder().key().location().toString();
|
String entityId = type.builtInRegistryHolder().key().identifier().toString();
|
||||||
String modId = entityId.split(":")[0];
|
String modId = entityId.split(":")[0];
|
||||||
|
|
||||||
// 检查实体ID匹配
|
// 检查实体ID匹配
|
||||||
|
|
@ -166,7 +166,7 @@ public abstract class EntityMapResolve<T> {
|
||||||
// 检查标签匹配
|
// 检查标签匹配
|
||||||
for (String rs : result.tagMap.keySet()) {
|
for (String rs : result.tagMap.keySet()) {
|
||||||
String body = rs.startsWith("#") ? rs.substring(1) : rs;
|
String body = rs.startsWith("#") ? rs.substring(1) : rs;
|
||||||
ResourceLocation tagId = Lib39.rl(body);
|
Identifier tagId = Lib39.rl(body);
|
||||||
TagKey<EntityType<?>> tag = TagKey.create(Registries.ENTITY_TYPE, tagId);
|
TagKey<EntityType<?>> tag = TagKey.create(Registries.ENTITY_TYPE, tagId);
|
||||||
if (type.builtInRegistryHolder().is(tag)) {
|
if (type.builtInRegistryHolder().is(tag)) {
|
||||||
return new EntityMatchResult<>(EntityResolveResult.Type.TAG, rs, result.tagMap.get(rs));
|
return new EntityMatchResult<>(EntityResolveResult.Type.TAG, rs, result.tagMap.get(rs));
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ public class RidingApplier {
|
||||||
if (RidingValidator.wouldCreateCycle(entity, vehicle)) {
|
if (RidingValidator.wouldCreateCycle(entity, vehicle)) {
|
||||||
throw new RidingCycleException(entityId, vehicleId);
|
throw new RidingCycleException(entityId, vehicleId);
|
||||||
}
|
}
|
||||||
boolean success = entity.startRiding(vehicle, true);
|
boolean success = entity.startRiding(vehicle, true, true);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
Lib39.LOGGER.error("Failed to mount entity {} to vehicle {}", entityId, vehicleId);
|
Lib39.LOGGER.error("Failed to mount entity {} to vehicle {}", entityId, vehicleId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,17 +13,18 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package top.r3944realms.lib39.util.nbt;
|
package top.r3944realms.lib39.util.storage.nbt;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import com.mojang.authlib.properties.Property;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.ListTag;
|
import net.minecraft.nbt.ListTag;
|
||||||
|
import net.minecraft.world.item.component.ResolvableProfile;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -47,24 +48,33 @@ public class NBTReader {
|
||||||
public static NBTReader of(@NotNull CompoundTag nbt) {
|
public static NBTReader of(@NotNull CompoundTag nbt) {
|
||||||
return new NBTReader(nbt);
|
return new NBTReader(nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String nbt reader.
|
* 从CompoundTag创建读取器
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param nbt the nbt opt
|
||||||
* @param setter the setter
|
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
// 基本读取方法 - 直接赋值给成员变量
|
@NotNull
|
||||||
public NBTReader string(String key, Consumer<String> setter) {
|
public static NBTReader ofOpt(@NotNull Optional<CompoundTag> nbt) {
|
||||||
if (nbt.contains(key)) {
|
return new NBTReader(nbt.orElse(new CompoundTag()));
|
||||||
setter.accept(nbt.getString(key));
|
}
|
||||||
|
@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 key the key
|
||||||
* @param setter the setter
|
* @param setter the setter
|
||||||
|
|
@ -72,7 +82,14 @@ public class NBTReader {
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
public NBTReader string(String key, @NotNull Consumer<String> setter, String defaultValue) {
|
public NBTReader string(String key, @NotNull Consumer<String> setter, String defaultValue) {
|
||||||
setter.accept(nbt.contains(key) ? nbt.getString(key) : defaultValue);
|
if (nbt.contains(key)) {
|
||||||
|
Optional<String> value = nbt.getString(key);
|
||||||
|
if (checkOpt(value)) {
|
||||||
|
setter.accept(value.get());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setter.accept(defaultValue);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,13 +102,14 @@ public class NBTReader {
|
||||||
*/
|
*/
|
||||||
public NBTReader byteValue(String key, Consumer<Byte> setter) {
|
public NBTReader byteValue(String key, Consumer<Byte> setter) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
setter.accept(nbt.getByte(key));
|
Optional<Byte> value = nbt.getByte(key);
|
||||||
|
if (checkOpt(value)) setter.accept(value.get());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Byte value nbt reader.
|
* Byte value nbt reader with default value.
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param setter the setter
|
* @param setter the setter
|
||||||
|
|
@ -99,7 +117,14 @@ public class NBTReader {
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
public NBTReader byteValue(String key, @NotNull Consumer<Byte> setter, byte defaultValue) {
|
public NBTReader byteValue(String key, @NotNull Consumer<Byte> setter, byte defaultValue) {
|
||||||
setter.accept(nbt.contains(key) ? nbt.getByte(key) : defaultValue);
|
if (nbt.contains(key)) {
|
||||||
|
Optional<Byte> value = nbt.getByte(key);
|
||||||
|
if (checkOpt(value)) {
|
||||||
|
setter.accept(value.get());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setter.accept(defaultValue);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,13 +137,14 @@ public class NBTReader {
|
||||||
*/
|
*/
|
||||||
public NBTReader shortValue(String key, Consumer<Short> setter) {
|
public NBTReader shortValue(String key, Consumer<Short> setter) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
setter.accept(nbt.getShort(key));
|
Optional<Short> value = nbt.getShort(key);
|
||||||
|
if (checkOpt(value)) setter.accept(value.get());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short value nbt reader.
|
* Short value nbt reader with default value.
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param setter the setter
|
* @param setter the setter
|
||||||
|
|
@ -126,7 +152,14 @@ public class NBTReader {
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
public NBTReader shortValue(String key, @NotNull Consumer<Short> setter, short defaultValue) {
|
public NBTReader shortValue(String key, @NotNull Consumer<Short> setter, short defaultValue) {
|
||||||
setter.accept(nbt.contains(key) ? nbt.getShort(key) : defaultValue);
|
if (nbt.contains(key)) {
|
||||||
|
Optional<Short> value = nbt.getShort(key);
|
||||||
|
if (checkOpt(value)) {
|
||||||
|
setter.accept(value.get());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setter.accept(defaultValue);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,13 +172,14 @@ public class NBTReader {
|
||||||
*/
|
*/
|
||||||
public NBTReader intValue(String key, Consumer<Integer> setter) {
|
public NBTReader intValue(String key, Consumer<Integer> setter) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
setter.accept(nbt.getInt(key));
|
Optional<Integer> value = nbt.getInt(key);
|
||||||
|
if (checkOpt(value)) setter.accept(value.get());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Int value nbt reader.
|
* Int value nbt reader with default value.
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param setter the setter
|
* @param setter the setter
|
||||||
|
|
@ -153,7 +187,14 @@ public class NBTReader {
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
public NBTReader intValue(String key, @NotNull Consumer<Integer> setter, int defaultValue) {
|
public NBTReader intValue(String key, @NotNull Consumer<Integer> setter, int defaultValue) {
|
||||||
setter.accept(nbt.contains(key) ? nbt.getInt(key) : defaultValue);
|
if (nbt.contains(key)) {
|
||||||
|
Optional<Integer> value = nbt.getInt(key);
|
||||||
|
if (checkOpt(value)) {
|
||||||
|
setter.accept(value.get());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setter.accept(defaultValue);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,13 +207,14 @@ public class NBTReader {
|
||||||
*/
|
*/
|
||||||
public NBTReader longValue(String key, Consumer<Long> setter) {
|
public NBTReader longValue(String key, Consumer<Long> setter) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
setter.accept(nbt.getLong(key));
|
Optional<Long> value = nbt.getLong(key);
|
||||||
|
if (checkOpt(value)) setter.accept(value.get());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Long value nbt reader.
|
* Long value nbt reader with default value.
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param setter the setter
|
* @param setter the setter
|
||||||
|
|
@ -180,7 +222,14 @@ public class NBTReader {
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
public NBTReader longValue(String key, @NotNull Consumer<Long> setter, long defaultValue) {
|
public NBTReader longValue(String key, @NotNull Consumer<Long> setter, long defaultValue) {
|
||||||
setter.accept(nbt.contains(key) ? nbt.getLong(key) : defaultValue);
|
if (nbt.contains(key)) {
|
||||||
|
Optional<Long> value = nbt.getLong(key);
|
||||||
|
if (checkOpt(value)) {
|
||||||
|
setter.accept(value.get());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setter.accept(defaultValue);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,13 +242,14 @@ public class NBTReader {
|
||||||
*/
|
*/
|
||||||
public NBTReader floatValue(String key, Consumer<Float> setter) {
|
public NBTReader floatValue(String key, Consumer<Float> setter) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
setter.accept(nbt.getFloat(key));
|
Optional<Float> value = nbt.getFloat(key);
|
||||||
|
if (checkOpt(value)) setter.accept(value.get());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Float value nbt reader.
|
* Float value nbt reader with default value.
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param setter the setter
|
* @param setter the setter
|
||||||
|
|
@ -207,7 +257,14 @@ public class NBTReader {
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
public NBTReader floatValue(String key, @NotNull Consumer<Float> setter, float defaultValue) {
|
public NBTReader floatValue(String key, @NotNull Consumer<Float> setter, float defaultValue) {
|
||||||
setter.accept(nbt.contains(key) ? nbt.getFloat(key) : defaultValue);
|
if (nbt.contains(key)) {
|
||||||
|
Optional<Float> value = nbt.getFloat(key);
|
||||||
|
if (checkOpt(value)) {
|
||||||
|
setter.accept(value.get());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setter.accept(defaultValue);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -220,13 +277,14 @@ public class NBTReader {
|
||||||
*/
|
*/
|
||||||
public NBTReader doubleValue(String key, Consumer<Double> setter) {
|
public NBTReader doubleValue(String key, Consumer<Double> setter) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
setter.accept(nbt.getDouble(key));
|
Optional<Double> value = nbt.getDouble(key);
|
||||||
|
if (checkOpt(value)) setter.accept(value.get());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Double value nbt reader.
|
* Double value nbt reader with default value.
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param setter the setter
|
* @param setter the setter
|
||||||
|
|
@ -234,7 +292,14 @@ public class NBTReader {
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
public NBTReader doubleValue(String key, @NotNull Consumer<Double> setter, double defaultValue) {
|
public NBTReader doubleValue(String key, @NotNull Consumer<Double> setter, double defaultValue) {
|
||||||
setter.accept(nbt.contains(key) ? nbt.getDouble(key) : defaultValue);
|
if (nbt.contains(key)) {
|
||||||
|
Optional<Double> value = nbt.getDouble(key);
|
||||||
|
if (checkOpt(value)) {
|
||||||
|
setter.accept(value.get());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setter.accept(defaultValue);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -247,13 +312,14 @@ public class NBTReader {
|
||||||
*/
|
*/
|
||||||
public NBTReader booleanValue(String key, Consumer<Boolean> setter) {
|
public NBTReader booleanValue(String key, Consumer<Boolean> setter) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
setter.accept(nbt.getBoolean(key));
|
Optional<Boolean> value = nbt.getBoolean(key);
|
||||||
|
if (checkOpt(value)) setter.accept(value.get());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boolean value nbt reader.
|
* Boolean value nbt reader with default value.
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param setter the setter
|
* @param setter the setter
|
||||||
|
|
@ -261,7 +327,14 @@ public class NBTReader {
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
public NBTReader booleanValue(String key, @NotNull Consumer<Boolean> setter, boolean defaultValue) {
|
public NBTReader booleanValue(String key, @NotNull Consumer<Boolean> setter, boolean defaultValue) {
|
||||||
setter.accept(nbt.contains(key) ? nbt.getBoolean(key) : defaultValue);
|
if (nbt.contains(key)) {
|
||||||
|
Optional<Boolean> value = nbt.getBoolean(key);
|
||||||
|
if (checkOpt(value)) {
|
||||||
|
setter.accept(value.get());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setter.accept(defaultValue);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -272,10 +345,10 @@ public class NBTReader {
|
||||||
* @param setter the setter
|
* @param setter the setter
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
// 数组类型
|
|
||||||
public NBTReader byteArray(String key, Consumer<byte[]> setter) {
|
public NBTReader byteArray(String key, Consumer<byte[]> setter) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
setter.accept(nbt.getByteArray(key));
|
Optional<byte[]> value = nbt.getByteArray(key);
|
||||||
|
if (checkOpt(value)) setter.accept(value.get());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -289,7 +362,8 @@ public class NBTReader {
|
||||||
*/
|
*/
|
||||||
public NBTReader intArray(String key, Consumer<int[]> setter) {
|
public NBTReader intArray(String key, Consumer<int[]> setter) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
setter.accept(nbt.getIntArray(key));
|
Optional<int[]> value = nbt.getIntArray(key);
|
||||||
|
if (checkOpt(value)) setter.accept(value.get());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -303,39 +377,12 @@ public class NBTReader {
|
||||||
*/
|
*/
|
||||||
public NBTReader longArray(String key, Consumer<long[]> setter) {
|
public NBTReader longArray(String key, Consumer<long[]> setter) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
setter.accept(nbt.getLongArray(key));
|
Optional<long[]> value = nbt.getLongArray(key);
|
||||||
|
if (checkOpt(value)) setter.accept(value.get());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Uuid nbt reader.
|
|
||||||
*
|
|
||||||
* @param key the key
|
|
||||||
* @param setter the setter
|
|
||||||
* @return the nbt reader
|
|
||||||
*/
|
|
||||||
// UUID
|
|
||||||
public NBTReader uuid(String key, Consumer<UUID> 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<UUID> setter, UUID defaultValue) {
|
|
||||||
setter.accept(nbt.hasUUID(key) ? nbt.getUUID(key) : defaultValue);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compound nbt reader.
|
* Compound nbt reader.
|
||||||
*
|
*
|
||||||
|
|
@ -343,16 +390,16 @@ public class NBTReader {
|
||||||
* @param setter the setter
|
* @param setter the setter
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
// CompoundTag
|
|
||||||
public NBTReader compound(String key, Consumer<CompoundTag> setter) {
|
public NBTReader compound(String key, Consumer<CompoundTag> setter) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
setter.accept(nbt.getCompound(key));
|
Optional<CompoundTag> value = nbt.getCompound(key);
|
||||||
|
if (checkOpt(value)) setter.accept(value.get());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compound nbt reader.
|
* Compound nbt reader with default value.
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param setter the setter
|
* @param setter the setter
|
||||||
|
|
@ -360,58 +407,10 @@ public class NBTReader {
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
public NBTReader compound(String key, @NotNull Consumer<CompoundTag> setter, CompoundTag defaultValue) {
|
public NBTReader compound(String key, @NotNull Consumer<CompoundTag> 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<ListTag> setter) {
|
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
setter.accept(nbt.getList(key, type));
|
Optional<CompoundTag> value = nbt.getCompound(key);
|
||||||
}
|
if (checkOpt(value)) {
|
||||||
return this;
|
setter.accept(value.get());
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Game profile nbt reader.
|
|
||||||
*
|
|
||||||
* @param key the key
|
|
||||||
* @param setter the setter
|
|
||||||
* @return the nbt reader
|
|
||||||
*/
|
|
||||||
public NBTReader gameProfile(String key, Consumer<GameProfile> 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<GameProfile> 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);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -420,83 +419,48 @@ public class NBTReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read GameProfile from CompoundTag.
|
* List nbt reader.
|
||||||
*
|
*
|
||||||
* @param tag the tag
|
* @param key the key
|
||||||
* @return the game profile, or null if invalid
|
* @param setter the setter
|
||||||
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
@Nullable
|
public NBTReader list(String key, Consumer<ListTag> setter) {
|
||||||
private static GameProfile readGameProfileFromTag(@NotNull CompoundTag tag) {
|
if (nbt.contains(key)) {
|
||||||
String name = null;
|
Optional<ListTag> value = nbt.getList(key);
|
||||||
UUID uuid = null;
|
if (checkOpt(value)) setter.accept(value.get());
|
||||||
|
|
||||||
// 支持 "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;
|
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NBTReader gameProfile(String key, Consumer<ResolvableProfile> setter) {
|
||||||
|
Optional<ResolvableProfile> read = nbt.read(key, ResolvableProfile.CODEC);
|
||||||
|
if (read.isPresent()) {
|
||||||
|
try {
|
||||||
|
ResolvableProfile profile = read.get();
|
||||||
|
setter.accept(profile);
|
||||||
|
return this;
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBTReader gameProfile(String key, Consumer<ResolvableProfile> setter, ResolvableProfile defaultValue) {
|
||||||
|
Optional<ResolvableProfile> read = nbt.read(key, ResolvableProfile.CODEC);
|
||||||
|
if (read.isPresent()) {
|
||||||
|
try {
|
||||||
|
ResolvableProfile profile = read.get();
|
||||||
|
setter.accept(profile);
|
||||||
|
return this;
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setter.accept(defaultValue);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Vec 3 nbt reader.
|
* Vec 3 nbt reader.
|
||||||
*
|
*
|
||||||
|
|
@ -504,23 +468,31 @@ public class NBTReader {
|
||||||
* @param setter the setter
|
* @param setter the setter
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
// Vec3支持
|
|
||||||
public NBTReader vec3(String key, Consumer<Vec3> setter) {
|
public NBTReader vec3(String key, Consumer<Vec3> setter) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
CompoundTag vecTag = nbt.getCompound(key);
|
Optional<CompoundTag> vecTag = nbt.getCompound(key);
|
||||||
if (vecTag.contains("X") && vecTag.contains("Y") && vecTag.contains("Z")) {
|
if (checkOpt(vecTag)) {
|
||||||
setter.accept(new Vec3(
|
CompoundTag vec = vecTag.get();
|
||||||
vecTag.getDouble("X"),
|
if (vec.contains("X") && vec.contains("Y") && vec.contains("Z")) {
|
||||||
vecTag.getDouble("Y"),
|
Optional<Double> x = vec.getDouble("X");
|
||||||
vecTag.getDouble("Z")
|
Optional<Double> y = vec.getDouble("Y");
|
||||||
));
|
Optional<Double> z = vec.getDouble("Z");
|
||||||
|
if (checkOpt(x, y, z)) {
|
||||||
|
Vec3 value = new Vec3(
|
||||||
|
x.get(),
|
||||||
|
y.get(),
|
||||||
|
z.get()
|
||||||
|
);
|
||||||
|
setter.accept(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vec 3 nbt reader.
|
* Vec 3 nbt reader with default value.
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param setter the setter
|
* @param setter the setter
|
||||||
|
|
@ -529,14 +501,23 @@ public class NBTReader {
|
||||||
*/
|
*/
|
||||||
public NBTReader vec3(String key, Consumer<Vec3> setter, Vec3 defaultValue) {
|
public NBTReader vec3(String key, Consumer<Vec3> setter, Vec3 defaultValue) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
CompoundTag vecTag = nbt.getCompound(key);
|
Optional<CompoundTag> vecTag = nbt.getCompound(key);
|
||||||
if (vecTag.contains("X") && vecTag.contains("Y") && vecTag.contains("Z")) {
|
if (checkOpt(vecTag)) {
|
||||||
setter.accept(new Vec3(
|
CompoundTag vec = vecTag.get();
|
||||||
vecTag.getDouble("X"),
|
if (vec.contains("X") && vec.contains("Y") && vec.contains("Z")) {
|
||||||
vecTag.getDouble("Y"),
|
Optional<Double> x = vec.getDouble("X");
|
||||||
vecTag.getDouble("Z")
|
Optional<Double> y = vec.getDouble("Y");
|
||||||
));
|
Optional<Double> z = vec.getDouble("Z");
|
||||||
return this;
|
if (checkOpt(x, y, z)) {
|
||||||
|
Vec3 value = new Vec3(
|
||||||
|
x.get(),
|
||||||
|
y.get(),
|
||||||
|
z.get()
|
||||||
|
);
|
||||||
|
setter.accept(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setter.accept(defaultValue);
|
setter.accept(defaultValue);
|
||||||
|
|
@ -552,21 +533,24 @@ public class NBTReader {
|
||||||
* @param setter the setter
|
* @param setter the setter
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
// 枚举支持
|
|
||||||
public <T extends Enum<T>> NBTReader enumValue(String key, Class<T> enumClass, Consumer<T> setter) {
|
public <T extends Enum<T>> NBTReader enumValue(String key, Class<T> enumClass, Consumer<T> setter) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
String value = nbt.getString(key);
|
Optional<String> value = nbt.getString(key);
|
||||||
try {
|
if(checkOpt(value)) {
|
||||||
setter.accept(Enum.valueOf(enumClass, value.toUpperCase()));
|
try {
|
||||||
} catch (IllegalArgumentException ignored) {
|
T enumValue = Enum.valueOf(enumClass, value.get().toUpperCase());
|
||||||
// 保持setter的当前值
|
setter.accept(enumValue);
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
// 保持setter的当前值
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum value nbt reader.
|
* Enum value nbt reader with default value.
|
||||||
*
|
*
|
||||||
* @param <T> the type parameter
|
* @param <T> the type parameter
|
||||||
* @param key the key
|
* @param key the key
|
||||||
|
|
@ -577,18 +561,21 @@ public class NBTReader {
|
||||||
*/
|
*/
|
||||||
public <T extends Enum<T>> NBTReader enumValue(String key, Class<T> enumClass, Consumer<T> setter, T defaultValue) {
|
public <T extends Enum<T>> NBTReader enumValue(String key, Class<T> enumClass, Consumer<T> setter, T defaultValue) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
String value = nbt.getString(key);
|
Optional<String> value = nbt.getString(key);
|
||||||
try {
|
if (checkOpt(value)) {
|
||||||
setter.accept(Enum.valueOf(enumClass, value.toUpperCase()));
|
try {
|
||||||
return this;
|
T enumValue = Enum.valueOf(enumClass, value.get().toUpperCase());
|
||||||
} catch (IllegalArgumentException ignored) {
|
setter.accept(enumValue);
|
||||||
|
return this;
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
// 保持setter的当前值
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setter.accept(defaultValue);
|
setter.accept(defaultValue);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nested nbt reader.
|
* Nested nbt reader.
|
||||||
*
|
*
|
||||||
|
|
@ -596,16 +583,18 @@ public class NBTReader {
|
||||||
* @param consumer the consumer
|
* @param consumer the consumer
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
// 嵌套读取支持
|
|
||||||
public NBTReader nested(String key, Consumer<NBTReader> consumer) {
|
public NBTReader nested(String key, Consumer<NBTReader> consumer) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
consumer.accept(new NBTReader(nbt.getCompound(key)));
|
Optional<CompoundTag> compound = nbt.getCompound(key);
|
||||||
|
if (checkOpt(compound)) {
|
||||||
|
consumer.accept(new NBTReader(compound.get()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nested nbt reader.
|
* Nested nbt reader with orElse.
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param consumer the consumer
|
* @param consumer the consumer
|
||||||
|
|
@ -614,7 +603,10 @@ public class NBTReader {
|
||||||
*/
|
*/
|
||||||
public NBTReader nested(String key, Consumer<NBTReader> consumer, Runnable orElse) {
|
public NBTReader nested(String key, Consumer<NBTReader> consumer, Runnable orElse) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
consumer.accept(new NBTReader(nbt.getCompound(key)));
|
Optional<CompoundTag> compound = nbt.getCompound(key);
|
||||||
|
if (checkOpt(compound)) {
|
||||||
|
consumer.accept(new NBTReader(compound.get()));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
orElse.run();
|
orElse.run();
|
||||||
}
|
}
|
||||||
|
|
@ -628,7 +620,6 @@ public class NBTReader {
|
||||||
* @param action the action
|
* @param action the action
|
||||||
* @return the nbt reader
|
* @return the nbt reader
|
||||||
*/
|
*/
|
||||||
// 条件读取
|
|
||||||
public NBTReader ifPresent(String key, Runnable action) {
|
public NBTReader ifPresent(String key, Runnable action) {
|
||||||
if (nbt.contains(key)) {
|
if (nbt.contains(key)) {
|
||||||
action.run();
|
action.run();
|
||||||
|
|
@ -655,7 +646,6 @@ public class NBTReader {
|
||||||
*
|
*
|
||||||
* @return the raw
|
* @return the raw
|
||||||
*/
|
*/
|
||||||
// 获取原始NBT
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CompoundTag getRaw() {
|
public CompoundTag getRaw() {
|
||||||
return nbt;
|
return nbt;
|
||||||
|
|
@ -667,14 +657,20 @@ public class NBTReader {
|
||||||
* @param nbt the nbt
|
* @param nbt the nbt
|
||||||
* @return the vec 3
|
* @return the vec 3
|
||||||
*/
|
*/
|
||||||
// 便捷的静态方法(保持原有功能)
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Vec3 readVec3(@NotNull CompoundTag nbt) {
|
public static Vec3 readVec3(@NotNull CompoundTag nbt) {
|
||||||
if (nbt.contains("X") && nbt.contains("Y") && nbt.contains("Z")) {
|
if (nbt.contains("X") && nbt.contains("Y") && nbt.contains("Z")) {
|
||||||
return new Vec3(
|
Optional<Double> x = nbt.getDouble("X");
|
||||||
nbt.getDouble("X"),
|
Optional<Double> y = nbt.getDouble("Y");
|
||||||
nbt.getDouble("Y"),
|
Optional<Double> z = nbt.getDouble("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 {
|
} else {
|
||||||
throw new IllegalArgumentException("NBT is missing X, Y, or Z value for Vec3");
|
throw new IllegalArgumentException("NBT is missing X, Y, or Z value for Vec3");
|
||||||
|
|
@ -690,11 +686,16 @@ public class NBTReader {
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Vec3 readVec3Safe(@NotNull CompoundTag nbt) {
|
public static Vec3 readVec3Safe(@NotNull CompoundTag nbt) {
|
||||||
if (nbt.contains("X") && nbt.contains("Y") && nbt.contains("Z")) {
|
if (nbt.contains("X") && nbt.contains("Y") && nbt.contains("Z")) {
|
||||||
return new Vec3(
|
Optional<Double> x = nbt.getDouble("X");
|
||||||
nbt.getDouble("X"),
|
Optional<Double> y = nbt.getDouble("Y");
|
||||||
nbt.getDouble("Y"),
|
Optional<Double> z = nbt.getDouble("Z");
|
||||||
nbt.getDouble("Z")
|
if (checkOpt(x, y, z)) {
|
||||||
);
|
return new Vec3(
|
||||||
|
x.get(),
|
||||||
|
y.get(),
|
||||||
|
z.get()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
package top.r3944realms.lib39.util.nbt;
|
package top.r3944realms.lib39.util.storage.nbt;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import com.mojang.authlib.properties.Property;
|
|
||||||
import io.netty.util.internal.StringUtil;
|
|
||||||
import net.minecraft.nbt.*;
|
import net.minecraft.nbt.*;
|
||||||
|
import net.minecraft.world.item.component.ResolvableProfile;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
|
@ -164,6 +163,17 @@ public class NBTWriter {
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public NBTWriter gameProfile(String key, ResolvableProfile profile) {
|
||||||
|
root.store(key, ResolvableProfile.CODEC, profile);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBTWriter gameProfile(String key, @NonNull Optional<ResolvableProfile> profile) {
|
||||||
|
if (profile.isPresent()) {
|
||||||
|
root.store(key, ResolvableProfile.CODEC, profile.get());
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -397,47 +407,15 @@ public class NBTWriter {
|
||||||
}
|
}
|
||||||
return this;
|
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.
|
* Compound nbt writer.
|
||||||
|
* 嵌套CompoundTag
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param consumer the consumer
|
* @param consumer the consumer
|
||||||
* @return the nbt writer
|
* @return the nbt writer
|
||||||
*/
|
*/
|
||||||
// 嵌套CompoundTag
|
|
||||||
public NBTWriter compound(String key, Consumer<NBTWriter> consumer) {
|
public NBTWriter compound(String key, Consumer<NBTWriter> consumer) {
|
||||||
if (consumer != null) {
|
if (consumer != null) {
|
||||||
NBTWriter nestedBuilder = new NBTWriter();
|
NBTWriter nestedBuilder = new NBTWriter();
|
||||||
|
|
@ -496,12 +474,12 @@ public class NBTWriter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List nbt writer.
|
* List nbt writer.
|
||||||
|
* ListTag支持
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param consumer the consumer
|
* @param consumer the consumer
|
||||||
* @return the nbt writer
|
* @return the nbt writer
|
||||||
*/
|
*/
|
||||||
// ListTag支持
|
|
||||||
public NBTWriter list(String key, Consumer<ListNBTBuilder> consumer) {
|
public NBTWriter list(String key, Consumer<ListNBTBuilder> consumer) {
|
||||||
if (consumer != null) {
|
if (consumer != null) {
|
||||||
ListNBTBuilder listBuilder = new ListNBTBuilder();
|
ListNBTBuilder listBuilder = new ListNBTBuilder();
|
||||||
|
|
@ -572,60 +550,6 @@ public class NBTWriter {
|
||||||
return this;
|
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<GameProfile> value) {
|
|
||||||
if (condition && value != null) {
|
|
||||||
root.put(key, writeGameProfile(value.get()));
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String if nbt writer.
|
* String if nbt writer.
|
||||||
*
|
*
|
||||||
|
|
@ -671,21 +595,6 @@ public class NBTWriter {
|
||||||
return this;
|
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<UUID> value) {
|
|
||||||
if (condition && value != null) {
|
|
||||||
root.putUUID(key, value.get());
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boolean value if nbt writer.
|
* Boolean value if nbt writer.
|
||||||
*
|
*
|
||||||
|
|
@ -1162,7 +1071,7 @@ public class NBTWriter {
|
||||||
* @return the all keys
|
* @return the all keys
|
||||||
*/
|
*/
|
||||||
public java.util.Set<String> getAllKeys() {
|
public java.util.Set<String> getAllKeys() {
|
||||||
return root.getAllKeys();
|
return root.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -0,0 +1,557 @@
|
||||||
|
package top.r3944realms.lib39.util.storage.vauleio;
|
||||||
|
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import net.minecraft.world.item.component.ResolvableProfile;
|
||||||
|
import net.minecraft.world.level.storage.ValueInput;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ValueInput Helper类
|
||||||
|
* 提供链式操作和类型安全的ValueInput数据读取
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class ValueInputWriter {
|
||||||
|
private final ValueInput valueInput;
|
||||||
|
|
||||||
|
private ValueInputWriter(ValueInput valueInput) {
|
||||||
|
this.valueInput = valueInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从ValueInput创建读取器
|
||||||
|
*
|
||||||
|
* @param valueInput the value input
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public static ValueInputWriter of(@NotNull ValueInput valueInput) {
|
||||||
|
return new ValueInputWriter(valueInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter string(String key, Consumer<String> setter) {
|
||||||
|
valueInput.getString(key).ifPresent(setter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @param defaultValue the default value
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter string(String key, @NotNull Consumer<String> setter, String defaultValue) {
|
||||||
|
setter.accept(valueInput.getStringOr(key, defaultValue));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Boolean value value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter booleanValue(String key, Consumer<Boolean> setter) {
|
||||||
|
valueInput.read(key, Codec.BOOL).ifPresent(setter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Boolean value value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @param defaultValue the default value
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter booleanValue(String key, @NotNull Consumer<Boolean> setter, boolean defaultValue) {
|
||||||
|
setter.accept(valueInput.getBooleanOr(key, defaultValue));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Byte value value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter byteValue(String key, Consumer<Byte> setter) {
|
||||||
|
valueInput.read(key, Codec.BYTE).ifPresent(setter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Byte value value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @param defaultValue the default value
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter byteValue(String key, @NotNull Consumer<Byte> setter, byte defaultValue) {
|
||||||
|
setter.accept(valueInput.getByteOr(key, defaultValue));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short value value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter shortValue(String key, Consumer<Short> setter) {
|
||||||
|
valueInput.read(key, Codec.SHORT).ifPresent(setter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short value value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @param defaultValue the default value
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter shortValue(String key, @NotNull Consumer<Short> setter, short defaultValue) {
|
||||||
|
setter.accept((short) valueInput.getShortOr(key, defaultValue));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Int value value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter intValue(String key, Consumer<Integer> setter) {
|
||||||
|
valueInput.getInt(key).ifPresent(setter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Int value value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @param defaultValue the default value
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter intValue(String key, @NotNull Consumer<Integer> setter, int defaultValue) {
|
||||||
|
setter.accept(valueInput.getIntOr(key, defaultValue));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Long value value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter longValue(String key, Consumer<Long> setter) {
|
||||||
|
valueInput.getLong(key).ifPresent(setter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Long value value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @param defaultValue the default value
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter longValue(String key, @NotNull Consumer<Long> setter, long defaultValue) {
|
||||||
|
setter.accept(valueInput.getLongOr(key, defaultValue));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Float value value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter floatValue(String key, Consumer<Float> setter) {
|
||||||
|
valueInput.read(key, Codec.FLOAT).ifPresent(setter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Float value value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @param defaultValue the default value
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter floatValue(String key, @NotNull Consumer<Float> setter, float defaultValue) {
|
||||||
|
setter.accept(valueInput.getFloatOr(key, defaultValue));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Double value value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter doubleValue(String key, Consumer<Double> setter) {
|
||||||
|
valueInput.read(key, Codec.DOUBLE).ifPresent(setter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Double value value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @param defaultValue the default value
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter doubleValue(String key, @NotNull Consumer<Double> setter, double defaultValue) {
|
||||||
|
setter.accept(valueInput.getDoubleOr(key, defaultValue));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Int array value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter intArray(String key, Consumer<int[]> setter) {
|
||||||
|
valueInput.getIntArray(key).ifPresent(setter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Int array value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @param defaultValue the default value
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter intArray(String key, @NotNull Consumer<int[]> setter, int[] defaultValue) {
|
||||||
|
setter.accept(valueInput.getIntArray(key).orElse(defaultValue));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Codec value value input reader.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param key the key
|
||||||
|
* @param codec the codec
|
||||||
|
* @param setter the setter
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public <T> ValueInputWriter codecValue(String key, Codec<T> codec, Consumer<T> setter) {
|
||||||
|
valueInput.read(key, codec).ifPresent(setter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Codec value value input reader.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param key the key
|
||||||
|
* @param codec the codec
|
||||||
|
* @param setter the setter
|
||||||
|
* @param defaultValue the default value
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public <T> ValueInputWriter codecValue(String key, Codec<T> codec, @NotNull Consumer<T> setter, T defaultValue) {
|
||||||
|
setter.accept(valueInput.read(key, codec).orElse(defaultValue));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vec 3 value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter vec3(String key, Consumer<Vec3> setter) {
|
||||||
|
valueInput.child(key).ifPresent(child -> {
|
||||||
|
try {
|
||||||
|
Vec3 vec = readVec3(child);
|
||||||
|
setter.accept(vec);
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
// 忽略解析错误
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vec 3 value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param setter the setter
|
||||||
|
* @param defaultValue the default value
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter vec3(String key, Consumer<Vec3> setter, Vec3 defaultValue) {
|
||||||
|
Optional<ValueInput> child = valueInput.child(key);
|
||||||
|
if (child.isPresent()) {
|
||||||
|
try {
|
||||||
|
Vec3 vec = readVec3(child.get());
|
||||||
|
setter.accept(vec);
|
||||||
|
return this;
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
// 忽略解析错误,使用默认值
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setter.accept(defaultValue);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValueInputWriter gameProfile(String key, Consumer<ResolvableProfile> setter) {
|
||||||
|
Optional<ResolvableProfile> read = valueInput.read(key, ResolvableProfile.CODEC);
|
||||||
|
if (read.isPresent()) {
|
||||||
|
try {
|
||||||
|
ResolvableProfile profile = read.get();
|
||||||
|
setter.accept(profile);
|
||||||
|
return this;
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValueInputWriter gameProfile(String key, Consumer<ResolvableProfile> setter, ResolvableProfile defaultValue) {
|
||||||
|
Optional<ResolvableProfile> read = valueInput.read(key, ResolvableProfile.CODEC);
|
||||||
|
if (read.isPresent()) {
|
||||||
|
try {
|
||||||
|
ResolvableProfile profile = read.get();
|
||||||
|
setter.accept(profile);
|
||||||
|
return this;
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setter.accept(defaultValue);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum value value input reader.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param key the key
|
||||||
|
* @param enumClass the enum class
|
||||||
|
* @param setter the setter
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public <T extends Enum<T>> ValueInputWriter enumValue(String key, Class<T> enumClass, Consumer<T> setter) {
|
||||||
|
valueInput.getString(key).ifPresent(value -> {
|
||||||
|
try {
|
||||||
|
setter.accept(Enum.valueOf(enumClass, value.toUpperCase()));
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
// 忽略枚举解析错误
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum value value input reader.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param key the key
|
||||||
|
* @param enumClass the enum class
|
||||||
|
* @param setter the setter
|
||||||
|
* @param defaultValue the default value
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public <T extends Enum<T>> ValueInputWriter enumValue(String key, Class<T> enumClass, Consumer<T> setter, T defaultValue) {
|
||||||
|
Optional<String> value = valueInput.getString(key);
|
||||||
|
if (value.isPresent()) {
|
||||||
|
try {
|
||||||
|
setter.accept(Enum.valueOf(enumClass, value.get().toUpperCase()));
|
||||||
|
return this;
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
// 忽略枚举解析错误
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setter.accept(defaultValue);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nested value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param consumer the consumer
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter nested(String key, Consumer<ValueInputWriter> consumer) {
|
||||||
|
valueInput.child(key).ifPresent(child -> consumer.accept(new ValueInputWriter(child)));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nested value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param consumer the consumer
|
||||||
|
* @param orElse the or else
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter nested(String key, Consumer<ValueInputWriter> consumer, Runnable orElse) {
|
||||||
|
Optional<ValueInput> child = valueInput.child(key);
|
||||||
|
if (child.isPresent()) {
|
||||||
|
consumer.accept(new ValueInputWriter(child.get()));
|
||||||
|
} else {
|
||||||
|
orElse.run();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List value input reader.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param key the key
|
||||||
|
* @param codec the codec
|
||||||
|
* @param consumer the consumer
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public <T> ValueInputWriter list(String key, Codec<T> codec, Consumer<java.util.stream.Stream<T>> consumer) {
|
||||||
|
valueInput.list(key, codec).ifPresent(list -> {
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
consumer.accept(list.stream());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List value input reader.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param key the key
|
||||||
|
* @param codec the codec
|
||||||
|
* @param consumer the consumer
|
||||||
|
* @param defaultValue the default value
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public <T> ValueInputWriter list(String key, Codec<T> codec, @NotNull Consumer<java.util.stream.Stream<T>> consumer, java.util.stream.Stream<T> defaultValue) {
|
||||||
|
Optional<ValueInput.TypedInputList<T>> list = valueInput.list(key, codec);
|
||||||
|
if (list.isPresent() && !list.get().isEmpty()) {
|
||||||
|
consumer.accept(list.get().stream());
|
||||||
|
} else {
|
||||||
|
consumer.accept(defaultValue);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Children list value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param consumer the consumer
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter childrenList(String key, Consumer<java.util.stream.Stream<ValueInputWriter>> consumer) {
|
||||||
|
valueInput.childrenList(key).ifPresent(list -> {
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
consumer.accept(list.stream().map(ValueInputWriter::new));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If present value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param action the action
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter ifPresent(String key, Runnable action) {
|
||||||
|
if (valueInput.child(key).isPresent()) {
|
||||||
|
action.run();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If absent value input reader.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param action the action
|
||||||
|
* @return the value input reader
|
||||||
|
*/
|
||||||
|
public ValueInputWriter ifAbsent(String key, Runnable action) {
|
||||||
|
if (valueInput.child(key).isEmpty()) {
|
||||||
|
action.run();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets raw.
|
||||||
|
*
|
||||||
|
* @return the raw
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public ValueInput getRaw() {
|
||||||
|
return valueInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read vec 3 vec 3.
|
||||||
|
*
|
||||||
|
* @param valueInput the value input
|
||||||
|
* @return the vec 3
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public static Vec3 readVec3(@NotNull ValueInput valueInput) {
|
||||||
|
double x = valueInput.getDoubleOr("X", 0.0);
|
||||||
|
double y = valueInput.getDoubleOr("Y", 0.0);
|
||||||
|
double z = valueInput.getDoubleOr("Z", 0.0);
|
||||||
|
return new Vec3(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read vec 3 safe vec 3.
|
||||||
|
*
|
||||||
|
* @param valueInput the value input
|
||||||
|
* @return the vec 3
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public static Vec3 readVec3Safe(@NotNull ValueInput valueInput) {
|
||||||
|
try {
|
||||||
|
return readVec3(valueInput);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,648 @@
|
||||||
|
package top.r3944realms.lib39.util.storage.vauleio;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import net.minecraft.util.ProblemReporter;
|
||||||
|
import net.minecraft.world.item.component.ResolvableProfile;
|
||||||
|
import net.minecraft.world.level.storage.TagValueOutput;
|
||||||
|
import net.minecraft.world.level.storage.ValueOutput;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jspecify.annotations.NonNull;
|
||||||
|
import org.jspecify.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ValueOutput Helper类
|
||||||
|
* 提供链式操作和类型安全的ValueOutput数据写入
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({"unused", "OptionalUsedAsFieldOrParameterType", "UnusedReturnValue"})
|
||||||
|
public class ValueOutputReader {
|
||||||
|
private final ValueOutput valueOutput;
|
||||||
|
private ValueOutputReader() {
|
||||||
|
this.valueOutput = TagValueOutput.createWithoutContext(ProblemReporter.DISCARDING);
|
||||||
|
}
|
||||||
|
private ValueOutputReader(ValueOutput valueOutput) {
|
||||||
|
this.valueOutput = valueOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个新的NBT构建器
|
||||||
|
*
|
||||||
|
* @return the nbt writer
|
||||||
|
*/
|
||||||
|
@Contract(value = " -> new", pure = true)
|
||||||
|
public static @NotNull ValueOutputReader builder() {
|
||||||
|
return new ValueOutputReader();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从ValueOutput创建写入器
|
||||||
|
*
|
||||||
|
* @param valueOutput the value output
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public static ValueOutputReader of(@NotNull ValueOutput valueOutput) {
|
||||||
|
return new ValueOutputReader(valueOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
// 基本写入方法
|
||||||
|
public ValueOutputReader string(String key, String value) {
|
||||||
|
if (value != null) {
|
||||||
|
valueOutput.putString(key, value);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @param defaultValue the default value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader string(String key, @Nullable String value, String defaultValue) {
|
||||||
|
valueOutput.putString(key, value != null ? value : defaultValue);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader string(String key, @NonNull Optional<String> value) {
|
||||||
|
value.ifPresent(v -> valueOutput.putString(key, v));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Boolean value value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader booleanValue(String key, boolean value) {
|
||||||
|
valueOutput.putBoolean(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Boolean value value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader booleanValue(String key, @NonNull Optional<Boolean> value) {
|
||||||
|
value.ifPresent(v -> valueOutput.putBoolean(key, v));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Byte value value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader byteValue(String key, byte value) {
|
||||||
|
valueOutput.putByte(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Byte value value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader byteValue(String key, @NonNull Optional<Byte> value) {
|
||||||
|
value.ifPresent(v -> valueOutput.putByte(key, v));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short value value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader shortValue(String key, short value) {
|
||||||
|
valueOutput.putShort(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short value value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader shortValue(String key, @NonNull Optional<Short> value) {
|
||||||
|
value.ifPresent(v -> valueOutput.putShort(key, v));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Int value value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader intValue(String key, int value) {
|
||||||
|
valueOutput.putInt(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Int value value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader intValue(String key, @NonNull Optional<Integer> value) {
|
||||||
|
value.ifPresent(v -> valueOutput.putInt(key, v));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Long value value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader longValue(String key, long value) {
|
||||||
|
valueOutput.putLong(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Long value value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader longValue(String key, @NonNull Optional<Long> value) {
|
||||||
|
value.ifPresent(v -> valueOutput.putLong(key, v));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Float value value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader floatValue(String key, float value) {
|
||||||
|
valueOutput.putFloat(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Float value value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader floatValue(String key, @NonNull Optional<Float> value) {
|
||||||
|
value.ifPresent(v -> valueOutput.putFloat(key, v));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Double value value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader doubleValue(String key, double value) {
|
||||||
|
valueOutput.putDouble(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Double value value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader doubleValue(String key, @NonNull Optional<Double> value) {
|
||||||
|
value.ifPresent(v -> valueOutput.putDouble(key, v));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Int array value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader intArray(String key, int[] value) {
|
||||||
|
if (value != null && value.length > 0) {
|
||||||
|
valueOutput.putIntArray(key, value);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Int array value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader intArray(String key, @NonNull Optional<int[]> value) {
|
||||||
|
value.ifPresent(v -> {
|
||||||
|
if (v.length > 0) {
|
||||||
|
valueOutput.putIntArray(key, v);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Codec value value output writer.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param key the key
|
||||||
|
* @param codec the codec
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public <T> ValueOutputReader codecValue(String key, Codec<T> codec, T value) {
|
||||||
|
if (value != null) {
|
||||||
|
valueOutput.store(key, codec, value);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Codec value value output writer.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param key the key
|
||||||
|
* @param codec the codec
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public <T> ValueOutputReader codecValue(String key, Codec<T> codec, @NonNull Optional<T> value) {
|
||||||
|
value.ifPresent(v -> valueOutput.store(key, codec, v));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Codec nullable value value output writer.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param key the key
|
||||||
|
* @param codec the codec
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public <T> ValueOutputReader codecNullable(String key, Codec<T> codec, @Nullable T value) {
|
||||||
|
valueOutput.storeNullable(key, codec, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValueOutputReader gameProfile(String key, ResolvableProfile profile) {
|
||||||
|
valueOutput.store(key, ResolvableProfile.CODEC, profile);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValueOutputReader gameProfile(String key, @NonNull Optional<ResolvableProfile> profile) {
|
||||||
|
if (profile.isPresent()) {
|
||||||
|
valueOutput.store(key, ResolvableProfile.CODEC, profile.get());
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Vec 3 value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param vec the vec
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader vec3(String key, Vec3 vec) {
|
||||||
|
if (vec != null) {
|
||||||
|
ValueOutput child = valueOutput.child(key);
|
||||||
|
writeVec3(child, vec);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vec 3 value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param vec the vec
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader vec3(String key, @NonNull Optional<Vec3> vec) {
|
||||||
|
vec.ifPresent(v -> vec3(key, v));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum value value output writer.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public <T extends Enum<T>> ValueOutputReader enumValue(String key, T value) {
|
||||||
|
if (value != null) {
|
||||||
|
valueOutput.putString(key, value.name().toLowerCase());
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum value value output writer.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public <T extends Enum<T>> ValueOutputReader enumValue(String key, @NonNull Optional<T> value) {
|
||||||
|
value.ifPresent(v -> valueOutput.putString(key, v.name().toLowerCase()));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nested value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param consumer the consumer
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader nested(String key, @NonNull Consumer<ValueOutputReader> consumer) {
|
||||||
|
ValueOutput child = valueOutput.child(key);
|
||||||
|
consumer.accept(new ValueOutputReader(child));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nested if present value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param supplier the supplier
|
||||||
|
* @param consumer the consumer
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader nestedIfPresent(String key, @NonNull Supplier<Boolean> supplier, Consumer<ValueOutputReader> consumer) {
|
||||||
|
if (supplier.get()) {
|
||||||
|
ValueOutput child = valueOutput.child(key);
|
||||||
|
consumer.accept(new ValueOutputReader(child));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List value output writer.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param key the key
|
||||||
|
* @param elementCodec the element codec
|
||||||
|
* @param elements the elements
|
||||||
|
* @param consumer the consumer
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public <T> ValueOutputReader list(String key, Codec<T> elementCodec, Iterable<T> elements, Consumer<TypedListWriter<T>> consumer) {
|
||||||
|
ValueOutput.TypedOutputList<T> list = valueOutput.list(key, elementCodec);
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
TypedListWriter<T> writer = new TypedListWriter<>(list);
|
||||||
|
consumer.accept(writer);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List value output writer.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param key the key
|
||||||
|
* @param elementCodec the element codec
|
||||||
|
* @param elements the elements
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public <T> ValueOutputReader list(String key, Codec<T> elementCodec, @NonNull Iterable<T> elements) {
|
||||||
|
ValueOutput.TypedOutputList<T> list = valueOutput.list(key, elementCodec);
|
||||||
|
for (T element : elements) {
|
||||||
|
if (element != null) {
|
||||||
|
list.add(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Children list value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param consumer the consumer
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader childrenList(String key, Consumer<ChildrenListWriter> consumer) {
|
||||||
|
ValueOutput.ValueOutputList list = valueOutput.childrenList(key);
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
ChildrenListWriter writer = new ChildrenListWriter(list);
|
||||||
|
consumer.accept(writer);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If present value output writer.
|
||||||
|
*
|
||||||
|
* @param condition the condition
|
||||||
|
* @param action the action
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader ifPresent(boolean condition, Consumer<ValueOutputReader> action) {
|
||||||
|
if (condition) {
|
||||||
|
action.accept(this);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If present value output writer.
|
||||||
|
*
|
||||||
|
* @param condition the condition
|
||||||
|
* @param action the action
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader ifPresent(@NonNull Supplier<Boolean> condition, Consumer<ValueOutputReader> action) {
|
||||||
|
if (condition.get()) {
|
||||||
|
action.accept(this);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discard value output writer.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @return the value output writer
|
||||||
|
*/
|
||||||
|
public ValueOutputReader discard(String key) {
|
||||||
|
valueOutput.discard(key);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets raw.
|
||||||
|
*
|
||||||
|
* @return the raw
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public ValueOutput getRaw() {
|
||||||
|
return valueOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write vec 3.
|
||||||
|
*
|
||||||
|
* @param valueOutput the value output
|
||||||
|
* @param vec the vec
|
||||||
|
*/
|
||||||
|
public static void writeVec3(@NotNull ValueOutput valueOutput, @NotNull Vec3 vec) {
|
||||||
|
valueOutput.putDouble("X", vec.x);
|
||||||
|
valueOutput.putDouble("Y", vec.y);
|
||||||
|
valueOutput.putDouble("Z", vec.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write vec 3 safe.
|
||||||
|
*
|
||||||
|
* @param valueOutput the value output
|
||||||
|
* @param vec the vec
|
||||||
|
*/
|
||||||
|
public static void writeVec3Safe(@NotNull ValueOutput valueOutput, @Nullable Vec3 vec) {
|
||||||
|
if (vec != null) {
|
||||||
|
writeVec3(valueOutput, vec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Typed list writer.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
*/
|
||||||
|
public static class TypedListWriter<T> {
|
||||||
|
private final ValueOutput.TypedOutputList<T> list;
|
||||||
|
|
||||||
|
private TypedListWriter(ValueOutput.TypedOutputList<T> list) {
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add typed list writer.
|
||||||
|
*
|
||||||
|
* @param element the element
|
||||||
|
* @return the typed list writer
|
||||||
|
*/
|
||||||
|
public TypedListWriter<T> add(T element) {
|
||||||
|
if (element != null) {
|
||||||
|
list.add(element);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add all typed list writer.
|
||||||
|
*
|
||||||
|
* @param elements the elements
|
||||||
|
* @return the typed list writer
|
||||||
|
*/
|
||||||
|
public TypedListWriter<T> addAll(@NonNull Iterable<T> elements) {
|
||||||
|
for (T element : elements) {
|
||||||
|
if (element != null) {
|
||||||
|
list.add(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is empty boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return list.isEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Children list writer.
|
||||||
|
*/
|
||||||
|
public static class ChildrenListWriter {
|
||||||
|
private final ValueOutput.ValueOutputList list;
|
||||||
|
|
||||||
|
private ChildrenListWriter(ValueOutput.ValueOutputList list) {
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add child value output writer.
|
||||||
|
*
|
||||||
|
* @param consumer the consumer
|
||||||
|
* @return the children list writer
|
||||||
|
*/
|
||||||
|
public ChildrenListWriter addChild(@NonNull Consumer<ValueOutputReader> consumer) {
|
||||||
|
ValueOutput child = list.addChild();
|
||||||
|
consumer.accept(new ValueOutputReader(child));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discard last children list writer.
|
||||||
|
*
|
||||||
|
* @return the children list writer
|
||||||
|
*/
|
||||||
|
public ChildrenListWriter discardLast() {
|
||||||
|
list.discardLast();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is empty boolean.
|
||||||
|
*
|
||||||
|
* @return the boolean
|
||||||
|
*/
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return list.isEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,12 +16,11 @@ import net.minecraft.util.Mth;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.world.effect.MobEffect;
|
import net.minecraft.world.effect.MobEffect;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.npc.VillagerDataHolder;
|
import net.minecraft.world.entity.npc.villager.VillagerDataHolder;
|
||||||
import net.minecraft.world.entity.npc.VillagerTrades;
|
import net.minecraft.world.entity.npc.villager.VillagerTrades;
|
||||||
import net.minecraft.world.entity.npc.VillagerType;
|
import net.minecraft.world.entity.npc.villager.VillagerType;
|
||||||
import net.minecraft.world.item.*;
|
import net.minecraft.world.item.*;
|
||||||
import net.minecraft.world.item.alchemy.Potion;
|
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.alchemy.PotionContents;
|
||||||
import net.minecraft.world.item.component.DyedItemColor;
|
import net.minecraft.world.item.component.DyedItemColor;
|
||||||
import net.minecraft.world.item.component.SuspiciousStewEffects;
|
import net.minecraft.world.item.component.SuspiciousStewEffects;
|
||||||
|
|
@ -42,7 +41,6 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 村民交易构建器
|
* 村民交易构建器
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
import net.minecraft.commands.CommandBuildContext;
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
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.ICommandHelpManager;
|
||||||
import top.r3944realms.lib39.core.command.model.CommandNode;
|
import top.r3944realms.lib39.core.command.model.CommandNode;
|
||||||
import top.r3944realms.lib39.core.command.model.CommandPath;
|
import top.r3944realms.lib39.core.command.model.CommandPath;
|
||||||
|
|
@ -50,7 +50,7 @@ public interface RegisterCommandHelpCallback {
|
||||||
*
|
*
|
||||||
* @return the id
|
* @return the id
|
||||||
*/
|
*/
|
||||||
ResourceLocation getID();
|
Identifier getID();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add child.
|
* Add child.
|
||||||
|
|
@ -103,7 +103,7 @@ public interface RegisterCommandHelpCallback {
|
||||||
*/
|
*/
|
||||||
record CommandHelpRegistrar(LiteralArgumentBuilder<CommandSourceStack> builder, ICommandHelpManager helpManager, CommandBuildContext context) implements Registrar {
|
record CommandHelpRegistrar(LiteralArgumentBuilder<CommandSourceStack> builder, ICommandHelpManager helpManager, CommandBuildContext context) implements Registrar {
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getID() {
|
public Identifier getID() {
|
||||||
return helpManager.getID();
|
return helpManager.getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package top.r3944realms.lib39.api.callback;
|
||||||
import net.fabricmc.fabric.api.event.Event;
|
import net.fabricmc.fabric.api.event.Event;
|
||||||
import net.fabricmc.fabric.api.event.EventFactory;
|
import net.fabricmc.fabric.api.event.EventFactory;
|
||||||
import net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup;
|
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 net.minecraft.world.entity.Entity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import top.r3944realms.lib39.core.sync.ISyncData;
|
import top.r3944realms.lib39.core.sync.ISyncData;
|
||||||
|
|
@ -62,7 +62,7 @@ public interface SyncManagerRegisterCallback {
|
||||||
* @param dataClass the data class
|
* @param dataClass the data class
|
||||||
*/
|
*/
|
||||||
<T extends ISyncData<?>> void register(
|
<T extends ISyncData<?>> void register(
|
||||||
ResourceLocation id,
|
Identifier id,
|
||||||
ISyncManager<Entity, T> syncManager,
|
ISyncManager<Entity, T> syncManager,
|
||||||
Class<T> dataClass
|
Class<T> dataClass
|
||||||
);
|
);
|
||||||
|
|
@ -73,7 +73,7 @@ public interface SyncManagerRegisterCallback {
|
||||||
* @param id the id
|
* @param id the id
|
||||||
* @param entityClasses the entity classes
|
* @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 id the id
|
||||||
* @param entityClasses the entity classes
|
* @param entityClasses the entity classes
|
||||||
*/
|
*/
|
||||||
void disallowEntityClass(ResourceLocation id, Class<?>... entityClasses);
|
void disallowEntityClass(Identifier id, Class<?>... entityClasses);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 绑定 EntityApiLookup(用于分离注册的情况)
|
* 绑定 EntityApiLookup(用于分离注册的情况)
|
||||||
|
|
@ -91,7 +91,7 @@ public interface SyncManagerRegisterCallback {
|
||||||
* @param apiLookup the EntityApiLookup
|
* @param apiLookup the EntityApiLookup
|
||||||
*/
|
*/
|
||||||
<T extends ISyncData<?>> void bindApiLookup(
|
<T extends ISyncData<?>> void bindApiLookup(
|
||||||
ResourceLocation id,
|
Identifier id,
|
||||||
net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup<T, Void> apiLookup
|
net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup<T, Void> apiLookup
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -100,7 +100,7 @@ public interface SyncManagerRegisterCallback {
|
||||||
*
|
*
|
||||||
* @param id the id
|
* @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
|
* @param allowedEntityClasses the allowed entity classes
|
||||||
*/
|
*/
|
||||||
default <T extends ISyncData<?>> void registerComplete(
|
default <T extends ISyncData<?>> void registerComplete(
|
||||||
ResourceLocation id,
|
Identifier id,
|
||||||
ISyncManager<Entity, T> syncManager,
|
ISyncManager<Entity, T> syncManager,
|
||||||
Class<T> dataClass,
|
Class<T> dataClass,
|
||||||
Class<?>... allowedEntityClasses
|
Class<?>... allowedEntityClasses
|
||||||
|
|
@ -132,7 +132,7 @@ public interface SyncManagerRegisterCallback {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends ISyncData<?>> void register(
|
public <T extends ISyncData<?>> void register(
|
||||||
@NotNull ResourceLocation id,
|
@NotNull Identifier id,
|
||||||
@NotNull ISyncManager<Entity, T> syncManager,
|
@NotNull ISyncManager<Entity, T> syncManager,
|
||||||
@NotNull Class<T> dataClass
|
@NotNull Class<T> dataClass
|
||||||
) {
|
) {
|
||||||
|
|
@ -140,25 +140,25 @@ public interface SyncManagerRegisterCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void allowEntityClass(@NotNull ResourceLocation id, @NotNull Class<?>... entityClasses) {
|
public void allowEntityClass(@NotNull Identifier id, @NotNull Class<?>... entityClasses) {
|
||||||
manager.allowEntityClass(id, entityClasses);
|
manager.allowEntityClass(id, entityClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disallowEntityClass(@NotNull ResourceLocation id, @NotNull Class<?>... entityClasses) {
|
public void disallowEntityClass(@NotNull Identifier id, @NotNull Class<?>... entityClasses) {
|
||||||
manager.disallowEntityClass(id, entityClasses);
|
manager.disallowEntityClass(id, entityClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends ISyncData<?>> void bindApiLookup(
|
public <T extends ISyncData<?>> void bindApiLookup(
|
||||||
@NotNull ResourceLocation id,
|
@NotNull Identifier id,
|
||||||
@NotNull EntityApiLookup<T, Void> apiLookup
|
@NotNull EntityApiLookup<T, Void> apiLookup
|
||||||
) {
|
) {
|
||||||
manager.bindApiLookup(id, apiLookup);
|
manager.bindApiLookup(id, apiLookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unbindApiLookup(@NotNull ResourceLocation id) {
|
public void unbindApiLookup(@NotNull Identifier id) {
|
||||||
manager.unbindApiLookup(id);
|
manager.unbindApiLookup(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.base.compat.jade;
|
package top.r3944realms.lib39.base.compat.jade;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import snownee.jade.api.IWailaClientRegistration;
|
import snownee.jade.api.IWailaClientRegistration;
|
||||||
import snownee.jade.api.IWailaPlugin;
|
import snownee.jade.api.IWailaPlugin;
|
||||||
|
|
@ -18,7 +18,7 @@ public class FabricJadePlugin implements IWailaPlugin {
|
||||||
/**
|
/**
|
||||||
* The constant UID.
|
* The constant UID.
|
||||||
*/
|
*/
|
||||||
public static final ResourceLocation UID = Lib39.rl("lib39");
|
public static final Identifier UID = Lib39.rl("lib39");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerClient(@NotNull IWailaClientRegistration registration) {
|
public void registerClient(@NotNull IWailaClientRegistration registration) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package top.r3944realms.lib39.base.compat.jade.provider;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import snownee.jade.api.BlockAccessor;
|
import snownee.jade.api.BlockAccessor;
|
||||||
import snownee.jade.api.IBlockComponentProvider;
|
import snownee.jade.api.IBlockComponentProvider;
|
||||||
|
|
@ -16,7 +16,7 @@ import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
|
||||||
*/
|
*/
|
||||||
public class FabricDollComponentProvider implements IBlockComponentProvider {
|
public class FabricDollComponentProvider implements IBlockComponentProvider {
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getUid() {
|
public Identifier getUid() {
|
||||||
return FabricJadePlugin.UID;
|
return FabricJadePlugin.UID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
import net.minecraft.core.component.DataComponents;
|
import net.minecraft.core.component.DataComponents;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.Services;
|
import net.minecraft.server.Services;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
|
@ -122,8 +122,8 @@ public class FabricCommonEventHandler {
|
||||||
public static void onServerTick(MinecraftServer server) {
|
public static void onServerTick(MinecraftServer server) {
|
||||||
if (syncData2Manager == null) return;
|
if (syncData2Manager == null) return;
|
||||||
if (server.getTickCount() % 10 == 0)
|
if (server.getTickCount() % 10 == 0)
|
||||||
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
|
syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
|
||||||
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
|
syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -135,7 +135,7 @@ public class FabricCommonEventHandler {
|
||||||
public static void onEntityJoinWorld(@NotNull Entity entity, ServerLevel level) {
|
public static void onEntityJoinWorld(@NotNull Entity entity, ServerLevel level) {
|
||||||
if (entity.level().isClientSide) return;
|
if (entity.level().isClientSide) return;
|
||||||
|
|
||||||
for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
|
for (Identifier id : syncData2Manager.getRegisteredKeys()) {
|
||||||
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
|
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
|
||||||
syncData2Manager.trackEntityForManager(entity, id);
|
syncData2Manager.trackEntityForManager(entity, id);
|
||||||
}
|
}
|
||||||
|
|
@ -151,7 +151,7 @@ public class FabricCommonEventHandler {
|
||||||
public static void onEntityLeaveWorld(@NotNull Entity entity, ServerLevel level) {
|
public static void onEntityLeaveWorld(@NotNull Entity entity, ServerLevel level) {
|
||||||
if (entity.level().isClientSide) return;
|
if (entity.level().isClientSide) return;
|
||||||
|
|
||||||
for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
|
for (Identifier id : syncData2Manager.getRegisteredKeys()) {
|
||||||
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
|
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
|
||||||
syncData2Manager.untrackEntityForManager(entity, id);
|
syncData2Manager.untrackEntityForManager(entity, id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
import net.minecraft.network.codec.StreamCodec;
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
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.entity.Entity;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
@ -22,11 +22,11 @@ import java.util.Optional;
|
||||||
/**
|
/**
|
||||||
* The type Sync nbt lookup data entity s 2 c payload.
|
* 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.
|
* 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");
|
Lib39.rl("sync_nbt_lookup_data_entity");
|
||||||
/**
|
/**
|
||||||
* The constant TYPE.
|
* The constant TYPE.
|
||||||
|
|
@ -56,7 +56,7 @@ public record SyncNBTLookupDataEntityS2CPayload(int entityId, ResourceLocation i
|
||||||
* @param buf the buffer
|
* @param buf the buffer
|
||||||
*/
|
*/
|
||||||
public SyncNBTLookupDataEntityS2CPayload(RegistryFriendlyByteBuf buf) {
|
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) {
|
public void write(@NotNull FriendlyByteBuf friendlyByteBuf) {
|
||||||
friendlyByteBuf.writeInt(entityId);
|
friendlyByteBuf.writeInt(entityId);
|
||||||
friendlyByteBuf.writeResourceLocation(id);
|
friendlyByteBuf.writeIdentifier(id);
|
||||||
friendlyByteBuf.writeNbt(data);
|
friendlyByteBuf.writeNbt(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package top.r3944realms.lib39.core.sync;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup;
|
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 net.minecraft.world.entity.Entity;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
|
@ -17,10 +17,10 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
|
||||||
/**
|
/**
|
||||||
* The Typed entries.
|
* The Typed entries.
|
||||||
*/
|
*/
|
||||||
protected final Map<ResourceLocation, TypedSyncEntry<?>> typedEntries = Maps.newConcurrentMap();
|
protected final Map<Identifier, TypedSyncEntry<?>> typedEntries = Maps.newConcurrentMap();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<ResourceLocation, TypedSyncEntry<?>> getTypedEntries() {
|
protected Map<Identifier, TypedSyncEntry<?>> getTypedEntries() {
|
||||||
return typedEntries;
|
return typedEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,11 +57,11 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
|
||||||
* @param dataClass the data class
|
* @param dataClass the data class
|
||||||
*/
|
*/
|
||||||
public <T extends ISyncData<?>> void registerManager(
|
public <T extends ISyncData<?>> void registerManager(
|
||||||
ResourceLocation key,
|
Identifier key,
|
||||||
ISyncManager<Entity, T> manager,
|
ISyncManager<Entity, T> manager,
|
||||||
Class<T> dataClass
|
Class<T> 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(manager, "Sync manager cannot be null");
|
||||||
Objects.requireNonNull(dataClass, "Data class cannot be null");
|
Objects.requireNonNull(dataClass, "Data class cannot be null");
|
||||||
|
|
||||||
|
|
@ -77,8 +77,8 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param apiLookup the EntityApiLookup
|
* @param apiLookup the EntityApiLookup
|
||||||
*/
|
*/
|
||||||
public <T extends ISyncData<?>> void bindApiLookup(ResourceLocation key, EntityApiLookup<T, Void> apiLookup) {
|
public <T extends ISyncData<?>> void bindApiLookup(Identifier key, EntityApiLookup<T, Void> apiLookup) {
|
||||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||||
Objects.requireNonNull(apiLookup, "EntityApiLookup cannot be null");
|
Objects.requireNonNull(apiLookup, "EntityApiLookup cannot be null");
|
||||||
|
|
||||||
TypedSyncEntry<?> entry = typedEntries.get(key);
|
TypedSyncEntry<?> entry = typedEntries.get(key);
|
||||||
|
|
@ -94,8 +94,8 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
*/
|
*/
|
||||||
public void unbindApiLookup(ResourceLocation key) {
|
public void unbindApiLookup(Identifier key) {
|
||||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||||
|
|
||||||
TypedSyncEntry<?> entry = typedEntries.get(key);
|
TypedSyncEntry<?> entry = typedEntries.get(key);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
|
|
@ -112,7 +112,7 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
|
||||||
* @param newApiLookup the new api lookup
|
* @param newApiLookup the new api lookup
|
||||||
*/
|
*/
|
||||||
protected <T extends ISyncData<?>> void updateApiLookupInEntry(
|
protected <T extends ISyncData<?>> void updateApiLookupInEntry(
|
||||||
ResourceLocation id,
|
Identifier id,
|
||||||
TypedSyncEntry<?> entry,
|
TypedSyncEntry<?> entry,
|
||||||
EntityApiLookup<T, Void> newApiLookup
|
EntityApiLookup<T, Void> newApiLookup
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package top.r3944realms.lib39.core.sync;
|
package top.r3944realms.lib39.core.sync;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup;
|
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 net.minecraft.world.entity.Entity;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import top.r3944realms.lib39.core.event.FabricCommonEventHandler;
|
import top.r3944realms.lib39.core.event.FabricCommonEventHandler;
|
||||||
|
|
@ -25,7 +25,7 @@ public abstract class SyncLookupProvider<T extends NBTEntitySyncData> implements
|
||||||
*
|
*
|
||||||
* @return the id
|
* @return the id
|
||||||
*/
|
*/
|
||||||
protected abstract ResourceLocation getId();
|
protected abstract Identifier getId();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public @Nullable T find(Entity entity, Void context) {
|
public @Nullable T find(Entity entity, Void context) {
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@ package top.r3944realms.lib39.example.content.data;
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import top.r3944realms.lib39.Lib39;
|
import top.r3944realms.lib39.Lib39;
|
||||||
import top.r3944realms.lib39.core.sync.IFabricUpdate;
|
import top.r3944realms.lib39.core.sync.IFabricUpdate;
|
||||||
import top.r3944realms.lib39.util.nbt.NBTReader;
|
import top.r3944realms.lib39.util.storage.nbt.NBTReader;
|
||||||
import top.r3944realms.lib39.util.nbt.NBTWriter;
|
import top.r3944realms.lib39.util.storage.nbt.NBTWriter;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
@ -23,7 +23,7 @@ public class FabricTestSyncData extends AbstractedTestSyncData implements IFabri
|
||||||
/**
|
/**
|
||||||
* The constant ID.
|
* 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 键常量
|
// NBT 键常量
|
||||||
private static final String NBT_KEY_STRING = "test_string";
|
private static final String NBT_KEY_STRING = "test_string";
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.example.content.data;
|
package top.r3944realms.lib39.example.content.data;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import top.r3944realms.lib39.core.sync.SyncLookupProvider;
|
import top.r3944realms.lib39.core.sync.SyncLookupProvider;
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ public class FabricTestSyncLookupProvider extends SyncLookupProvider<AbstractedT
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResourceLocation getId() {
|
protected Identifier getId() {
|
||||||
return FabricTestSyncData.ID;
|
return FabricTestSyncData.ID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package top.r3944realms.lib39.example.core.compat;
|
package top.r3944realms.lib39.example.core.compat;
|
||||||
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import top.r3944realms.lib39.Lib39;
|
import top.r3944realms.lib39.Lib39;
|
||||||
import top.r3944realms.lib39.core.compat.ICompat;
|
import top.r3944realms.lib39.core.compat.ICompat;
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ public class FabricLib39Compat implements ICompat {
|
||||||
/**
|
/**
|
||||||
* The constant ID.
|
* The constant ID.
|
||||||
*/
|
*/
|
||||||
public static ResourceLocation ID = Lib39.rl("lib39");
|
public static Identifier ID = Lib39.rl("lib39");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInitialize(boolean initialize) {
|
public void setInitialize(boolean initialize) {
|
||||||
|
|
@ -33,7 +33,7 @@ public class FabricLib39Compat implements ICompat {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation id() {
|
public Identifier id() {
|
||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.example.core.compat;
|
package top.r3944realms.lib39.example.core.compat;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import top.r3944realms.lib39.Lib39;
|
import top.r3944realms.lib39.Lib39;
|
||||||
import top.r3944realms.lib39.core.compat.CompatManager;
|
import top.r3944realms.lib39.core.compat.CompatManager;
|
||||||
import top.r3944realms.lib39.core.compat.ICompat;
|
import top.r3944realms.lib39.core.compat.ICompat;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
import net.minecraft.network.codec.StreamCodec;
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
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.server.level.ServerPlayer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import top.r3944realms.lib39.Lib39;
|
import top.r3944realms.lib39.Lib39;
|
||||||
|
|
@ -19,7 +19,7 @@ public record FabricClientDataPacket(AbstractedTestSyncData clientData, int targ
|
||||||
/**
|
/**
|
||||||
* The constant CLIENT_TEST_DATA.
|
* The constant CLIENT_TEST_DATA.
|
||||||
*/
|
*/
|
||||||
public static final ResourceLocation CLIENT_TEST_DATA =
|
public static final Identifier CLIENT_TEST_DATA =
|
||||||
Lib39.rl("client_test_data");
|
Lib39.rl("client_test_data");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import net.minecraft.commands.CommandBuildContext;
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.neoforged.bus.api.Event;
|
import net.neoforged.bus.api.Event;
|
||||||
import top.r3944realms.lib39.core.command.ICommandHelpManager;
|
import top.r3944realms.lib39.core.command.ICommandHelpManager;
|
||||||
import top.r3944realms.lib39.core.command.model.CommandNode;
|
import top.r3944realms.lib39.core.command.model.CommandNode;
|
||||||
|
|
@ -37,7 +37,7 @@ public class RegisterCommandHelpEvent extends Event {
|
||||||
*
|
*
|
||||||
* @return the id
|
* @return the id
|
||||||
*/
|
*/
|
||||||
public ResourceLocation getID() {
|
public Identifier getID() {
|
||||||
return helpManager.getID();
|
return helpManager.getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.api.event;
|
package top.r3944realms.lib39.api.event;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.neoforged.bus.api.Event;
|
import net.neoforged.bus.api.Event;
|
||||||
import net.neoforged.neoforge.capabilities.EntityCapability;
|
import net.neoforged.neoforge.capabilities.EntityCapability;
|
||||||
import top.r3944realms.lib39.core.sync.ISyncData;
|
import top.r3944realms.lib39.core.sync.ISyncData;
|
||||||
|
|
@ -45,7 +45,7 @@ public class SyncManagerRegisterEvent extends Event {
|
||||||
* @param capability the capability
|
* @param capability the capability
|
||||||
*/
|
*/
|
||||||
public <K, T extends ISyncData<?>> void registerSyncManager(
|
public <K, T extends ISyncData<?>> void registerSyncManager(
|
||||||
ResourceLocation id,
|
Identifier id,
|
||||||
ISyncManager<EntityCapability<T, Void>, T> syncManager,
|
ISyncManager<EntityCapability<T, Void>, T> syncManager,
|
||||||
EntityCapability<T, Void> capability
|
EntityCapability<T, Void> capability
|
||||||
) {
|
) {
|
||||||
|
|
@ -57,7 +57,7 @@ public class SyncManagerRegisterEvent extends Event {
|
||||||
*
|
*
|
||||||
* @param id the id
|
* @param id the id
|
||||||
*/
|
*/
|
||||||
public void unregisterSyncManager(ResourceLocation id) {
|
public void unregisterSyncManager(Identifier id) {
|
||||||
syncs2Manager.removeManager(id);
|
syncs2Manager.removeManager(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,7 +67,7 @@ public class SyncManagerRegisterEvent extends Event {
|
||||||
* @param id the id
|
* @param id the id
|
||||||
* @param entityClasses the entity classes
|
* @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);
|
syncs2Manager.allowEntityClass(id, entityClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ public class SyncManagerRegisterEvent extends Event {
|
||||||
* @param id the id
|
* @param id the id
|
||||||
* @param entityClasses the entity classes
|
* @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);
|
syncs2Manager.disallowEntityClass(id, entityClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,7 +88,7 @@ public class SyncManagerRegisterEvent extends Event {
|
||||||
* @param id 必须先注册安全同步管理器,再绑定Cap,否则会抛出{@link IllegalStateException 未找到对应安全同步管理器}
|
* @param id 必须先注册安全同步管理器,再绑定Cap,否则会抛出{@link IllegalStateException 未找到对应安全同步管理器}
|
||||||
* @param capability the capability
|
* @param capability the capability
|
||||||
*/
|
*/
|
||||||
public <T extends ISyncData<?>> void bindCapability(ResourceLocation id, EntityCapability<T, Void> capability) {
|
public <T extends ISyncData<?>> void bindCapability(Identifier id, EntityCapability<T, Void> capability) {
|
||||||
syncs2Manager.bindCapability(id, capability);
|
syncs2Manager.bindCapability(id, capability);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@ public class SyncManagerRegisterEvent extends Event {
|
||||||
*
|
*
|
||||||
* @param id the id
|
* @param id the id
|
||||||
*/
|
*/
|
||||||
public void unbindCapability(ResourceLocation id) {
|
public void unbindCapability(Identifier id) {
|
||||||
syncs2Manager.unbindCapability(id);
|
syncs2Manager.unbindCapability(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,7 +112,7 @@ public class SyncManagerRegisterEvent extends Event {
|
||||||
* @param allowedEntityClasses the allowed entity classes
|
* @param allowedEntityClasses the allowed entity classes
|
||||||
*/
|
*/
|
||||||
public <K, T extends ISyncData<?>> void registerComplete(
|
public <K, T extends ISyncData<?>> void registerComplete(
|
||||||
ResourceLocation id,
|
Identifier id,
|
||||||
ISyncManager<EntityCapability<T, Void>, T> syncManager,
|
ISyncManager<EntityCapability<T, Void>, T> syncManager,
|
||||||
EntityCapability<T, Void> capability,
|
EntityCapability<T, Void> capability,
|
||||||
Class<?>... allowedEntityClasses
|
Class<?>... allowedEntityClasses
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.base.compat.jade;
|
package top.r3944realms.lib39.base.compat.jade;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import snownee.jade.api.IWailaClientRegistration;
|
import snownee.jade.api.IWailaClientRegistration;
|
||||||
import snownee.jade.api.IWailaPlugin;
|
import snownee.jade.api.IWailaPlugin;
|
||||||
|
|
@ -17,7 +17,7 @@ public class NeoForgeJadePlugin implements IWailaPlugin {
|
||||||
/**
|
/**
|
||||||
* The constant UID.
|
* The constant UID.
|
||||||
*/
|
*/
|
||||||
public static final ResourceLocation UID = Lib39.rl("lib39");
|
public static final Identifier UID = Lib39.rl("lib39");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerClient(@NotNull IWailaClientRegistration registration) {
|
public void registerClient(@NotNull IWailaClientRegistration registration) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package top.r3944realms.lib39.base.compat.jade.provider;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import snownee.jade.api.BlockAccessor;
|
import snownee.jade.api.BlockAccessor;
|
||||||
import snownee.jade.api.IBlockComponentProvider;
|
import snownee.jade.api.IBlockComponentProvider;
|
||||||
|
|
@ -17,7 +17,7 @@ import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
|
||||||
*/
|
*/
|
||||||
public class NeoForgeDollComponentProvider implements IBlockComponentProvider {
|
public class NeoForgeDollComponentProvider implements IBlockComponentProvider {
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getUid() {
|
public Identifier getUid() {
|
||||||
return NeoForgeJadePlugin.UID;
|
return NeoForgeJadePlugin.UID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,37 +44,37 @@ public class Lib39BaseDataGenEvent {
|
||||||
}
|
}
|
||||||
private static void LanguageGenerator(@NotNull GatherDataEvent event, McLocale language) {
|
private static void LanguageGenerator(@NotNull GatherDataEvent event, McLocale language) {
|
||||||
event.getGenerator().addProvider(
|
event.getGenerator().addProvider(
|
||||||
event.includeClient(),
|
true,
|
||||||
(DataProvider.Factory<SimpleLanguageProvider>) pOutput -> new SimpleLanguageProvider(pOutput, Lib39.MOD_ID ,language , Lib39LangKey.INSTANCE)
|
(DataProvider.Factory<SimpleLanguageProvider>) pOutput -> new SimpleLanguageProvider(pOutput, Lib39.MOD_ID ,language , Lib39LangKey.INSTANCE)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
private static void ItemModelDataGenerate(@NotNull GatherDataEvent event) {
|
private static void ItemModelDataGenerate(@NotNull GatherDataEvent event) {
|
||||||
event.getGenerator().addProvider(
|
event.getGenerator().addProvider(
|
||||||
event.includeClient(),
|
true,
|
||||||
(DataProvider.Factory<Lib39ItemModelProvider>) pOutput -> new Lib39ItemModelProvider(pOutput, event.getExistingFileHelper())
|
(DataProvider.Factory<Lib39ItemModelProvider>) pOutput -> new Lib39ItemModelProvider(pOutput, event.getExistingFileHelper())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
private static void BlockModelDataGenerate(@NotNull GatherDataEvent event) {
|
private static void BlockModelDataGenerate(@NotNull GatherDataEvent event) {
|
||||||
event.getGenerator().addProvider(
|
event.getGenerator().addProvider(
|
||||||
event.includeClient(),
|
true,
|
||||||
(DataProvider.Factory<Lib39BlockModelProvider>) pOutput -> new Lib39BlockModelProvider(pOutput, event.getExistingFileHelper())
|
(DataProvider.Factory<Lib39BlockModelProvider>) pOutput -> new Lib39BlockModelProvider(pOutput, event.getExistingFileHelper())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
private static void BlockStateDataGenerate(@NotNull GatherDataEvent event) {
|
private static void BlockStateDataGenerate(@NotNull GatherDataEvent event) {
|
||||||
event.getGenerator().addProvider(
|
event.getGenerator().addProvider(
|
||||||
event.includeClient(),
|
true,
|
||||||
(DataProvider.Factory<Lib39BlockStatesProvider>) pOutput -> new Lib39BlockStatesProvider(pOutput, event.getExistingFileHelper())
|
(DataProvider.Factory<Lib39BlockStatesProvider>) pOutput -> new Lib39BlockStatesProvider(pOutput, event.getExistingFileHelper())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
private static void SoundDefinitionDataGenerate(@NotNull GatherDataEvent event) {
|
private static void SoundDefinitionDataGenerate(@NotNull GatherDataEvent event) {
|
||||||
event.getGenerator().addProvider(
|
event.getGenerator().addProvider(
|
||||||
event.includeClient(),
|
true,
|
||||||
(DataProvider.Factory<Lib39SoundDefinitionsProvider>) pOutput -> new Lib39SoundDefinitionsProvider(pOutput, event.getExistingFileHelper())
|
(DataProvider.Factory<Lib39SoundDefinitionsProvider>) pOutput -> new Lib39SoundDefinitionsProvider(pOutput, event.getExistingFileHelper())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
private static void LootTableDataGenerate(@NotNull GatherDataEvent event) {
|
private static void LootTableDataGenerate(@NotNull GatherDataEvent event) {
|
||||||
event.getGenerator().addProvider(
|
event.getGenerator().addProvider(
|
||||||
event.includeServer(),
|
true,
|
||||||
(DataProvider.Factory<SimpleLootTableProvider>) pOutput -> {
|
(DataProvider.Factory<SimpleLootTableProvider>) pOutput -> {
|
||||||
try {
|
try {
|
||||||
return new SimpleLootTableProvider(pOutput, new SubProvidersWrapper().addBlockEntry(new Lib39BlockLootTable(event.getLookupProvider())), event.getLookupProvider());
|
return new SimpleLootTableProvider(pOutput, new SubProvidersWrapper().addBlockEntry(new Lib39BlockLootTable(event.getLookupProvider())), event.getLookupProvider());
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package top.r3944realms.lib39.base.datagen.provider;
|
package top.r3944realms.lib39.base.datagen.provider;
|
||||||
|
|
||||||
import net.minecraft.data.PackOutput;
|
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.client.model.generators.BlockModelProvider;
|
||||||
import net.neoforged.neoforge.common.data.ExistingFileHelper;
|
import net.neoforged.neoforge.common.data.ExistingFileHelper;
|
||||||
import top.r3944realms.lib39.Lib39;
|
import top.r3944realms.lib39.Lib39;
|
||||||
|
|
@ -35,7 +35,7 @@ public class Lib39BlockModelProvider extends BlockModelProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void createPlantsModel(PlantHelper.Plant plant) {
|
private void createPlantsModel(PlantHelper.Plant plant) {
|
||||||
ResourceLocation rl = PlantHelper.getTextureRL(plant);
|
Identifier rl = PlantHelper.getTextureRL(plant);
|
||||||
getBuilder("block/doll_item/" + plant)
|
getBuilder("block/doll_item/" + plant)
|
||||||
.parent(getExistingFile(Lib39.rl("block/base_doll_item")))
|
.parent(getExistingFile(Lib39.rl("block/base_doll_item")))
|
||||||
.texture("item", rl)
|
.texture("item", rl)
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,8 @@ package top.r3944realms.lib39.base.datagen.provider;
|
||||||
|
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.data.PackOutput;
|
import net.minecraft.data.PackOutput;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.world.item.Item;
|
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.Lib39;
|
||||||
import top.r3944realms.lib39.base.datagen.value.Lib39LangKey;
|
import top.r3944realms.lib39.base.datagen.value.Lib39LangKey;
|
||||||
import top.r3944realms.lib39.datagen.value.LangKeyValue;
|
import top.r3944realms.lib39.datagen.value.LangKeyValue;
|
||||||
|
|
@ -80,7 +78,7 @@ public class Lib39ItemModelProvider extends ItemModelProvider {
|
||||||
* @param item the item
|
* @param item the item
|
||||||
* @param location the location
|
* @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);
|
withExistingParent(itemName(item), GENERATED).texture("layer0", location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,7 +88,7 @@ public class Lib39ItemModelProvider extends ItemModelProvider {
|
||||||
* @param item the item
|
* @param item the item
|
||||||
* @param location the location
|
* @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);
|
withExistingParent(itemName(item), HANDHELD).texture("layer0", location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,7 +116,7 @@ public class Lib39ItemModelProvider extends ItemModelProvider {
|
||||||
* @param path the path
|
* @param path the path
|
||||||
* @return the resource location
|
* @return the resource location
|
||||||
*/
|
*/
|
||||||
public ResourceLocation resourceItem(String path){
|
public Identifier resourceItem(String path){
|
||||||
return modLoc("item/" + path);
|
return modLoc("item/" + path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.core.compat;
|
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.api.distmarker.Dist;
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.fml.common.EventBusSubscriber;
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
|
|
@ -30,7 +30,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
||||||
/**
|
/**
|
||||||
* The Compats.
|
* The Compats.
|
||||||
*/
|
*/
|
||||||
protected final Map<ResourceLocation, INeoForgeCompat> compats = new HashMap<>();
|
protected final Map<Identifier, INeoForgeCompat> compats = new HashMap<>();
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 存储事件监听器配置
|
* 存储事件监听器配置
|
||||||
|
|
@ -40,7 +40,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
||||||
protected final List<ListenerConfig> listenerConfigs = new ArrayList<>();
|
protected final List<ListenerConfig> listenerConfigs = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<ResourceLocation, INeoForgeCompat> getCompatMap() {
|
public Map<Identifier, INeoForgeCompat> getCompatMap() {
|
||||||
return compats;
|
return compats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,14 +51,14 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
||||||
* @param modEventBus the mod event bus
|
* @param modEventBus the mod event bus
|
||||||
* @param gameEventBus the game event bus
|
* @param gameEventBus the game event bus
|
||||||
*/
|
*/
|
||||||
public NeoForgeCompatManager(ResourceLocation id, IEventBus modEventBus, IEventBus gameEventBus) {
|
public NeoForgeCompatManager(Identifier id, IEventBus modEventBus, IEventBus gameEventBus) {
|
||||||
super(id);
|
super(id);
|
||||||
this.modEventBus = modEventBus;
|
this.modEventBus = modEventBus;
|
||||||
this.gameEventBus = gameEventBus;
|
this.gameEventBus = gameEventBus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doRegisterCompat(ResourceLocation id, INeoForgeCompat compat) {
|
protected void doRegisterCompat(Identifier id, INeoForgeCompat compat) {
|
||||||
super.doRegisterCompat(id, compat);
|
super.doRegisterCompat(id, compat);
|
||||||
addListenerForCompat(id);
|
addListenerForCompat(id);
|
||||||
}
|
}
|
||||||
|
|
@ -80,7 +80,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
||||||
* @param dists the dists
|
* @param dists the dists
|
||||||
* @param bus the bus
|
* @param bus the bus
|
||||||
*/
|
*/
|
||||||
public void addListenerForCompat(ResourceLocation compatId, @Nullable Dist dists, EventBusSubscriber.Bus bus) {
|
public void addListenerForCompat(Identifier compatId, @Nullable Dist dists, EventBusSubscriber.Bus bus) {
|
||||||
listenerConfigs.add(new ListenerConfig(compatId, dists, bus));
|
listenerConfigs.add(new ListenerConfig(compatId, dists, bus));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +89,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
||||||
*
|
*
|
||||||
* @param compatId the compat id
|
* @param compatId the compat id
|
||||||
*/
|
*/
|
||||||
public void addListenerForCompat(ResourceLocation compatId) {
|
public void addListenerForCompat(Identifier compatId) {
|
||||||
addListenerForCompat(compatId, null, EventBusSubscriber.Bus.GAME);
|
addListenerForCompat(compatId, null, EventBusSubscriber.Bus.GAME);
|
||||||
addListenerForCompat(compatId, null, EventBusSubscriber.Bus.MOD);
|
addListenerForCompat(compatId, null, EventBusSubscriber.Bus.MOD);
|
||||||
|
|
||||||
|
|
@ -129,7 +129,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
||||||
pendingTasks.clear();
|
pendingTasks.clear();
|
||||||
|
|
||||||
// 初始化所有兼容模块
|
// 初始化所有兼容模块
|
||||||
for (Map.Entry<ResourceLocation, INeoForgeCompat> entry : compats.entrySet()) {
|
for (Map.Entry<Identifier, INeoForgeCompat> entry : compats.entrySet()) {
|
||||||
if (!entry.getValue().isInitialized() && entry.getValue().isModLoaded()) {
|
if (!entry.getValue().isInitialized() && entry.getValue().isModLoaded()) {
|
||||||
try {
|
try {
|
||||||
entry.getValue().initialize();
|
entry.getValue().initialize();
|
||||||
|
|
@ -178,7 +178,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
||||||
/**
|
/**
|
||||||
* 将监听器应用到特定兼容模块
|
* 将监听器应用到特定兼容模块
|
||||||
*/
|
*/
|
||||||
private void applyListenerToCompat(ResourceLocation compatId, ListenerConfig config) {
|
private void applyListenerToCompat(Identifier compatId, ListenerConfig config) {
|
||||||
INeoForgeCompat compat = compats.get(compatId);
|
INeoForgeCompat compat = compats.get(compatId);
|
||||||
if (compat != null && config.shouldApply(compat)) {
|
if (compat != null && config.shouldApply(compat)) {
|
||||||
applyListenerToCompat(compat, config);
|
applyListenerToCompat(compat, config);
|
||||||
|
|
@ -257,7 +257,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
||||||
* @param compatId the compat id
|
* @param compatId the compat id
|
||||||
* @param bus the bus
|
* @param bus the bus
|
||||||
*/
|
*/
|
||||||
public void addListenerForCompat(ResourceLocation compatId, EventBusSubscriber.Bus bus) {
|
public void addListenerForCompat(Identifier compatId, EventBusSubscriber.Bus bus) {
|
||||||
addListenerForCompat(compatId, null, bus);
|
addListenerForCompat(compatId, null, bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -268,7 +268,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
||||||
/**
|
/**
|
||||||
* The Compat id.
|
* The Compat id.
|
||||||
*/
|
*/
|
||||||
final ResourceLocation compatId;
|
final Identifier compatId;
|
||||||
/**
|
/**
|
||||||
* The Dists.
|
* The Dists.
|
||||||
*/
|
*/
|
||||||
|
|
@ -285,7 +285,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
||||||
* @param dists the dists
|
* @param dists the dists
|
||||||
* @param bus the bus
|
* @param bus the bus
|
||||||
*/
|
*/
|
||||||
ListenerConfig(ResourceLocation compatId, Dist dists, EventBusSubscriber.Bus bus) {
|
ListenerConfig(Identifier compatId, Dist dists, EventBusSubscriber.Bus bus) {
|
||||||
this.compatId = compatId;
|
this.compatId = compatId;
|
||||||
this.dists = dists;
|
this.dists = dists;
|
||||||
this.bus = bus;
|
this.bus = bus;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
import net.minecraft.core.component.DataComponents;
|
import net.minecraft.core.component.DataComponents;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.item.CreativeModeTab;
|
import net.minecraft.world.item.CreativeModeTab;
|
||||||
|
|
@ -143,8 +143,8 @@ public class CommonEventHandler {
|
||||||
public static void onServerTick(ServerTickEvent.Post event) {
|
public static void onServerTick(ServerTickEvent.Post event) {
|
||||||
if (syncData2Manager == null) return;
|
if (syncData2Manager == null) return;
|
||||||
if (event.getServer().getTickCount() % 10 == 0)
|
if (event.getServer().getTickCount() % 10 == 0)
|
||||||
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
|
syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
|
||||||
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
|
syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -206,7 +206,7 @@ public class CommonEventHandler {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
if (entity.level().isClientSide) return;
|
if (entity.level().isClientSide) return;
|
||||||
|
|
||||||
for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
|
for (Identifier id : syncData2Manager.getRegisteredKeys()) {
|
||||||
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
|
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
|
||||||
syncData2Manager.trackEntityForManager(entity, id);
|
syncData2Manager.trackEntityForManager(entity, id);
|
||||||
}
|
}
|
||||||
|
|
@ -223,7 +223,7 @@ public class CommonEventHandler {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
if (entity.level().isClientSide) return;
|
if (entity.level().isClientSide) return;
|
||||||
|
|
||||||
for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
|
for (Identifier id : syncData2Manager.getRegisteredKeys()) {
|
||||||
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
|
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
|
||||||
syncData2Manager.untrackEntityForManager(entity, id);
|
syncData2Manager.untrackEntityForManager(entity, id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
import net.minecraft.network.codec.StreamCodec;
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
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.entity.Entity;
|
||||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
|
|
@ -25,11 +25,11 @@ import java.util.function.Supplier;
|
||||||
* The type Sync nbt data s 2 c payload.
|
* The type Sync nbt data s 2 c payload.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@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.
|
* 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");
|
Lib39.rl("sync_nbt_cap_data_entity");
|
||||||
/**
|
/**
|
||||||
* The constant TYPE.
|
* The constant TYPE.
|
||||||
|
|
@ -60,7 +60,7 @@ public record SyncNBTCapDataEntityS2CPayload(int entityId, ResourceLocation id,
|
||||||
*/
|
*/
|
||||||
public static void encode(@NotNull SyncNBTCapDataEntityS2CPayload msg, @NotNull FriendlyByteBuf buffer) {
|
public static void encode(@NotNull SyncNBTCapDataEntityS2CPayload msg, @NotNull FriendlyByteBuf buffer) {
|
||||||
buffer.writeInt(msg.entityId);
|
buffer.writeInt(msg.entityId);
|
||||||
buffer.writeResourceLocation(msg.id);
|
buffer.writeIdentifier(msg.id);
|
||||||
buffer.writeNbt(msg.data);
|
buffer.writeNbt(msg.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,7 +72,7 @@ public record SyncNBTCapDataEntityS2CPayload(int entityId, ResourceLocation id,
|
||||||
*/
|
*/
|
||||||
@Contract("_ -> new")
|
@Contract("_ -> new")
|
||||||
public static @NotNull SyncNBTCapDataEntityS2CPayload decode(@NotNull FriendlyByteBuf buffer) {
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.core.sync;
|
package top.r3944realms.lib39.core.sync;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.neoforged.neoforge.capabilities.ICapabilityProvider;
|
import net.neoforged.neoforge.capabilities.ICapabilityProvider;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
@ -26,7 +26,7 @@ public abstract class SyncCapProvider<T extends NBTEntitySyncData> implements IC
|
||||||
*
|
*
|
||||||
* @return 能力 ID
|
* @return 能力 ID
|
||||||
*/
|
*/
|
||||||
protected abstract ResourceLocation getId();
|
protected abstract Identifier getId();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package top.r3944realms.lib39.core.sync;
|
package top.r3944realms.lib39.core.sync;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.neoforged.neoforge.capabilities.EntityCapability;
|
import net.neoforged.neoforge.capabilities.EntityCapability;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
|
@ -17,10 +17,10 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
|
||||||
/**
|
/**
|
||||||
* The Typed entries.
|
* The Typed entries.
|
||||||
*/
|
*/
|
||||||
protected final Map<ResourceLocation, TypedSyncEntry<?>> typedEntries = Maps.newConcurrentMap();
|
protected final Map<Identifier, TypedSyncEntry<?>> typedEntries = Maps.newConcurrentMap();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<ResourceLocation, TypedSyncEntry<?>> getTypedEntries() {
|
protected Map<Identifier, TypedSyncEntry<?>> getTypedEntries() {
|
||||||
return typedEntries;
|
return typedEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,11 +50,11 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
|
||||||
* @param capability the capability
|
* @param capability the capability
|
||||||
*/
|
*/
|
||||||
public <T extends ISyncData<?>> void registerManager(
|
public <T extends ISyncData<?>> void registerManager(
|
||||||
ResourceLocation key,
|
Identifier key,
|
||||||
ISyncManager<EntityCapability<T, Void>, T> manager,
|
ISyncManager<EntityCapability<T, Void>, T> manager,
|
||||||
EntityCapability<T, Void> capability
|
EntityCapability<T, Void> 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(manager, "Sync manager cannot be null");
|
||||||
Objects.requireNonNull(capability, "Capability cannot be null");
|
Objects.requireNonNull(capability, "Capability cannot be null");
|
||||||
|
|
||||||
|
|
@ -69,8 +69,8 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
|
||||||
* @param key the key
|
* @param key the key
|
||||||
* @param capability the capability
|
* @param capability the capability
|
||||||
*/
|
*/
|
||||||
public <T extends ISyncData<?>> void bindCapability(ResourceLocation key, EntityCapability<T, Void> capability) {
|
public <T extends ISyncData<?>> void bindCapability(Identifier key, EntityCapability<T, Void> capability) {
|
||||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||||
Objects.requireNonNull(capability, "Capability cannot be null");
|
Objects.requireNonNull(capability, "Capability cannot be null");
|
||||||
|
|
||||||
TypedSyncEntry<?> entry = typedEntries.get(key);
|
TypedSyncEntry<?> entry = typedEntries.get(key);
|
||||||
|
|
@ -85,8 +85,8 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
|
||||||
*
|
*
|
||||||
* @param key the key
|
* @param key the key
|
||||||
*/
|
*/
|
||||||
public void unbindCapability(ResourceLocation key) {
|
public void unbindCapability(Identifier key) {
|
||||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||||
|
|
||||||
TypedSyncEntry<?> entry = typedEntries.get(key);
|
TypedSyncEntry<?> entry = typedEntries.get(key);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
|
|
@ -103,7 +103,7 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
|
||||||
* @param entry the entry
|
* @param entry the entry
|
||||||
* @param newCapability the new capability
|
* @param newCapability the new capability
|
||||||
*/
|
*/
|
||||||
protected <T extends ISyncData<?>> void updateCapabilityInEntry(ResourceLocation id, TypedSyncEntry<?> entry, EntityCapability<T, Void> newCapability) {
|
protected <T extends ISyncData<?>> void updateCapabilityInEntry(Identifier id, TypedSyncEntry<?> entry, EntityCapability<T, Void> newCapability) {
|
||||||
updateDataProviderInEntry(id, entry, key -> newCapability != null ? Optional.ofNullable(key.getCapability(newCapability)) : Optional.empty());
|
updateDataProviderInEntry(id, entry, key -> newCapability != null ? Optional.ofNullable(key.getCapability(newCapability)) : Optional.empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ import net.minecraft.core.WritableRegistry;
|
||||||
import net.minecraft.data.PackOutput;
|
import net.minecraft.data.PackOutput;
|
||||||
import net.minecraft.data.loot.LootTableProvider;
|
import net.minecraft.data.loot.LootTableProvider;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.util.ProblemReporter;
|
import net.minecraft.util.ProblemReporter;
|
||||||
import net.minecraft.world.level.storage.loot.LootTable;
|
import net.minecraft.world.level.storage.loot.LootTable;
|
||||||
import net.minecraft.world.level.storage.loot.ValidationContext;
|
import net.minecraft.world.level.storage.loot.ValidationContext;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.example.compat;
|
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.bus.api.IEventBus;
|
||||||
import net.neoforged.fml.ModList;
|
import net.neoforged.fml.ModList;
|
||||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||||
|
|
@ -23,7 +23,7 @@ public class Lib39Compat implements INeoForgeCompat {
|
||||||
/**
|
/**
|
||||||
* The constant ID.
|
* The constant ID.
|
||||||
*/
|
*/
|
||||||
public static ResourceLocation ID = Lib39.rl("lib39");
|
public static Identifier ID = Lib39.rl("lib39");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInitialize(boolean initialize) {
|
public void setInitialize(boolean initialize) {
|
||||||
|
|
@ -36,7 +36,7 @@ public class Lib39Compat implements INeoForgeCompat {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation id() {
|
public Identifier id() {
|
||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package top.r3944realms.lib39.example.content.data;
|
package top.r3944realms.lib39.example.content.data;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import top.r3944realms.lib39.Lib39;
|
import top.r3944realms.lib39.Lib39;
|
||||||
import top.r3944realms.lib39.core.sync.SyncCapProvider;
|
import top.r3944realms.lib39.core.sync.SyncCapProvider;
|
||||||
|
|
@ -13,7 +13,7 @@ public class TestSyncCapProvider extends SyncCapProvider<AbstractedTestSyncData>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResourceLocation getId() {
|
protected Identifier getId() {
|
||||||
return Lib39.rl("test_data");
|
return Lib39.rl("test_data");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ package top.r3944realms.lib39.example.content.data;
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import top.r3944realms.lib39.Lib39;
|
import top.r3944realms.lib39.Lib39;
|
||||||
import top.r3944realms.lib39.core.sync.INeoForgeUpdate;
|
import top.r3944realms.lib39.core.sync.INeoForgeUpdate;
|
||||||
import top.r3944realms.lib39.util.nbt.NBTReader;
|
import top.r3944realms.lib39.util.storage.nbt.NBTReader;
|
||||||
import top.r3944realms.lib39.util.nbt.NBTWriter;
|
import top.r3944realms.lib39.util.storage.nbt.NBTWriter;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
@ -22,7 +22,7 @@ public class TestSyncData extends AbstractedTestSyncData implements INeoForgeUpd
|
||||||
/**
|
/**
|
||||||
* The constant ID.
|
* 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 键常量
|
// NBT 键常量
|
||||||
private static final String NBT_KEY_STRING = "test_string";
|
private static final String NBT_KEY_STRING = "test_string";
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
import net.minecraft.network.codec.StreamCodec;
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
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.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||||
|
|
@ -21,7 +21,7 @@ public record ClientDataPayload(AbstractedTestSyncData clientData, int targetEnt
|
||||||
/**
|
/**
|
||||||
* The constant CLIENT_DATA_PACKET_ID.
|
* 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");
|
Lib39.rl("client_data");
|
||||||
/**
|
/**
|
||||||
* The constant TYPE.
|
* The constant TYPE.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package top.r3944realms.lib39.util;
|
package top.r3944realms.lib39.util;
|
||||||
|
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
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.*;
|
||||||
import net.minecraft.world.entity.animal.Animal;
|
import net.minecraft.world.entity.animal.Animal;
|
||||||
import net.minecraft.world.entity.monster.Monster;
|
import net.minecraft.world.entity.monster.Monster;
|
||||||
|
|
@ -85,7 +85,7 @@ public class EntityCapabilityHelper {
|
||||||
|
|
||||||
BuiltInRegistries.ENTITY_TYPE.stream()
|
BuiltInRegistries.ENTITY_TYPE.stream()
|
||||||
.filter(entityType -> {
|
.filter(entityType -> {
|
||||||
ResourceLocation key = BuiltInRegistries.ENTITY_TYPE.getKey(entityType);
|
Identifier key = BuiltInRegistries.ENTITY_TYPE.getKey(entityType);
|
||||||
return namespace.equals(key.getNamespace());
|
return namespace.equals(key.getNamespace());
|
||||||
})
|
})
|
||||||
.forEach(entityType -> event.registerEntity(capability, entityType, provider));
|
.forEach(entityType -> event.registerEntity(capability, entityType, provider));
|
||||||
|
|
|
||||||
27
primers-doc/1.21.10-from-1.21.9.md
Normal file
27
primers-doc/1.21.10-from-1.21.9.md
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
# Minecraft 1.21.9 -> 1.21.10 模组迁移入门文档
|
||||||
|
|
||||||
|
本文档是一个高层次、非详尽的概述,介绍如何将您的模组从 1.21.9 迁移到 1.21.10。本文不涉及任何特定的模组加载器,只关注原版类的变更。所有提供的名称均使用官方的 Mojang 映射。
|
||||||
|
|
||||||
|
本入门文档采用 [知识共享署名 4.0 国际许可协议](http://creativecommons.org/licenses/by/4.0/) 授权,因此您可以自由地将其用作参考,并请留下链接以便其他读者查阅。
|
||||||
|
|
||||||
|
如果存在任何不正确或缺失的信息,请在本仓库提交 issue,或在 Neoforged Discord 服务器中 @ChampionAsh5357。
|
||||||
|
|
||||||
|
感谢:
|
||||||
|
|
||||||
|
- @melanx 指出了一个拼写错误
|
||||||
|
|
||||||
|
## 资源包变更
|
||||||
|
|
||||||
|
原版中有许多面向用户的变更为未在下面讨论,但这些变更可能与模组制作者相关。您可以在 [Misode 的版本更新日志](https://misode.github.io/versions/?id=1.21.10&tab=changelog) 中找到它们的列表。
|
||||||
|
|
||||||
|
## 小幅迁移
|
||||||
|
|
||||||
|
以下是有用或有趣的增加、变更和移除的列表,它们不值得在入门文档中拥有自己的章节。
|
||||||
|
|
||||||
|
### 新增列表
|
||||||
|
|
||||||
|
- `net.minecraft.world.entity.decoration.HangingEntity#getPopBox` - 返回一个边界框,指示如果发生碰撞,实体将从何处弹出。
|
||||||
|
|
||||||
|
### 变更列表
|
||||||
|
|
||||||
|
- `net.minecraft.world.level.block.state.BlockBehaviour#entityInside` 现在接受一个 `boolean` 参数,指示实体是与方块相交还是在方块内部。
|
||||||
3146
primers-doc/1.21.11-from-1.21.10.md
Normal file
3146
primers-doc/1.21.11-from-1.21.10.md
Normal file
File diff suppressed because it is too large
Load Diff
3195
primers-doc/1.21.2-from-1.21.1.md
Normal file
3195
primers-doc/1.21.2-from-1.21.1.md
Normal file
File diff suppressed because it is too large
Load Diff
1448
primers-doc/1.21.4-from-1.21.2-3.md
Normal file
1448
primers-doc/1.21.4-from-1.21.2-3.md
Normal file
File diff suppressed because it is too large
Load Diff
3058
primers-doc/1.21.5-from-1.21.4.md
Normal file
3058
primers-doc/1.21.5-from-1.21.4.md
Normal file
File diff suppressed because it is too large
Load Diff
2203
primers-doc/1.21.6-from-1.21.5.md
Normal file
2203
primers-doc/1.21.6-from-1.21.5.md
Normal file
File diff suppressed because it is too large
Load Diff
38
primers-doc/1.21.7-from-1.21.6.md
Normal file
38
primers-doc/1.21.7-from-1.21.6.md
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
# Minecraft 1.21.6 -> 1.21.7 模组迁移入门文档
|
||||||
|
|
||||||
|
本文档是一个高层次、非详尽的概述,介绍如何将您的模组从 1.21.6 迁移到 1.21.7。本文不涉及任何特定的模组加载器,只关注原版类的变更。所有提供的名称均使用官方的 Mojang 映射。
|
||||||
|
|
||||||
|
本入门文档采用 [知识共享署名 4.0 国际许可协议](http://creativecommons.org/licenses/by/4.0/) 授权,因此您可以自由地将其用作参考,并请留下链接以便其他读者查阅。
|
||||||
|
|
||||||
|
如果存在任何不正确或缺失的信息,请在本仓库提交 issue,或在 Neoforged Discord 服务器中 @ChampionAsh5357。
|
||||||
|
|
||||||
|
## 资源包变更
|
||||||
|
|
||||||
|
原版中有许多面向用户的变更为未在下面讨论,但这些变更可能与模组制作者相关。您可以在 [Misode 的版本更新日志](https://misode.github.io/versions/?id=1.21.7&tab=changelog) 中找到它们的列表。
|
||||||
|
|
||||||
|
## 小幅迁移
|
||||||
|
|
||||||
|
以下是有用或有趣的增加、变更和移除的列表,它们不值得在入门文档中拥有自己的章节。
|
||||||
|
|
||||||
|
### 新增列表
|
||||||
|
|
||||||
|
- `com.mojang.blaze3d.opengl.DirectStateAccess#copyBufferSubData` - 将一个缓冲区对象的数据存储的全部或部分复制到另一个缓冲区对象的数据存储。
|
||||||
|
- `com.mojang.blaze3d.pipeline.BlendFunction#INVERT` - 反转 RGB 源和目标的混合因子。Alpha 使用源的默认因子,目标使用零。
|
||||||
|
- `com.mojang.blaze3d.systems.CommandEncoder#copyToBuffer` - 将一个缓冲区切片的数据存储复制到另一个缓冲区切片。
|
||||||
|
- `net.minecraft.Util#isAarch64` - 返回操作系统架构是否使用 aarch64。
|
||||||
|
- `net.minecraft.client.gui.GuiGraphics#textHighlight` - 在提供的边界周围添加一个高亮框。
|
||||||
|
- `net.minecraft.client.renderer.RenderPipelines#GUI_INVERT` - 用于绘制具有反色效果的 GUI 元素的渲染管线。
|
||||||
|
- `net.minecraft.client.renderer.item.TrackingItemRenderState` - 一个跟踪用于渲染物品堆栈的模型源的渲染状态。
|
||||||
|
|
||||||
|
### 变更列表
|
||||||
|
|
||||||
|
- `com.mojang.blaze3d.pipeline.RenderPipeline$Builder#withColorLogic` 现已弃用
|
||||||
|
- `net.minecraft.client.gui.renderer.GuiRenderer#MIN_GUI_Z` 现在是私有的
|
||||||
|
- `net.minecraft.client.gui.render.state.GuiItemRenderState` 现在接受 `TrackingItemRenderState` 而不是 `ItemStackRenderState`
|
||||||
|
- `itemStackRenderState` 现在返回 `TrackingItemRenderState`
|
||||||
|
- `net.minecraft.client.renderer.RenderPipelines#GUI_TEXT_HIGHLIGHT` 现在使用 `ADDITIVE` 混合函数而不是 `OR_REVERSE` 颜色逻辑
|
||||||
|
- `net.minecraft.client.renderer.item.ItemStackRenderState#getModelIdentity` -> `TrackingItemRenderState#getModelIdentity`
|
||||||
|
|
||||||
|
### 移除列表
|
||||||
|
|
||||||
|
- `net.minecraft.client.renderer.item.ItemStackRenderState#clearModelIdentity`
|
||||||
19
primers-doc/1.21.8-from-1.21.7.md
Normal file
19
primers-doc/1.21.8-from-1.21.7.md
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Minecraft 1.21.7 -> 1.21.8 模组迁移入门文档
|
||||||
|
|
||||||
|
本文档是一个高层次、非详尽的概述,介绍如何将您的模组从 1.21.7 迁移到 1.21.8。本文不涉及任何特定的模组加载器,只关注原版类的变更。所有提供的名称均使用官方的 Mojang 映射。
|
||||||
|
|
||||||
|
本入门文档采用 [知识共享署名 4.0 国际许可协议](http://creativecommons.org/licenses/by/4.0/) 授权,因此您可以自由地将其用作参考,并请留下链接以便其他读者查阅。
|
||||||
|
|
||||||
|
如果存在任何不正确或缺失的信息,请在本仓库提交 issue,或在 Neoforged Discord 服务器中 @ChampionAsh5357。
|
||||||
|
|
||||||
|
## 资源包变更
|
||||||
|
|
||||||
|
原版中有许多面向用户的变更为未在下面讨论,但这些变更可能与模组制作者相关。您可以在 [Misode 的版本更新日志](https://misode.github.io/versions/?id=1.21.8&tab=changelog) 中找到它们的列表。
|
||||||
|
|
||||||
|
## 小幅迁移
|
||||||
|
|
||||||
|
以下是有用或有趣的增加、变更和移除的列表,它们不值得在入门文档中拥有自己的章节。
|
||||||
|
|
||||||
|
### 新增列表
|
||||||
|
|
||||||
|
- `com.mojang.blaze3d.GraphicsWorkarounds` - 一个用于解决特定图形硬件问题的辅助工具。
|
||||||
2532
primers-doc/1.21.9-from-1.21.8.md
Normal file
2532
primers-doc/1.21.9-from-1.21.8.md
Normal file
File diff suppressed because it is too large
Load Diff
4957
primers-doc/26.1-from-1.21.11.md
Normal file
4957
primers-doc/26.1-from-1.21.11.md
Normal file
File diff suppressed because it is too large
Load Diff
135
primers-doc/README.md
Normal file
135
primers-doc/README.md
Normal file
|
|
@ -0,0 +1,135 @@
|
||||||
|
# 详细入门文档
|
||||||
|
|
||||||
|
这些章节按步骤保留了上游入门文档的内容。每个章节标题都直接链接到入门文档页面内的相应章节。
|
||||||
|
|
||||||
|
## 1.21.1 -> 1.21.2/3
|
||||||
|
|
||||||
|
[完整入门文档](1.21.2-from-1.21.1.md)
|
||||||
|
|
||||||
|
- [资源包变更](1.21.2-from-1.21.1.md#资源包变更)
|
||||||
|
- [持有者集过渡](1.21.2-from-1.21.1.md#持有者集-过渡)
|
||||||
|
- [GUI 渲染类型](1.21.2-from-1.21.1.md#gui-渲染类型)
|
||||||
|
- [着色器重写](1.21.2-from-1.21.1.md#着色器重写)
|
||||||
|
- [实体渲染状态](1.21.2-from-1.21.1.md#实体渲染状态)
|
||||||
|
- [装备与物品、模型等等](1.21.2-from-1.21.1.md#装备与物品-模型等等)
|
||||||
|
- [盔甲材料、装备和模型(纹理)](1.21.2-from-1.21.1.md#盔甲材料-装备和模型纹理)
|
||||||
|
- [交互结果](1.21.2-from-1.21.1.md#交互结果)
|
||||||
|
- [乐器,数据包版](1.21.2-from-1.21.1.md#乐器-数据包版)
|
||||||
|
- [试炼刷怪笼配置,现在采用数据包形式](1.21.2-from-1.21.1.md#试炼刷怪笼配置-现在采用数据包形式)
|
||||||
|
- [配方提供者,数据提供者的“并非真正”](1.21.2-from-1.21.1.md#配方提供者-数据提供者的并非真正)
|
||||||
|
- [原料的转变](1.21.2-from-1.21.1.md#原料的转变)
|
||||||
|
- [BlockEntityTypes 私有化了!](1.21.2-from-1.21.1.md#blockentitytypes-私有化)
|
||||||
|
- [消耗品](1.21.2-from-1.21.1.md#消耗品)
|
||||||
|
- [注册表对象 ID,在属性里?](1.21.2-from-1.21.1.md#注册表对象-id-在属性里)
|
||||||
|
- [属性变更](1.21.2-from-1.21.1.md#属性变更)
|
||||||
|
- [配方,现在采用注册表格式](1.21.2-from-1.21.1.md#配方-现在采用注册表格式)
|
||||||
|
- [小幅迁移](1.21.2-from-1.21.1.md#小幅-迁移)
|
||||||
|
|
||||||
|
## 1.21.2/3 -> 1.21.4
|
||||||
|
|
||||||
|
[完整入门文档](1.21.4-from-1.21.2-3.md)
|
||||||
|
|
||||||
|
- [资源包变更](1.21.4-from-1.21.2-3.md#资源包变更)
|
||||||
|
- [客户端物品](1.21.4-from-1.21.2-3.md#客户端-物品)
|
||||||
|
- [生物替换当前物品](1.21.4-from-1.21.2-3.md#生物-替换当前物品)
|
||||||
|
- [粒子,通过渲染类型渲染](1.21.4-from-1.21.2-3.md#粒子-通过渲染类型渲染)
|
||||||
|
- [小幅迁移](1.21.4-from-1.21.2-3.md#小幅-迁移)
|
||||||
|
|
||||||
|
## 1.21.4 -> 1.21.5
|
||||||
|
|
||||||
|
[完整入门文档](1.21.5-from-1.21.4.md)
|
||||||
|
|
||||||
|
- [资源包变更](1.21.5-from-1.21.4.md#资源包变更)
|
||||||
|
- [正确处理方块实体的移除](1.21.5-from-1.21.4.md#正确处理方块实体的移除)
|
||||||
|
- [体素形状辅助类](1.21.5-from-1.21.4.md#体素形状辅助类)
|
||||||
|
- [武器、工具和盔甲:去除冗余](1.21.5-from-1.21.4.md#武器工具和盔甲-去除冗余)
|
||||||
|
- [加权列表重做](1.21.5-from-1.21.4.md#加权列表重做)
|
||||||
|
- [加载票](1.21.5-from-1.21.4.md#加载票)
|
||||||
|
- [游戏测试大修](1.21.5-from-1.21.4.md#游戏测试-大修)
|
||||||
|
- [数据组件获取器](1.21.5-from-1.21.4.md#数据组件-获取器)
|
||||||
|
- [标签与解析](1.21.5-from-1.21.4.md#标签与解析)
|
||||||
|
- [保存数据,现在带有类型](1.21.5-from-1.21.4.md#保存数据-现在带有类型)
|
||||||
|
- [渲染管线重做](1.21.5-from-1.21.4.md#渲染管线重做)
|
||||||
|
- [模型重做](1.21.5-from-1.21.4.md#模型-重做)
|
||||||
|
- [小幅迁移](1.21.5-from-1.21.4.md#小幅-迁移)
|
||||||
|
|
||||||
|
## 1.21.5 -> 1.21.6
|
||||||
|
|
||||||
|
[完整入门文档](1.21.6-from-1.21.5.md)
|
||||||
|
|
||||||
|
- [资源包变更](1.21.6-from-1.21.5.md#资源包变更)
|
||||||
|
- [GUI 变更](1.21.6-from-1.21.5.md#gui-变更)
|
||||||
|
- [路径点](1.21.6-from-1.21.5.md#路径点)
|
||||||
|
- [Blaze3d 变更](1.21.6-from-1.21.5.md#blaze3d-变更)
|
||||||
|
- [标签提供者:追加器重写](1.21.6-from-1.21.5.md#标签提供者-追加器重写)
|
||||||
|
- [通用编码与解码:替换直接 NBT 访问](1.21.6-from-1.21.5.md#通用编码与解码-替换直接-nbt-访问)
|
||||||
|
- [服务端玩家变更](1.21.6-from-1.21.5.md#服务端玩家变更)
|
||||||
|
- [小幅迁移](1.21.6-from-1.21.5.md#小幅-迁移)
|
||||||
|
|
||||||
|
## 1.21.6 -> 1.21.7
|
||||||
|
|
||||||
|
[完整入门文档](1.21.7-from-1.21.6.md)
|
||||||
|
|
||||||
|
- [资源包变更](1.21.7-from-1.21.6.md#资源包变更)
|
||||||
|
- [小幅迁移](1.21.7-from-1.21.6.md#小幅-迁移)
|
||||||
|
|
||||||
|
## 1.21.7 -> 1.21.8
|
||||||
|
|
||||||
|
[完整入门文档](1.21.8-from-1.21.7.md)
|
||||||
|
|
||||||
|
- [资源包变更](1.21.8-from-1.21.7.md#资源包变更)
|
||||||
|
- [小幅迁移](1.21.8-from-1.21.7.md#小幅-迁移)
|
||||||
|
|
||||||
|
## 1.21.8 -> 1.21.9
|
||||||
|
|
||||||
|
[完整入门文档](1.21.9-from-1.21.8.md)
|
||||||
|
|
||||||
|
- [资源包变更](1.21.9-from-1.21.8.md#资源包变更)
|
||||||
|
- [调试大修](1.21.9-from-1.21.8.md#调试-大修)
|
||||||
|
- [调试屏幕](1.21.9-from-1.21.8.md#调试-屏幕)
|
||||||
|
- [功能提交:电影版](1.21.9-from-1.21.8.md#功能提交-电影版)
|
||||||
|
- [字体字形管线](1.21.9-from-1.21.8.md#字体-字形-管线)
|
||||||
|
- [JSON-RPC 管理服务器](1.21.9-from-1.21.8.md#json-rpc-管理服务器)
|
||||||
|
- [输入处理整合](1.21.9-from-1.21.8.md#输入处理整合)
|
||||||
|
- [`Level#isClientSide` 现在为 private](1.21.9-from-1.21.8.md#levelisclientside-现在为-private)
|
||||||
|
- [小幅迁移](1.21.9-from-1.21.8.md#小幅-迁移)
|
||||||
|
|
||||||
|
## 1.21.9 -> 1.21.10
|
||||||
|
|
||||||
|
[完整入门文档](1.21.10-from-1.21.9.md)
|
||||||
|
|
||||||
|
- [资源包变更](1.21.10-from-1.21.9.md#资源包变更)
|
||||||
|
- [小幅迁移](1.21.10-from-1.21.9.md#小幅-迁移)
|
||||||
|
|
||||||
|
## 1.21.10 -> 1.21.11
|
||||||
|
|
||||||
|
[完整入门文档](1.21.11-from-1.21.10.md)
|
||||||
|
|
||||||
|
- [资源包变更](1.21.11-from-1.21.10.md#资源包变更)
|
||||||
|
- [重命名混乱](1.21.11-from-1.21.10.md#重命名混乱)
|
||||||
|
- [哦,又来了,一次渲染重写](1.21.11-from-1.21.10.md#哦又来了-一次渲染重写)
|
||||||
|
- [Gizmo 控件](1.21.11-from-1.21.10.md#gizmo-控件)
|
||||||
|
- [权限大修](1.21.11-from-1.21.10.md#权限-大修)
|
||||||
|
- [新数据组件](1.21.11-from-1.21.10.md#新数据组件)
|
||||||
|
- [环境属性的时间线](1.21.11-from-1.21.10.md#环境属性的时间线)
|
||||||
|
- [游戏规则洗牌](1.21.11-from-1.21.10.md#游戏规则洗牌)
|
||||||
|
- [小幅迁移](1.21.11-from-1.21.10.md#小幅-迁移)
|
||||||
|
|
||||||
|
## 1.21.11 -> 26.1
|
||||||
|
|
||||||
|
[完整入门文档](26.1-from-1.21.11.md)
|
||||||
|
|
||||||
|
- [资源包变更](26.1-from-1.21.11.md#资源包变更)
|
||||||
|
- [Java 25 与反混淆](26.1-from-1.21.11.md#java-25-与反混淆)
|
||||||
|
- [战利品类型展开](26.1-from-1.21.11.md#战利品类型-展开)
|
||||||
|
- [验证大修](26.1-from-1.21.11.md#验证-大修)
|
||||||
|
- [数据包村民交易](26.1-from-1.21.11.md#数据包村民交易)
|
||||||
|
- [`Level#random` 字段现在为 protected](26.1-from-1.21.11.md#levelrandom-字段现在为-protected)
|
||||||
|
- [数据组件初始化器](26.1-from-1.21.11.md#数据组件-初始化器)
|
||||||
|
- [物品实例与堆栈模板](26.1-from-1.21.11.md#物品实例与堆栈模板)
|
||||||
|
- [序列化器记录与配方信息](26.1-from-1.21.11.md#序列化器记录与配方信息)
|
||||||
|
- [染料组件](26.1-from-1.21.11.md#染料组件)
|
||||||
|
- [世界时钟与时间标记](26.1-from-1.21.11.md#世界时钟与时间标记)
|
||||||
|
- [将主关卡数据拆分为保存数据](26.1-from-1.21.11.md#将主关卡数据拆分为保存数据)
|
||||||
|
- [更多渲染变更](26.1-from-1.21.11.md#更多渲染变更)
|
||||||
|
- [小幅迁移](26.1-from-1.21.11.md#小幅-迁移)
|
||||||
Loading…
Reference in New Issue
Block a user