Compare commits
No commits in common. "15ab233b048e82c333109ad3c77fd2a78f2985ff" and "fe3d3478a94cc4ae0eba96a82e877ef1eaab1bd6" have entirely different histories.
15ab233b04
...
fe3d3478a9
18
AITask.md
18
AITask.md
|
|
@ -1,18 +0,0 @@
|
|||
# 任务:多平台模组项目迁移(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;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -48,8 +48,8 @@ public class Lib39 {
|
|||
* @return the resource location
|
||||
*/
|
||||
@Contract("_ -> new")
|
||||
public static @NotNull Identifier rl(String path) {
|
||||
return Identifier.fromNamespaceAndPath(Lib39.MOD_ID, path);
|
||||
public static @NotNull ResourceLocation rl(String path) {
|
||||
return ResourceLocation.fromNamespaceAndPath(Lib39.MOD_ID, path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -60,8 +60,8 @@ public class Lib39 {
|
|||
* @return the resource location
|
||||
*/
|
||||
@Contract("_, _ -> new")
|
||||
public static @NotNull Identifier rl(String modId, String path) {
|
||||
return Identifier.fromNamespaceAndPath(modId, path);
|
||||
public static @NotNull ResourceLocation rl(String modId, String path) {
|
||||
return ResourceLocation.fromNamespaceAndPath(modId, path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -71,8 +71,8 @@ public class Lib39 {
|
|||
* @return the resource location
|
||||
*/
|
||||
@Contract("_ -> new")
|
||||
public static @NotNull Identifier mrl(String path) {
|
||||
return Identifier.withDefaultNamespace(path);
|
||||
public static @NotNull ResourceLocation mrl(String path) {
|
||||
return ResourceLocation.withDefaultNamespace(path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.base.command;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.command.SimpleCommandHelpManager;
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ public class Lib39CommandHelpManager extends SimpleCommandHelpManager {
|
|||
/**
|
||||
* 作为唯一标识符
|
||||
*/
|
||||
Identifier ID = Lib39.rl("command_helper");
|
||||
ResourceLocation ID = Lib39.rl("command_helper");
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
|
|
@ -31,7 +31,7 @@ public class Lib39CommandHelpManager extends SimpleCommandHelpManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Identifier getID() {
|
||||
public ResourceLocation getID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import net.minecraft.commands.CommandSourceStack;
|
|||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
|
|
@ -19,7 +19,6 @@ import top.r3944realms.lib39.core.command.ICommandHelpManager;
|
|||
import top.r3944realms.lib39.core.command.SimpleHelpCommand;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
|
|
@ -93,7 +92,7 @@ public class Lib39HelpCommand extends SimpleHelpCommand {
|
|||
.executes(this::executeCalculate)))
|
||||
)
|
||||
.then(Commands.literal("teleport")
|
||||
.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)) // 需要游戏管理员權限
|
||||
.requires(source -> source.hasPermission(2)) // 需要OP權限
|
||||
.then(Commands.argument("target", EntityArgument.player())
|
||||
.executes(this::executeTeleport))
|
||||
)
|
||||
|
|
@ -285,14 +284,12 @@ public class Lib39HelpCommand extends SimpleHelpCommand {
|
|||
|
||||
if (source.getEntity() instanceof ServerPlayer player) {
|
||||
player.teleportTo(
|
||||
target.level(),
|
||||
target.serverLevel(),
|
||||
target.getX(),
|
||||
target.getY(),
|
||||
target.getZ(),
|
||||
Set.of(),
|
||||
target.getYRot(),
|
||||
target.getXRot(),
|
||||
true
|
||||
target.getXRot()
|
||||
);
|
||||
|
||||
source.sendSuccess(() ->
|
||||
|
|
@ -307,7 +304,7 @@ public class Lib39HelpCommand extends SimpleHelpCommand {
|
|||
|
||||
private int executeInfo(CommandContext<CommandSourceStack> context) {
|
||||
CommandSourceStack source = context.getSource();
|
||||
Identifier dimension = source.getLevel().dimension().identifier();
|
||||
ResourceLocation dimension = source.getLevel().dimension().location();
|
||||
|
||||
source.sendSuccess(() ->
|
||||
Component.translatable("commands.lib39.info.message")
|
||||
|
|
|
|||
|
|
@ -19,16 +19,16 @@ public class Lib39RecipeProvider extends RecipeProvider {
|
|||
* @param output the output
|
||||
* @param registries the registries
|
||||
*/
|
||||
public Lib39RecipeProvider(HolderLookup.Provider output, RecipeOutput recipeOutput) {
|
||||
super(output, recipeOutput);
|
||||
public Lib39RecipeProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) {
|
||||
super(output, registries);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildRecipes() {
|
||||
this.shapeless(RecipeCategory.MISC, Lib39Items.DOLL.get())
|
||||
public void buildRecipes(RecipeOutput recipeOutput) {
|
||||
ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, Lib39Items.DOLL.get())
|
||||
.requires(ItemTags.WOOL)
|
||||
.requires(Items.ARMOR_STAND)
|
||||
.unlockedBy("has_armor_stand",has(Items.ARMOR_STAND))
|
||||
.save(this.output);
|
||||
.save(recipeOutput);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package top.r3944realms.lib39.client.gui.component;
|
|||
import com.mojang.blaze3d.platform.Window;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
|
|
@ -11,7 +12,6 @@ import net.minecraft.client.renderer.ShaderInstance;
|
|||
import net.minecraft.network.chat.Component;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector2f;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import top.r3944realms.lib39.client.shader.Lib39Shaders;
|
||||
import top.r3944realms.lib39.util.MathUtil;
|
||||
import top.r3944realms.lib39.util.lang.FourConsumer;
|
||||
|
|
@ -681,7 +681,7 @@ public class WheelWidget extends AbstractWidget {
|
|||
* @param radius the radius
|
||||
*/
|
||||
public static void renderSelectionEffect(
|
||||
@NonNull GuiGraphics guiGraphics,
|
||||
GuiGraphics guiGraphics,
|
||||
float centerX,
|
||||
float centerY,
|
||||
int color,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package top.r3944realms.lib39.client.model;
|
||||
|
||||
import net.minecraft.client.model.geom.PartPose;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
|
|
@ -23,7 +23,7 @@ public enum DollPoses implements IDollPose{
|
|||
PartPose.offsetAndRotation(2.0F, 19.0F, -2.0F, -1.5708F, -0.3927F, 0.0F)
|
||||
);
|
||||
// 注册全局?
|
||||
private final Identifier id;
|
||||
private final ResourceLocation id;
|
||||
private final Vec3 offset;
|
||||
private final PartPose headPose;
|
||||
private final PartPose bodyPose;
|
||||
|
|
@ -52,7 +52,7 @@ public enum DollPoses implements IDollPose{
|
|||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Identifier getId() {
|
||||
public @NotNull ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package top.r3944realms.lib39.client.model;
|
||||
|
||||
import net.minecraft.client.model.geom.PartPose;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ public interface IDollPose {
|
|||
*
|
||||
* @return the id
|
||||
*/
|
||||
@NotNull Identifier getId();
|
||||
@NotNull ResourceLocation getId();
|
||||
|
||||
/**
|
||||
* Gets total offset.
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import net.minecraft.client.resources.DefaultPlayerSkin;
|
|||
import net.minecraft.client.resources.PlayerSkin;
|
||||
import net.minecraft.client.resources.SkinManager;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
import net.minecraft.world.level.block.SkullBlock;
|
||||
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.SkinManager;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
|
|
@ -75,7 +75,7 @@ public class DollItemRenderer extends BlockEntityWithoutLevelRenderer {
|
|||
|
||||
// 直接从 DataComponents.PROFILE 获取 ResolvableProfile
|
||||
ResolvableProfile profile = stack.get(DataComponents.PROFILE);
|
||||
Pair<Identifier, PlayerSkin.Model> skinInfo = getSkinInfo(profile);
|
||||
Pair<ResourceLocation, PlayerSkin.Model> skinInfo = getSkinInfo(profile);
|
||||
|
||||
poseStack.pushPose();
|
||||
VertexConsumer vertexConsumer = buffer.getBuffer(RenderType.entityTranslucent(skinInfo.first));
|
||||
|
|
@ -93,7 +93,7 @@ public class DollItemRenderer extends BlockEntityWithoutLevelRenderer {
|
|||
/**
|
||||
* 获取皮肤纹理和模型类型(1.21+ 版本)
|
||||
*/
|
||||
public static @NotNull Pair<Identifier, PlayerSkin.Model> getSkinInfo(@NotNull ResolvableProfile profile) {
|
||||
public static @NotNull Pair<ResourceLocation, PlayerSkin.Model> getSkinInfo(@NotNull ResolvableProfile profile) {
|
||||
SkinManager skinManager = Minecraft.getInstance().getSkinManager();
|
||||
|
||||
if (profile != null && profile.gameProfile() != null) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package top.r3944realms.lib39.core.command;
|
|||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.*;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import top.r3944realms.lib39.base.datagen.value.Lib39LangKey;
|
||||
|
|
@ -31,7 +31,7 @@ public interface ICommandHelpManager {
|
|||
*
|
||||
* @return the id
|
||||
*/
|
||||
Identifier getID();
|
||||
ResourceLocation getID();
|
||||
|
||||
/**
|
||||
* Gets head key.
|
||||
|
|
@ -291,10 +291,12 @@ public interface ICommandHelpManager {
|
|||
return Component.literal(rootCommand)
|
||||
.withStyle(ChatFormatting.AQUA)
|
||||
.withStyle(Style.EMPTY
|
||||
.withClickEvent(new ClickEvent.SuggestCommand(
|
||||
.withClickEvent(new ClickEvent(
|
||||
ClickEvent.Action.SUGGEST_COMMAND,
|
||||
rootCommand + " "
|
||||
))
|
||||
.withHoverEvent(new HoverEvent.ShowText(
|
||||
.withHoverEvent(new HoverEvent(
|
||||
HoverEvent.Action.SHOW_TEXT,
|
||||
Component.translatable(Lib39LangKey.Message.HELP_HOVER_COPY_TIP.getKey())
|
||||
))
|
||||
);
|
||||
|
|
@ -314,10 +316,12 @@ public interface ICommandHelpManager {
|
|||
MutableComponent commandName = Component.literal(node.getName())
|
||||
.withStyle(ChatFormatting.DARK_AQUA)
|
||||
.withStyle(Style.EMPTY
|
||||
.withClickEvent(new ClickEvent.SuggestCommand(
|
||||
.withClickEvent(new ClickEvent(
|
||||
ClickEvent.Action.SUGGEST_COMMAND,
|
||||
suggestedCommand
|
||||
))
|
||||
.withHoverEvent(new HoverEvent.ShowText(
|
||||
.withHoverEvent(new HoverEvent(
|
||||
HoverEvent.Action.SHOW_TEXT,
|
||||
Component.translatable(Lib39LangKey.Message.HELP_HOVER_COPY_TIP.getKey(), suggestedCommand)
|
||||
))
|
||||
);
|
||||
|
|
@ -366,10 +370,12 @@ public interface ICommandHelpManager {
|
|||
|
||||
// 为按钮添加点击事件
|
||||
toggleButton.withStyle(Style.EMPTY
|
||||
.withClickEvent(new ClickEvent.RunCommand(
|
||||
.withClickEvent(new ClickEvent(
|
||||
ClickEvent.Action.RUN_COMMAND,
|
||||
"/" + getCommandHead() + " help toggle " + node.hashCode()
|
||||
))
|
||||
.withHoverEvent(new HoverEvent.ShowText(
|
||||
.withHoverEvent(new HoverEvent(
|
||||
HoverEvent.Action.SHOW_TEXT,
|
||||
Component.translatable(Lib39LangKey.Message.HELP_CLICK_EXPAND.getKey())
|
||||
.withStyle(ChatFormatting.GRAY)
|
||||
))
|
||||
|
|
@ -461,12 +467,11 @@ public interface ICommandHelpManager {
|
|||
).withStyle(ChatFormatting.GRAY));
|
||||
|
||||
collapsedInfo.withStyle(Style.EMPTY
|
||||
.withClickEvent(new ClickEvent.RunCommand(
|
||||
.withClickEvent(new ClickEvent(
|
||||
ClickEvent.Action.RUN_COMMAND,
|
||||
"/" + getCommandHead() + " help toggle " + node.hashCode()
|
||||
))
|
||||
.withHoverEvent(new HoverEvent.ShowText(
|
||||
Component.translatable(Lib39LangKey.Message.HELP_CLICK_EXPAND.getKey())
|
||||
))
|
||||
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.translatable(Lib39LangKey.Message.HELP_CLICK_EXPAND.getKey())))
|
||||
);
|
||||
|
||||
result.add(collapsedInfo.append(Component.literal(NEWLINE)));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.core.command;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.core.command.model.CommandNode;
|
||||
import top.r3944realms.lib39.core.command.model.Parameter;
|
||||
|
|
@ -28,7 +28,7 @@ public abstract class SimpleCommandHelpManager implements ICommandHelpManager {
|
|||
public void initialize() {
|
||||
if (root == null) {
|
||||
// 現在子類的字段已經初始化完成
|
||||
Identifier id = getID();
|
||||
ResourceLocation id = getID();
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("getID() must return non-null");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.core.compat;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -22,7 +22,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
* @return the id
|
||||
*/
|
||||
@Override
|
||||
public Identifier getId() {
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
/**
|
||||
* The Id.
|
||||
*/
|
||||
protected final Identifier id;
|
||||
protected final ResourceLocation id;
|
||||
|
||||
/**
|
||||
* The Initialized.
|
||||
|
|
@ -58,7 +58,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
*
|
||||
* @param id the id
|
||||
*/
|
||||
public CompatManager(@NotNull Identifier id) {
|
||||
public CompatManager(@NotNull ResourceLocation id) {
|
||||
this.id = id;
|
||||
this.logger = LoggerFactory.getLogger(id.toString());
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
* @param compat the compat
|
||||
*/
|
||||
@Override
|
||||
public void registerCompat(Identifier id, C compat) {
|
||||
public void registerCompat(ResourceLocation id, C compat) {
|
||||
if (initialized) {
|
||||
// 已初始化,直接注册
|
||||
doRegisterCompat(id, compat);
|
||||
|
|
@ -87,7 +87,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
* @param id the id
|
||||
* @param compat the compat
|
||||
*/
|
||||
protected void doRegisterCompat(Identifier id, C compat) {
|
||||
protected void doRegisterCompat(ResourceLocation id, C compat) {
|
||||
if (getCompatMap().containsKey(id)) {
|
||||
logger.warn("Compat with id {} is already registered!", id);
|
||||
return;
|
||||
|
|
@ -122,7 +122,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
pendingTasks.clear();
|
||||
|
||||
// 初始化所有兼容模块
|
||||
for (Map.Entry<Identifier, C> entry : getCompatMap().entrySet()) {
|
||||
for (Map.Entry<ResourceLocation, C> entry : getCompatMap().entrySet()) {
|
||||
if (!entry.getValue().isInitialized() && entry.getValue().isModLoaded()) {
|
||||
try {
|
||||
entry.getValue().initialize();
|
||||
|
|
@ -143,7 +143,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
* @return the compat
|
||||
*/
|
||||
@Override
|
||||
public Optional<C> getCompat(Identifier id) {
|
||||
public Optional<C> getCompat(ResourceLocation id) {
|
||||
return Optional.ofNullable(getCompatMap().get(id));
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +154,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean hasCompat(Identifier id) {
|
||||
public boolean hasCompat(ResourceLocation id) {
|
||||
return getCompatMap().containsKey(id);
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
* @param id the id
|
||||
*/
|
||||
@Override
|
||||
public void unregisterCompat(Identifier id) {
|
||||
public void unregisterCompat(ResourceLocation id) {
|
||||
C removed = getCompatMap().remove(id);
|
||||
if (removed != null) {
|
||||
logger.debug("Unregistered compat: {}", id);
|
||||
|
|
@ -187,7 +187,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
*/
|
||||
public void onLoadComplete() {
|
||||
logger.info("Calling onLoadComplete for {} compatibility modules", getCompatMap().size());
|
||||
for (Map.Entry<Identifier, C> entry : getCompatMap().entrySet()) {
|
||||
for (Map.Entry<ResourceLocation, C> entry : getCompatMap().entrySet()) {
|
||||
try {
|
||||
entry.getValue().onLoadComplete();
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.core.compat;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ public interface ICompat {
|
|||
*
|
||||
* @return the resource location
|
||||
*/
|
||||
Identifier id();
|
||||
ResourceLocation id();
|
||||
|
||||
/**
|
||||
* Initialize.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.core.compat;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
|
@ -16,14 +16,14 @@ public interface ICompatManager<C extends ICompat> {
|
|||
*
|
||||
* @return the id
|
||||
*/
|
||||
Identifier getId();
|
||||
ResourceLocation getId();
|
||||
|
||||
/**
|
||||
* Gets compat map.
|
||||
*
|
||||
* @return the compat map
|
||||
*/
|
||||
Map<Identifier, C> getCompatMap();
|
||||
Map<ResourceLocation, C> getCompatMap();
|
||||
|
||||
/**
|
||||
* Initialize.
|
||||
|
|
@ -36,7 +36,7 @@ public interface ICompatManager<C extends ICompat> {
|
|||
* @param id the id
|
||||
* @param compat the compat
|
||||
*/
|
||||
void registerCompat(Identifier id, C compat);
|
||||
void registerCompat(ResourceLocation id, C compat);
|
||||
|
||||
/**
|
||||
* Register compat.
|
||||
|
|
@ -53,7 +53,7 @@ public interface ICompatManager<C extends ICompat> {
|
|||
* @param id the id
|
||||
* @return the compat
|
||||
*/
|
||||
Optional<C> getCompat(Identifier id);
|
||||
Optional<C> getCompat(ResourceLocation id);
|
||||
|
||||
/**
|
||||
* Has compat boolean.
|
||||
|
|
@ -61,12 +61,12 @@ public interface ICompatManager<C extends ICompat> {
|
|||
* @param id the id
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean hasCompat(Identifier id);
|
||||
boolean hasCompat(ResourceLocation id);
|
||||
|
||||
/**
|
||||
* Unregister compat.
|
||||
*
|
||||
* @param id the id
|
||||
*/
|
||||
void unregisterCompat(Identifier id);
|
||||
void unregisterCompat(ResourceLocation id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.core.compat;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
@ -13,19 +13,19 @@ public class SimpleCompatManager extends CompatManager<ICompat> {
|
|||
/**
|
||||
* The Compats.
|
||||
*/
|
||||
Map<Identifier, ICompat> compats = new HashMap<>();
|
||||
Map<ResourceLocation, ICompat> compats = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Instantiates a new Compat manager.
|
||||
*
|
||||
* @param id the id
|
||||
*/
|
||||
public SimpleCompatManager(@NotNull Identifier id) {
|
||||
public SimpleCompatManager(@NotNull ResourceLocation id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Identifier, ICompat> getCompatMap() {
|
||||
public Map<ResourceLocation, ICompat> getCompatMap() {
|
||||
return compats;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.core.register;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ public class Lib39SoundEvents {
|
|||
/**
|
||||
* The constant RL_DUCK_TOY.
|
||||
*/
|
||||
public static final Identifier RL_DUCK_TOY = Lib39.rl("duck_toy");
|
||||
public static final ResourceLocation RL_DUCK_TOY = Lib39.rl("duck_toy");
|
||||
/**
|
||||
* The constant DUCK_TOY.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -3,12 +3,8 @@ package top.r3944realms.lib39.core.sync;
|
|||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
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 java.util.Optional;
|
||||
|
||||
/**
|
||||
* The interface Lib 39 sync data holder.
|
||||
*/
|
||||
|
|
@ -30,25 +26,24 @@ public interface ILib39SyncDataHolder {
|
|||
/**
|
||||
* Lib 39 inject save sync data compound tag.
|
||||
*
|
||||
* @param output the tag
|
||||
* @param tag the tag
|
||||
* @return the compound tag
|
||||
*/
|
||||
default void lib39$injectSaveSyncData(ValueOutput output) {
|
||||
default CompoundTag lib39$injectSaveSyncData(CompoundTag tag) {
|
||||
if (lib39$getSyncData() != null && !lib39$getSyncData().isEmpty()) {
|
||||
output.store("Lib39Data", CompoundTag.CODEC, lib39$getSyncData());
|
||||
tag.put("Lib39Data", lib39$getSyncData());
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lib 39 inject load sync data.
|
||||
*
|
||||
* @param input the input
|
||||
* @param tag the tag
|
||||
*/
|
||||
default void lib39$injectLoadSyncData(@NotNull ValueInput input) {
|
||||
Optional<ValueInput> lib39DataOpt = input.child("Lib39Data");
|
||||
if (lib39DataOpt.isPresent()) {
|
||||
ValueInput valueInput = lib39DataOpt.get();
|
||||
Optional<CompoundTag> lib39Data = valueInput.read("Lib39Data", CompoundTag.CODEC);
|
||||
lib39$setSyncData(lib39Data.get());
|
||||
default void lib39$injectLoadSyncData(@NotNull CompoundTag tag) {
|
||||
if (tag.contains("Lib39Data", Tag.TAG_COMPOUND)) {
|
||||
lib39$setSyncData(tag.getCompound("Lib39Data"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,10 +63,7 @@ public interface ILib39SyncDataHolder {
|
|||
*/
|
||||
default void loadSyncData(NBTEntitySyncData syncData) {
|
||||
if (syncData != null && lib39$getSyncData().contains(syncData.id.toDebugFileName())) {
|
||||
Optional<CompoundTag> compound = lib39$getSyncData().getCompound(syncData.id.toDebugFileName());
|
||||
if (compound.isPresent()) {
|
||||
syncData.deserializeNBT(compound.get());
|
||||
}
|
||||
syncData.deserializeNBT(lib39$getSyncData().getCompound(syncData.id.toDebugFileName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.core.sync;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
/**
|
||||
* The interface Sync data.
|
||||
|
|
@ -13,7 +13,7 @@ public interface ISyncData<T> {
|
|||
*
|
||||
* @return the resource location
|
||||
*/
|
||||
Identifier id();
|
||||
ResourceLocation id();
|
||||
|
||||
/**
|
||||
* Is dirty boolean.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package top.r3944realms.lib39.core.sync;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
|
@ -15,19 +15,19 @@ public abstract class NBTEntitySyncData implements IEntity, ISyncData<NBTEntityS
|
|||
/**
|
||||
* The Id.
|
||||
*/
|
||||
protected final Identifier id;
|
||||
protected final ResourceLocation id;
|
||||
|
||||
/**
|
||||
* Instantiates a new Nbt sync data.
|
||||
*
|
||||
* @param id the id
|
||||
*/
|
||||
protected NBTEntitySyncData(Identifier id) {
|
||||
protected NBTEntitySyncData(ResourceLocation id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier id() {
|
||||
public ResourceLocation id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package top.r3944realms.lib39.core.sync;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
|
@ -22,7 +22,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
*
|
||||
* @return the typed entries
|
||||
*/
|
||||
protected abstract Map<Identifier, V> getTypedEntries();
|
||||
protected abstract Map<ResourceLocation, V> getTypedEntries();
|
||||
|
||||
/**
|
||||
* 数据提供者接口 - 用于通过键获取数据
|
||||
|
|
@ -86,11 +86,11 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <K, T extends ISyncData<?>> void registerManagerWithProvider(
|
||||
Identifier key,
|
||||
ResourceLocation key,
|
||||
ISyncManager<K, T> manager,
|
||||
DataProvider<Entity, T> dataProvider
|
||||
) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
Objects.requireNonNull(manager, "Sync manager cannot be null");
|
||||
Objects.requireNonNull(dataProvider, "Data provider cannot be null");
|
||||
|
||||
|
|
@ -108,11 +108,11 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <K, T extends ISyncData<?>> void registerManager(
|
||||
Identifier key,
|
||||
ResourceLocation key,
|
||||
ISyncManager<K, T> manager,
|
||||
Function<Entity, Optional<T>> getter
|
||||
) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
Objects.requireNonNull(manager, "Sync manager cannot be null");
|
||||
Objects.requireNonNull(getter, "Data getter function cannot be null");
|
||||
|
||||
|
|
@ -126,8 +126,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
* @param manager the manager
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void registerManager(Identifier key, ISyncManager<?, ? extends ISyncData<?>> manager) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
public void registerManager(ResourceLocation key, ISyncManager<?, ? extends ISyncData<?>> manager) {
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
Objects.requireNonNull(manager, "Sync manager cannot be null");
|
||||
|
||||
// 创建一个没有数据提供者的 TypedSyncEntry
|
||||
|
|
@ -146,7 +146,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
* @return the manager
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <K, T extends ISyncData<?>> Optional<ISyncManager<K, T>> getManager(Identifier key) {
|
||||
public <K, T extends ISyncData<?>> Optional<ISyncManager<K, T>> getManager(ResourceLocation key) {
|
||||
TypedSyncEntry<?,?> entry = getTypedEntries().get(key);
|
||||
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
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ISyncData<?>> Optional<DataProvider<Entity, T>> getDataProvider(Identifier key) {
|
||||
public <T extends ISyncData<?>> Optional<DataProvider<Entity, T>> getDataProvider(ResourceLocation key) {
|
||||
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
||||
if (entry != null && entry.dataProvider != null) {
|
||||
return Optional.of((DataProvider<Entity, T>) entry.dataProvider);
|
||||
|
|
@ -176,7 +176,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
* @return the entity data
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ISyncData<?>> Optional<T> getEntityData(Identifier key, Entity entity) {
|
||||
public <T extends ISyncData<?>> Optional<T> getEntityData(ResourceLocation key, Entity entity) {
|
||||
return getDataProvider(key)
|
||||
.flatMap(provider -> {
|
||||
Optional<ISyncData<?>> result = provider.getData(entity);
|
||||
|
|
@ -190,8 +190,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
* @param key the key
|
||||
* @param classes the classes
|
||||
*/
|
||||
public final void allowEntityClass(Identifier key, Class<?>... classes) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
public final void allowEntityClass(ResourceLocation key, Class<?>... classes) {
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
Objects.requireNonNull(classes, "Classes array cannot be null");
|
||||
|
||||
if (classes.length == 0) {
|
||||
|
|
@ -210,8 +210,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
* @param key the key
|
||||
* @param classes the classes
|
||||
*/
|
||||
public final void disallowEntityClass(Identifier key, Class<?>... classes) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
public final void disallowEntityClass(ResourceLocation key, Class<?>... classes) {
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
Objects.requireNonNull(classes, "Classes array cannot be null");
|
||||
|
||||
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
||||
|
|
@ -227,8 +227,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
* @param key the key
|
||||
* @param dataProvider the data provider
|
||||
*/
|
||||
public <T extends ISyncData<?>> void bindDataProvider(Identifier key, DataProvider<Entity, T> dataProvider) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
public <T extends ISyncData<?>> void bindDataProvider(ResourceLocation key, DataProvider<Entity, T> dataProvider) {
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
Objects.requireNonNull(dataProvider, "Data provider cannot be null");
|
||||
|
||||
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
||||
|
|
@ -247,7 +247,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
* @param key the key
|
||||
* @param getter the data getter function
|
||||
*/
|
||||
public <T extends ISyncData<?>> void bindDataGetter(Identifier key, @NotNull Function<Entity, Optional<T>> getter) {
|
||||
public <T extends ISyncData<?>> void bindDataGetter(ResourceLocation key, @NotNull Function<Entity, Optional<T>> getter) {
|
||||
bindDataProvider(key, getter::apply);
|
||||
}
|
||||
|
||||
|
|
@ -256,8 +256,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
*
|
||||
* @param key the key
|
||||
*/
|
||||
public void unbindDataProvider(Identifier key) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
public void unbindDataProvider(ResourceLocation key) {
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
|
||||
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
||||
if (entry != null) {
|
||||
|
|
@ -271,8 +271,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
*
|
||||
* @param key the key
|
||||
*/
|
||||
public void clearAllowedEntityClasses(Identifier key) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
public void clearAllowedEntityClasses(ResourceLocation key) {
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
|
||||
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
||||
if (entry != null) {
|
||||
|
|
@ -287,8 +287,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
* @param entityClass the entity class
|
||||
* @return the boolean
|
||||
*/
|
||||
public boolean isEntityClassAllowed(Identifier key, Class<?> entityClass) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
public boolean isEntityClassAllowed(ResourceLocation key, Class<?> entityClass) {
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
Objects.requireNonNull(entityClass, "Entity class cannot be null");
|
||||
|
||||
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
|
||||
|
|
@ -311,7 +311,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
* @param managerId the manager id
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void trackEntityForManager(Entity entity, Identifier managerId) {
|
||||
public void trackEntityForManager(Entity entity, ResourceLocation managerId) {
|
||||
TypedSyncEntry<UUID, ?> entry = (TypedSyncEntry<UUID, ?>) getTypedEntries().get(managerId);
|
||||
if (entry != null) {
|
||||
trackEntityWithTypedEntry(entity, entry);
|
||||
|
|
@ -332,7 +332,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
* @param managerId the manager id
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void untrackEntityForManager(Entity entity, Identifier managerId) {
|
||||
public void untrackEntityForManager(Entity entity, ResourceLocation managerId) {
|
||||
TypedSyncEntry<UUID, ?> entry = (TypedSyncEntry<UUID, ?>) getTypedEntries().get(managerId);
|
||||
if (entry != null) {
|
||||
untrackEntityWithTypedEntry(entity, entry);
|
||||
|
|
@ -352,7 +352,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
* @param entity the entity
|
||||
*/
|
||||
public void untrackEntityFromAllManagers(Entity entity) {
|
||||
for (Identifier id : getRegisteredKeys()) {
|
||||
for (ResourceLocation id : getRegisteredKeys()) {
|
||||
if (isEntityClassAllowed(id, entity.getClass())) {
|
||||
untrackEntityForManager(entity, id);
|
||||
}
|
||||
|
|
@ -365,7 +365,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
* @param entities the entities
|
||||
* @param managerId the manager id
|
||||
*/
|
||||
public void untrackEntitiesForManager(@NotNull Iterable<Entity> entities, Identifier managerId) {
|
||||
public void untrackEntitiesForManager(@NotNull Iterable<Entity> entities, ResourceLocation managerId) {
|
||||
for (Entity entity : entities) {
|
||||
untrackEntityForManager(entity, managerId);
|
||||
}
|
||||
|
|
@ -387,7 +387,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
*
|
||||
* @param managerId the manager id
|
||||
*/
|
||||
public void clearAllTrackedData(Identifier managerId) {
|
||||
public void clearAllTrackedData(ResourceLocation managerId) {
|
||||
TypedSyncEntry<?, ?> entry = getTypedEntries().get(managerId);
|
||||
if (entry != null) {
|
||||
clearTrackedDataForEntry(entry);
|
||||
|
|
@ -405,7 +405,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
* 清理所有管理器的跟踪数据
|
||||
*/
|
||||
public void clearAllTrackedData() {
|
||||
for (Identifier id : getRegisteredKeys()) {
|
||||
for (ResourceLocation id : getRegisteredKeys()) {
|
||||
clearAllTrackedData(id);
|
||||
}
|
||||
}
|
||||
|
|
@ -422,7 +422,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
// 辅助方法:更新条目的数据提供者
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <K, T extends ISyncData<?>> void updateDataProviderInEntry(
|
||||
Identifier id,
|
||||
ResourceLocation id,
|
||||
TypedSyncEntry<?,?> entry,
|
||||
DataProvider<Entity, T> newDataProvider
|
||||
) {
|
||||
|
|
@ -441,7 +441,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
*
|
||||
* @return the registered keys
|
||||
*/
|
||||
public Set<Identifier> getRegisteredKeys() {
|
||||
public Set<ResourceLocation> getRegisteredKeys() {
|
||||
return Collections.unmodifiableSet(getTypedEntries().keySet());
|
||||
}
|
||||
|
||||
|
|
@ -450,7 +450,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
*
|
||||
* @param consumer the consumer
|
||||
*/
|
||||
public void forEach(BiConsumer<Identifier, ISyncManager<?,?>> consumer) {
|
||||
public void forEach(BiConsumer<ResourceLocation, ISyncManager<?,?>> consumer) {
|
||||
Objects.requireNonNull(consumer, "Consumer cannot be null");
|
||||
getTypedEntries().forEach((key, entry) -> consumer.accept(key, entry.manager));
|
||||
}
|
||||
|
|
@ -476,8 +476,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
|
|||
*
|
||||
* @param key the key
|
||||
*/
|
||||
public void removeManager(Identifier key) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
public void removeManager(ResourceLocation key) {
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
getTypedEntries().remove(key);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package top.r3944realms.lib39.example.content.data;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.core.sync.NBTEntitySyncData;
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ public abstract class AbstractedTestSyncData extends NBTEntitySyncData {
|
|||
*
|
||||
* @param id the id
|
||||
*/
|
||||
protected AbstractedTestSyncData(Identifier id) {
|
||||
protected AbstractedTestSyncData(ResourceLocation id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package top.r3944realms.lib39.example.content.item;
|
|||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
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.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.item.component.TooltipDisplay;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 用于执行数据查询并检查同步状态的物品
|
||||
|
|
@ -39,7 +39,7 @@ public abstract class AbstractFabricItem extends Item {
|
|||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand hand) {
|
||||
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand hand) {
|
||||
ItemStack itemStack = player.getItemInHand(hand);
|
||||
|
||||
if (level.isClientSide()) {
|
||||
|
|
@ -64,10 +64,10 @@ public abstract class AbstractFabricItem extends Item {
|
|||
}
|
||||
|
||||
// 添加冷却时间
|
||||
player.getCooldowns().addCooldown(itemStack, 20); // 1秒冷却
|
||||
player.getCooldowns().addCooldown(this, 20); // 1秒冷却
|
||||
}
|
||||
|
||||
return InteractionResult.SUCCESS.heldItemTransformedTo(itemStack);
|
||||
return InteractionResultHolder.sidedSuccess(itemStack, level.isClientSide());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -193,7 +193,7 @@ public abstract class AbstractFabricItem extends Item {
|
|||
Thread.sleep(3000);
|
||||
|
||||
// 在服务器线程中执行结果处理
|
||||
player.level().getServer().execute(() -> {
|
||||
player.server.execute(() -> {
|
||||
displayServerSingleEndResults(player, target);
|
||||
});
|
||||
|
||||
|
|
@ -203,7 +203,7 @@ public abstract class AbstractFabricItem extends Item {
|
|||
player.sendSystemMessage(Component.literal("§c数据查询被中断"));
|
||||
} catch (Exception e) {
|
||||
Lib39.LOGGER.error("[FabricItem] 数据查询出错", e);
|
||||
player.level().getServer().execute(() ->
|
||||
player.server.execute(() ->
|
||||
player.sendSystemMessage(Component.literal("§c数据查询出错: " + e.getMessage()))
|
||||
);
|
||||
}
|
||||
|
|
@ -530,28 +530,29 @@ public abstract class AbstractFabricItem extends Item {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack itemStack, TooltipContext context, TooltipDisplay display, Consumer<Component> componentConsumer, TooltipFlag tooltipFlag) {
|
||||
super.appendHoverText(itemStack, context, display, componentConsumer, tooltipFlag);
|
||||
componentConsumer.accept(Component.literal("§7右键点击在 3 秒后执行"));
|
||||
componentConsumer.accept(Component.literal("§7§e准星瞄准生物§7的数据查询"));
|
||||
componentConsumer.accept(Component.literal("§7§oShift + 右键§7进行§e客户端-服务器双端同步检查§7"));
|
||||
componentConsumer.accept(Component.literal(""));
|
||||
componentConsumer.accept(Component.literal("§6查询延迟: §e3秒"));
|
||||
componentConsumer.accept(Component.literal("§6瞄准距离: §e20格"));
|
||||
componentConsumer.accept(Component.literal("§6冷却时间: §e1秒"));
|
||||
componentConsumer.accept(Component.literal(""));
|
||||
componentConsumer.accept(Component.literal("§a单端查询内容:"));
|
||||
componentConsumer.accept(Component.literal("§7- 基础数据字段"));
|
||||
componentConsumer.accept(Component.literal("§7- 自定义数据结构"));
|
||||
componentConsumer.accept(Component.literal("§7- 数据验证状态"));
|
||||
componentConsumer.accept(Component.literal("§7- 同步状态信息"));
|
||||
componentConsumer.accept(Component.literal(""));
|
||||
componentConsumer.accept(Component.literal("§e双端同步检查:"));
|
||||
componentConsumer.accept(Component.literal("§7- 客户端和服务器同时查询"));
|
||||
componentConsumer.accept(Component.literal("§7- 字段级同步状态对比"));
|
||||
componentConsumer.accept(Component.literal("§7- 总体同步率计算"));
|
||||
componentConsumer.accept(Component.literal("§7- 双端数据状态差异"));
|
||||
componentConsumer.accept(Component.literal("§7- 同步建议"));
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
||||
|
||||
tooltipComponents.add(Component.literal("§7右键点击在 3 秒后执行"));
|
||||
tooltipComponents.add(Component.literal("§7§e准星瞄准生物§7的数据查询"));
|
||||
tooltipComponents.add(Component.literal("§7§oShift + 右键§7进行§e客户端-服务器双端同步检查§7"));
|
||||
tooltipComponents.add(Component.literal(""));
|
||||
tooltipComponents.add(Component.literal("§6查询延迟: §e3秒"));
|
||||
tooltipComponents.add(Component.literal("§6瞄准距离: §e20格"));
|
||||
tooltipComponents.add(Component.literal("§6冷却时间: §e1秒"));
|
||||
tooltipComponents.add(Component.literal(""));
|
||||
tooltipComponents.add(Component.literal("§a单端查询内容:"));
|
||||
tooltipComponents.add(Component.literal("§7- 基础数据字段"));
|
||||
tooltipComponents.add(Component.literal("§7- 自定义数据结构"));
|
||||
tooltipComponents.add(Component.literal("§7- 数据验证状态"));
|
||||
tooltipComponents.add(Component.literal("§7- 同步状态信息"));
|
||||
tooltipComponents.add(Component.literal(""));
|
||||
tooltipComponents.add(Component.literal("§e双端同步检查:"));
|
||||
tooltipComponents.add(Component.literal("§7- 客户端和服务器同时查询"));
|
||||
tooltipComponents.add(Component.literal("§7- 字段级同步状态对比"));
|
||||
tooltipComponents.add(Component.literal("§7- 总体同步率计算"));
|
||||
tooltipComponents.add(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.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
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.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.item.component.TooltipDisplay;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 用于对准星生物触发 TestSyncData 随机变换的物品
|
||||
|
|
@ -40,7 +40,7 @@ public abstract class AbstractNeoForgeItem extends Item {
|
|||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand hand) {
|
||||
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand hand) {
|
||||
ItemStack itemStack = player.getItemInHand(hand);
|
||||
|
||||
if (!level.isClientSide()) {
|
||||
|
|
@ -55,10 +55,10 @@ public abstract class AbstractNeoForgeItem extends Item {
|
|||
}
|
||||
|
||||
// 添加冷却时间
|
||||
player.getCooldowns().addCooldown(itemStack, 20); // 1秒冷却
|
||||
player.getCooldowns().addCooldown(this, 20); // 1秒冷却
|
||||
}
|
||||
|
||||
return InteractionResult.SUCCESS.heldItemTransformedTo(itemStack);
|
||||
return InteractionResultHolder.sidedSuccess(itemStack, level.isClientSide());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -268,25 +268,27 @@ public abstract class AbstractNeoForgeItem extends Item {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack itemStack, TooltipContext context, TooltipDisplay display, Consumer<Component> componentConsumer, TooltipFlag tooltipFlag) {
|
||||
super.appendHoverText(itemStack, context, display, componentConsumer, tooltipFlag);
|
||||
componentConsumer.accept(Component.literal("§7右键点击触发§e准星瞄准生物§7的"));
|
||||
componentConsumer.accept(Component.literal("§7测试数据随机变换"));
|
||||
componentConsumer.accept(Component.literal("§7§oShift + 右键§7操作§e自身§7数据"));
|
||||
componentConsumer.accept(Component.literal(""));
|
||||
componentConsumer.accept(Component.literal("§6冷却时间: §e1秒"));
|
||||
componentConsumer.accept(Component.literal("§6瞄准距离: §e20格"));
|
||||
componentConsumer.accept(Component.literal(""));
|
||||
componentConsumer.accept(Component.literal("§a变换类型:"));
|
||||
componentConsumer.accept(Component.literal("§7- 完全随机数据"));
|
||||
componentConsumer.accept(Component.literal("§7- 字符串+计数器"));
|
||||
componentConsumer.accept(Component.literal("§7- 数值数据"));
|
||||
componentConsumer.accept(Component.literal("§7- 自定义数据"));
|
||||
componentConsumer.accept(Component.literal("§7- 重置默认值"));
|
||||
componentConsumer.accept(Component.literal("§7- 玩家专属数据"));
|
||||
componentConsumer.accept(Component.literal(""));
|
||||
componentConsumer.accept(Component.literal("§e自身操作特性:"));
|
||||
componentConsumer.accept(Component.literal("§7- 显示数据预览"));
|
||||
componentConsumer.accept(Component.literal("§7- 玩家专属数据变换"));
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
||||
|
||||
|
||||
tooltipComponents.add(Component.literal("§7右键点击触发§e准星瞄准生物§7的"));
|
||||
tooltipComponents.add(Component.literal("§7测试数据随机变换"));
|
||||
tooltipComponents.add(Component.literal("§7§oShift + 右键§7操作§e自身§7数据"));
|
||||
tooltipComponents.add(Component.literal(""));
|
||||
tooltipComponents.add(Component.literal("§6冷却时间: §e1秒"));
|
||||
tooltipComponents.add(Component.literal("§6瞄准距离: §e20格"));
|
||||
tooltipComponents.add(Component.literal(""));
|
||||
tooltipComponents.add(Component.literal("§a变换类型:"));
|
||||
tooltipComponents.add(Component.literal("§7- 完全随机数据"));
|
||||
tooltipComponents.add(Component.literal("§7- 字符串+计数器"));
|
||||
tooltipComponents.add(Component.literal("§7- 数值数据"));
|
||||
tooltipComponents.add(Component.literal("§7- 自定义数据"));
|
||||
tooltipComponents.add(Component.literal("§7- 重置默认值"));
|
||||
tooltipComponents.add(Component.literal("§7- 玩家专属数据"));
|
||||
tooltipComponents.add(Component.literal(""));
|
||||
tooltipComponents.add(Component.literal("§e自身操作特性:"));
|
||||
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.world.InteractionHand;
|
||||
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.example.client.screen.ForgeScreen;
|
||||
|
|
@ -25,7 +25,7 @@ public class ForgeItem extends Item {
|
|||
}
|
||||
|
||||
@Override
|
||||
public @NotNull InteractionResult use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand usedHand) {
|
||||
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand usedHand) {
|
||||
if (level.isClientSide() && usedHand == InteractionHand.MAIN_HAND) {
|
||||
ClientOpt.clientUse(usedHand);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package top.r3944realms.lib39.mixin.carryon;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
|
@ -11,12 +12,10 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import top.r3944realms.lib39.content.item.DollItem;
|
||||
import top.r3944realms.lib39.util.GameProfileHelper;
|
||||
import top.r3944realms.lib39.util.storage.nbt.NBTReader;
|
||||
import top.r3944realms.lib39.util.nbt.NBTReader;
|
||||
import tschipp.carryon.client.render.CarriedObjectRender;
|
||||
import tschipp.carryon.common.carry.CarryOnData;
|
||||
import tschipp.carryon.common.carry.CarryOnDataManager;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
|
|
@ -27,27 +26,40 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
@Mixin(value = CarriedObjectRender.class, remap = false)
|
||||
public class MixinCarriedObjectRender {
|
||||
@ModifyVariable(
|
||||
method = "drawBlock",
|
||||
method = "drawFirstPersonBlock",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
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
|
||||
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 modifyRenderStack(ItemStack renderStack, @Local(argsOnly = true) Player player) {
|
||||
if (renderStack.getItem() instanceof DollItem) {
|
||||
CarryOnData carry = CarryOnDataManager.getCarryData(player);
|
||||
if (carry != null) {
|
||||
Optional<CompoundTag> compound = carry.getNbt().getCompound("tile");
|
||||
AtomicReference<ResolvableProfile> profileHolder = new AtomicReference<>();
|
||||
NBTReader.ofOpt(compound).gameProfile("profile", profileHolder::set);
|
||||
if (profileHolder.get() != null) {
|
||||
GameProfileHelper.saveProfileToItemStack(renderStack,profileHolder.get());
|
||||
}
|
||||
private static ItemStack warpDollItem$1(ItemStack stack, @Local(ordinal = 0, argsOnly = true) Player player) {
|
||||
if (stack.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(stack, new ResolvableProfile(gameProfileAtomicReference.get()));
|
||||
}
|
||||
}
|
||||
return renderStack;
|
||||
return stack;
|
||||
}
|
||||
@ModifyVariable(
|
||||
method = "drawThirdPerson",
|
||||
at = @At(
|
||||
value = "LOAD",
|
||||
target = "Ltschipp/carryon/client/render/CarryRenderHelper;renderBakedModel(Lnet/minecraft/world/item/ItemStack;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/resources/model/BakedModel;)V"
|
||||
)
|
||||
)
|
||||
private static ItemStack warpDollItem$2(ItemStack tileItem, @Local(ordinal = 0) Player player) {
|
||||
if (tileItem.getItem() instanceof DollItem) {
|
||||
CompoundTag compound = CarryOnDataManager.getCarryData(player).getNbt().getCompound("tile");
|
||||
AtomicReference<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,10 +4,7 @@ import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
|
|||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
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.jspecify.annotations.NonNull;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
|
@ -46,20 +43,19 @@ public abstract class MixinEntity implements ILib39SyncDataHolder {
|
|||
}
|
||||
|
||||
@WrapMethod(method = "saveWithoutId")
|
||||
private void wrapSave(ValueOutput output, @NonNull Operation<Void> original) {
|
||||
private CompoundTag wrapSave(CompoundTag compound, @NotNull Operation<CompoundTag> original) {
|
||||
Services.PLATFORM.getUtilHelper().getSyncData2Manager().forEach((id, manager) -> {
|
||||
ISyncData<?> o = manager.getSyncMap().get(getUUID());
|
||||
if (o instanceof NBTEntitySyncData syncData) {
|
||||
saveSyncData(syncData);
|
||||
}
|
||||
});
|
||||
original.call(output);
|
||||
lib39$injectSaveSyncData(output);
|
||||
return lib39$injectSaveSyncData(original.call(compound));
|
||||
}
|
||||
|
||||
@WrapMethod(method = "load")
|
||||
private void warpLoad(ValueInput input, @NonNull Operation<Void> original) {
|
||||
original.call(input);
|
||||
lib39$injectLoadSyncData(input);
|
||||
private void warpLoad(CompoundTag compound, @NotNull Operation<Void> original) {
|
||||
original.call(compound);
|
||||
lib39$injectLoadSyncData(compound);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,68 +7,81 @@ import com.mojang.authlib.properties.Property;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.PlayerInfo;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
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.PlayerModelType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.util.nbt.NBTReader;
|
||||
import top.r3944realms.lib39.util.nbt.NBTWriter;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* The type GameProfile helper.
|
||||
*/
|
||||
public class GameProfileHelper {
|
||||
/**
|
||||
* 获取 GameProfile(通过玩家名)
|
||||
*/
|
||||
@Contract("_ -> new")
|
||||
public static @NonNull ResolvableProfile fetchGameProfileByName(String name) {
|
||||
return ResolvableProfile.createUnresolved(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 GameProfile(通过 UUID)
|
||||
* 异步获取 GameProfile(通过玩家名)
|
||||
* 直接复用 SkullBlockEntity 的实现
|
||||
*/
|
||||
@Contract("_ -> new")
|
||||
public static @NonNull ResolvableProfile fetchGameProfileByUUID(UUID uuid) {
|
||||
return ResolvableProfile.createUnresolved(uuid);
|
||||
public static CompletableFuture<Optional<GameProfile>> fetchGameProfileByName(String name) {
|
||||
return SkullBlockEntity.fetchGameProfile(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 GameProfile(自动识别类型)
|
||||
* 异步获取 GameProfile(通过 UUID)
|
||||
* 直接复用 SkullBlockEntity 的实现
|
||||
*/
|
||||
public static CompletableFuture<Optional<GameProfile>> fetchGameProfileByUUID(UUID uuid) {
|
||||
return SkullBlockEntity.fetchGameProfile(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步获取 GameProfile(自动识别类型)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> ResolvableProfile fetchGameProfile(T identifier) {
|
||||
public static <T> CompletableFuture<Optional<GameProfile>> fetchGameProfile(T identifier) {
|
||||
if (identifier instanceof UUID uuid) {
|
||||
return fetchGameProfileByUUID(uuid);
|
||||
} else if (identifier instanceof String name) {
|
||||
return fetchGameProfileByName(name);
|
||||
} else if (identifier instanceof GameProfile gameProfile) {
|
||||
return ResolvableProfile.createResolved(gameProfile);
|
||||
}
|
||||
throw new IllegalArgumentException("Identifier type not supported: " + identifier.getClass());
|
||||
return CompletableFuture.completedFuture(Optional.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 ItemStack 获取完整的 ResolvableProfile
|
||||
* 从 ItemStack 异步获取完整的 GameProfile
|
||||
* 需要配合 ResolvableProfile 使用
|
||||
*/
|
||||
public static ResolvableProfile fetchProfileFromItemStack(@NotNull ItemStack stack) {
|
||||
public static CompletableFuture<Optional<GameProfile>> fetchProfileFromItemStack(@NotNull ItemStack stack) {
|
||||
ResolvableProfile resolvable = stack.get(DataComponents.PROFILE);
|
||||
if (resolvable == null) {
|
||||
return ResolvableProfile.Static.EMPTY;
|
||||
return CompletableFuture.completedFuture(Optional.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
|
||||
|
|
@ -80,10 +93,10 @@ public class GameProfileHelper {
|
|||
* @param gameProfile the game profile
|
||||
* @return the resource location
|
||||
*/
|
||||
public static @NotNull Identifier resolveSkinTexture(@NotNull GameProfile gameProfile) {
|
||||
public static @NotNull ResourceLocation resolveSkinTexture(@NotNull GameProfile gameProfile) {
|
||||
return IClientOnly.check(() ->
|
||||
Minecraft.getInstance().getSkinManager()
|
||||
.createLookup(gameProfile, true)).get().body().texturePath();
|
||||
.getInsecureSkin(gameProfile)).texture();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -92,7 +105,7 @@ public class GameProfileHelper {
|
|||
* @param gameProfile the game profile
|
||||
* @return the skin texture
|
||||
*/
|
||||
public static Identifier getSkinTexture(@Nullable GameProfile gameProfile) {
|
||||
public static ResourceLocation getSkinTexture(@Nullable GameProfile gameProfile) {
|
||||
return IClientOnly.check(() -> {
|
||||
if (gameProfile == null) {
|
||||
return Lib39.mrl("textures/entity/player/wide/steve.png");
|
||||
|
|
@ -113,7 +126,7 @@ public class GameProfileHelper {
|
|||
PlayerInfo playerInfo = Objects.requireNonNull(Minecraft.getInstance()
|
||||
.getConnection())
|
||||
.getPlayerInfo(clientPlayer.getUUID());
|
||||
return playerInfo != null && PlayerModelType.SLIM.equals(playerInfo.getSkin().model());
|
||||
return playerInfo != null && "slim".equals(playerInfo.getSkin().model().id());
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
|
@ -127,12 +140,12 @@ public class GameProfileHelper {
|
|||
*/
|
||||
public static @NotNull String getSkinModelName(@NotNull Player player) {
|
||||
return IClientOnly.check(() -> {
|
||||
if (player.level().isClientSide() && player instanceof AbstractClientPlayer) {
|
||||
if (player.level().isClientSide && player instanceof AbstractClientPlayer) {
|
||||
PlayerInfo info = Objects.requireNonNull(Minecraft.getInstance().getConnection())
|
||||
.getPlayerInfo(player.getUUID());
|
||||
return info != null ? info.getSkin().model().name() : PlayerModelType.WIDE.name();
|
||||
return info != null ? info.getSkin().model().id() : "default";
|
||||
}
|
||||
return PlayerModelType.WIDE.name();
|
||||
return "default";
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -149,7 +162,7 @@ public class GameProfileHelper {
|
|||
* @param gameProfile the game profile
|
||||
* @return the skin texture
|
||||
*/
|
||||
public static Identifier getSkinTexture(@Nullable GameProfile gameProfile) {
|
||||
public static ResourceLocation getSkinTexture(@Nullable GameProfile gameProfile) {
|
||||
return ClientOpt.getSkinTexture(gameProfile);
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +173,7 @@ public class GameProfileHelper {
|
|||
* @param gameProfile the game profile
|
||||
* @return the resource location
|
||||
*/
|
||||
public static @NotNull Identifier resolveSkinTexture(@NotNull GameProfile gameProfile) {
|
||||
public static @NotNull ResourceLocation resolveSkinTexture(@NotNull GameProfile gameProfile) {
|
||||
return ClientOpt.resolveSkinTexture(gameProfile);
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +184,7 @@ public class GameProfileHelper {
|
|||
* @return the boolean
|
||||
*/
|
||||
public static boolean hasSlimArms(@NotNull Player player) {
|
||||
if (player.level().isClientSide()) {
|
||||
if (player.level().isClientSide) {
|
||||
return hasSlimArmsClient(player);
|
||||
} else {
|
||||
return hasSlimArmsServer(player);
|
||||
|
|
@ -186,7 +199,7 @@ public class GameProfileHelper {
|
|||
// 服务器端判断
|
||||
private static boolean hasSlimArmsServer(@NotNull Player player) {
|
||||
GameProfile profile = player.getGameProfile();
|
||||
for (Property property : profile.properties().get("textures")) {
|
||||
for (Property property : profile.getProperties().get("textures")) {
|
||||
try {
|
||||
String json = new String(Base64.getDecoder().decode(property.value()));
|
||||
JsonObject obj = JsonParser.parseString(json).getAsJsonObject();
|
||||
|
|
@ -228,7 +241,7 @@ public class GameProfileHelper {
|
|||
}
|
||||
|
||||
// 获取textures属性
|
||||
Collection<Property> textures = profile.properties().get("textures");
|
||||
Collection<Property> textures = profile.getProperties().get("textures");
|
||||
if (textures.isEmpty()) {
|
||||
return false; // 没有皮肤数据,使用默认
|
||||
}
|
||||
|
|
@ -300,7 +313,7 @@ public class GameProfileHelper {
|
|||
return "default";
|
||||
}
|
||||
|
||||
Collection<Property> textures = profile.properties().get("textures");
|
||||
Collection<Property> textures = profile.getProperties().get("textures");
|
||||
if (textures.isEmpty()) {
|
||||
return "default";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,10 +145,7 @@ public class MathUtil {
|
|||
* @return the direction
|
||||
*/
|
||||
public static Direction getDirection(BlockPos from, BlockPos to) {
|
||||
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);
|
||||
return Direction.fromDelta(from.getX() - to.getX(), from.getY() - to.getY(), from.getZ() - to.getZ());
|
||||
}
|
||||
|
||||
private static final Int2DoubleMap FACTORIAL_CACHE = new Int2DoubleOpenHashMap();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.util;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.StringRepresentable;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
|
@ -11,7 +11,6 @@ import top.r3944realms.lib39.Lib39;
|
|||
/**
|
||||
* The type Plant helper.
|
||||
*/
|
||||
//todo: 需添加26.1.2的新的Plant,部分条目可能需要重命名
|
||||
public class PlantHelper {
|
||||
/**
|
||||
* The enum Plant.
|
||||
|
|
@ -269,7 +268,7 @@ public class PlantHelper {
|
|||
* @return the texture rl
|
||||
*/
|
||||
@Contract("_ -> new")
|
||||
public static @NotNull Identifier getTextureRL(@NotNull Plant plant) {
|
||||
public static @NotNull ResourceLocation getTextureRL(@NotNull Plant plant) {
|
||||
return Lib39.mrl("block/" + plant.name);
|
||||
}
|
||||
|
||||
|
|
@ -280,7 +279,7 @@ public class PlantHelper {
|
|||
* @return the directly texture rl
|
||||
*/
|
||||
@Contract("_ -> new")
|
||||
public static @NotNull Identifier getDirectlyTextureRL(@NotNull Plant plant) {
|
||||
public static @NotNull ResourceLocation getDirectlyTextureRL(@NotNull Plant plant) {
|
||||
return Lib39.mrl("textures/block/" + plant.name + ".png");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,18 +13,17 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package top.r3944realms.lib39.util.storage.nbt;
|
||||
package top.r3944realms.lib39.util.nbt;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
|
|
@ -48,33 +47,24 @@ public class NBTReader {
|
|||
public static NBTReader of(@NotNull CompoundTag nbt) {
|
||||
return new NBTReader(nbt);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从CompoundTag创建读取器
|
||||
* String nbt reader.
|
||||
*
|
||||
* @param nbt the nbt opt
|
||||
* @param key the key
|
||||
* @param setter the setter
|
||||
* @return the nbt reader
|
||||
*/
|
||||
@NotNull
|
||||
public static NBTReader ofOpt(@NotNull Optional<CompoundTag> nbt) {
|
||||
return new NBTReader(nbt.orElse(new CompoundTag()));
|
||||
}
|
||||
@Contract(pure = true)
|
||||
private static boolean checkOpt(@NonNull Optional<?> nbt) {
|
||||
return nbt.isPresent();
|
||||
}
|
||||
@Contract(pure = true)
|
||||
private static boolean checkOpt(Optional<?> @NonNull ... nbts) {
|
||||
for (Optional<?> nbt : nbts) {
|
||||
if (nbt.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
// 基本读取方法 - 直接赋值给成员变量
|
||||
public NBTReader string(String key, Consumer<String> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
setter.accept(nbt.getString(key));
|
||||
}
|
||||
return true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* String nbt reader with default value.
|
||||
* String nbt reader.
|
||||
*
|
||||
* @param key the key
|
||||
* @param setter the setter
|
||||
|
|
@ -82,14 +72,7 @@ public class NBTReader {
|
|||
* @return the nbt reader
|
||||
*/
|
||||
public NBTReader string(String key, @NotNull Consumer<String> setter, String defaultValue) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<String> value = nbt.getString(key);
|
||||
if (checkOpt(value)) {
|
||||
setter.accept(value.get());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
setter.accept(defaultValue);
|
||||
setter.accept(nbt.contains(key) ? nbt.getString(key) : defaultValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -102,14 +85,13 @@ public class NBTReader {
|
|||
*/
|
||||
public NBTReader byteValue(String key, Consumer<Byte> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<Byte> value = nbt.getByte(key);
|
||||
if (checkOpt(value)) setter.accept(value.get());
|
||||
setter.accept(nbt.getByte(key));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Byte value nbt reader with default value.
|
||||
* Byte value nbt reader.
|
||||
*
|
||||
* @param key the key
|
||||
* @param setter the setter
|
||||
|
|
@ -117,14 +99,7 @@ public class NBTReader {
|
|||
* @return the nbt reader
|
||||
*/
|
||||
public NBTReader byteValue(String key, @NotNull Consumer<Byte> setter, byte defaultValue) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<Byte> value = nbt.getByte(key);
|
||||
if (checkOpt(value)) {
|
||||
setter.accept(value.get());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
setter.accept(defaultValue);
|
||||
setter.accept(nbt.contains(key) ? nbt.getByte(key) : defaultValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -137,14 +112,13 @@ public class NBTReader {
|
|||
*/
|
||||
public NBTReader shortValue(String key, Consumer<Short> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<Short> value = nbt.getShort(key);
|
||||
if (checkOpt(value)) setter.accept(value.get());
|
||||
setter.accept(nbt.getShort(key));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Short value nbt reader with default value.
|
||||
* Short value nbt reader.
|
||||
*
|
||||
* @param key the key
|
||||
* @param setter the setter
|
||||
|
|
@ -152,14 +126,7 @@ public class NBTReader {
|
|||
* @return the nbt reader
|
||||
*/
|
||||
public NBTReader shortValue(String key, @NotNull Consumer<Short> setter, short defaultValue) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<Short> value = nbt.getShort(key);
|
||||
if (checkOpt(value)) {
|
||||
setter.accept(value.get());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
setter.accept(defaultValue);
|
||||
setter.accept(nbt.contains(key) ? nbt.getShort(key) : defaultValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -172,14 +139,13 @@ public class NBTReader {
|
|||
*/
|
||||
public NBTReader intValue(String key, Consumer<Integer> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<Integer> value = nbt.getInt(key);
|
||||
if (checkOpt(value)) setter.accept(value.get());
|
||||
setter.accept(nbt.getInt(key));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Int value nbt reader with default value.
|
||||
* Int value nbt reader.
|
||||
*
|
||||
* @param key the key
|
||||
* @param setter the setter
|
||||
|
|
@ -187,14 +153,7 @@ public class NBTReader {
|
|||
* @return the nbt reader
|
||||
*/
|
||||
public NBTReader intValue(String key, @NotNull Consumer<Integer> setter, int defaultValue) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<Integer> value = nbt.getInt(key);
|
||||
if (checkOpt(value)) {
|
||||
setter.accept(value.get());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
setter.accept(defaultValue);
|
||||
setter.accept(nbt.contains(key) ? nbt.getInt(key) : defaultValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -207,14 +166,13 @@ public class NBTReader {
|
|||
*/
|
||||
public NBTReader longValue(String key, Consumer<Long> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<Long> value = nbt.getLong(key);
|
||||
if (checkOpt(value)) setter.accept(value.get());
|
||||
setter.accept(nbt.getLong(key));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Long value nbt reader with default value.
|
||||
* Long value nbt reader.
|
||||
*
|
||||
* @param key the key
|
||||
* @param setter the setter
|
||||
|
|
@ -222,14 +180,7 @@ public class NBTReader {
|
|||
* @return the nbt reader
|
||||
*/
|
||||
public NBTReader longValue(String key, @NotNull Consumer<Long> setter, long defaultValue) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<Long> value = nbt.getLong(key);
|
||||
if (checkOpt(value)) {
|
||||
setter.accept(value.get());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
setter.accept(defaultValue);
|
||||
setter.accept(nbt.contains(key) ? nbt.getLong(key) : defaultValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -242,14 +193,13 @@ public class NBTReader {
|
|||
*/
|
||||
public NBTReader floatValue(String key, Consumer<Float> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<Float> value = nbt.getFloat(key);
|
||||
if (checkOpt(value)) setter.accept(value.get());
|
||||
setter.accept(nbt.getFloat(key));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Float value nbt reader with default value.
|
||||
* Float value nbt reader.
|
||||
*
|
||||
* @param key the key
|
||||
* @param setter the setter
|
||||
|
|
@ -257,14 +207,7 @@ public class NBTReader {
|
|||
* @return the nbt reader
|
||||
*/
|
||||
public NBTReader floatValue(String key, @NotNull Consumer<Float> setter, float defaultValue) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<Float> value = nbt.getFloat(key);
|
||||
if (checkOpt(value)) {
|
||||
setter.accept(value.get());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
setter.accept(defaultValue);
|
||||
setter.accept(nbt.contains(key) ? nbt.getFloat(key) : defaultValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -277,14 +220,13 @@ public class NBTReader {
|
|||
*/
|
||||
public NBTReader doubleValue(String key, Consumer<Double> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<Double> value = nbt.getDouble(key);
|
||||
if (checkOpt(value)) setter.accept(value.get());
|
||||
setter.accept(nbt.getDouble(key));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Double value nbt reader with default value.
|
||||
* Double value nbt reader.
|
||||
*
|
||||
* @param key the key
|
||||
* @param setter the setter
|
||||
|
|
@ -292,14 +234,7 @@ public class NBTReader {
|
|||
* @return the nbt reader
|
||||
*/
|
||||
public NBTReader doubleValue(String key, @NotNull Consumer<Double> setter, double defaultValue) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<Double> value = nbt.getDouble(key);
|
||||
if (checkOpt(value)) {
|
||||
setter.accept(value.get());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
setter.accept(defaultValue);
|
||||
setter.accept(nbt.contains(key) ? nbt.getDouble(key) : defaultValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -312,14 +247,13 @@ public class NBTReader {
|
|||
*/
|
||||
public NBTReader booleanValue(String key, Consumer<Boolean> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<Boolean> value = nbt.getBoolean(key);
|
||||
if (checkOpt(value)) setter.accept(value.get());
|
||||
setter.accept(nbt.getBoolean(key));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Boolean value nbt reader with default value.
|
||||
* Boolean value nbt reader.
|
||||
*
|
||||
* @param key the key
|
||||
* @param setter the setter
|
||||
|
|
@ -327,14 +261,7 @@ public class NBTReader {
|
|||
* @return the nbt reader
|
||||
*/
|
||||
public NBTReader booleanValue(String key, @NotNull Consumer<Boolean> setter, boolean defaultValue) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<Boolean> value = nbt.getBoolean(key);
|
||||
if (checkOpt(value)) {
|
||||
setter.accept(value.get());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
setter.accept(defaultValue);
|
||||
setter.accept(nbt.contains(key) ? nbt.getBoolean(key) : defaultValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -345,10 +272,10 @@ public class NBTReader {
|
|||
* @param setter the setter
|
||||
* @return the nbt reader
|
||||
*/
|
||||
// 数组类型
|
||||
public NBTReader byteArray(String key, Consumer<byte[]> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<byte[]> value = nbt.getByteArray(key);
|
||||
if (checkOpt(value)) setter.accept(value.get());
|
||||
setter.accept(nbt.getByteArray(key));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
@ -362,8 +289,7 @@ public class NBTReader {
|
|||
*/
|
||||
public NBTReader intArray(String key, Consumer<int[]> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<int[]> value = nbt.getIntArray(key);
|
||||
if (checkOpt(value)) setter.accept(value.get());
|
||||
setter.accept(nbt.getIntArray(key));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
@ -377,12 +303,39 @@ public class NBTReader {
|
|||
*/
|
||||
public NBTReader longArray(String key, Consumer<long[]> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<long[]> value = nbt.getLongArray(key);
|
||||
if (checkOpt(value)) setter.accept(value.get());
|
||||
setter.accept(nbt.getLongArray(key));
|
||||
}
|
||||
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.
|
||||
*
|
||||
|
|
@ -390,16 +343,16 @@ public class NBTReader {
|
|||
* @param setter the setter
|
||||
* @return the nbt reader
|
||||
*/
|
||||
// CompoundTag
|
||||
public NBTReader compound(String key, Consumer<CompoundTag> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<CompoundTag> value = nbt.getCompound(key);
|
||||
if (checkOpt(value)) setter.accept(value.get());
|
||||
setter.accept(nbt.getCompound(key));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compound nbt reader with default value.
|
||||
* Compound nbt reader.
|
||||
*
|
||||
* @param key the key
|
||||
* @param setter the setter
|
||||
|
|
@ -407,14 +360,7 @@ public class NBTReader {
|
|||
* @return the nbt reader
|
||||
*/
|
||||
public NBTReader compound(String key, @NotNull Consumer<CompoundTag> setter, CompoundTag defaultValue) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<CompoundTag> value = nbt.getCompound(key);
|
||||
if (checkOpt(value)) {
|
||||
setter.accept(value.get());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
setter.accept(defaultValue);
|
||||
setter.accept(nbt.contains(key) ? nbt.getCompound(key) : defaultValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -422,45 +368,135 @@ public class NBTReader {
|
|||
* List nbt reader.
|
||||
*
|
||||
* @param key the key
|
||||
* @param type the type
|
||||
* @param setter the setter
|
||||
* @return the nbt reader
|
||||
*/
|
||||
public NBTReader list(String key, Consumer<ListTag> setter) {
|
||||
// ListTag
|
||||
public NBTReader list(String key, int type, Consumer<ListTag> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<ListTag> value = nbt.getList(key);
|
||||
if (checkOpt(value)) setter.accept(value.get());
|
||||
setter.accept(nbt.getList(key, type));
|
||||
}
|
||||
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();
|
||||
/**
|
||||
* 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;
|
||||
} 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();
|
||||
/**
|
||||
* 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;
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
setter.accept(defaultValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read GameProfile from CompoundTag.
|
||||
*
|
||||
* @param tag the tag
|
||||
* @return the game profile, or null if invalid
|
||||
*/
|
||||
@Nullable
|
||||
private static GameProfile readGameProfileFromTag(@NotNull CompoundTag tag) {
|
||||
String name = null;
|
||||
UUID uuid = null;
|
||||
|
||||
// 支持 "Name" 或 "name"
|
||||
if (tag.contains("Name", CompoundTag.TAG_STRING)) {
|
||||
name = tag.getString("Name");
|
||||
} else if (tag.contains("name", CompoundTag.TAG_STRING)) {
|
||||
name = tag.getString("name");
|
||||
}
|
||||
|
||||
// 支持 "Id" 或 "id"
|
||||
if (tag.hasUUID("Id")) {
|
||||
uuid = tag.getUUID("Id");
|
||||
} else if (tag.hasUUID("id")) {
|
||||
uuid = tag.getUUID("id");
|
||||
}
|
||||
|
||||
try {
|
||||
GameProfile profile = new GameProfile(uuid, name);
|
||||
|
||||
// 支持 "Properties" 或 "properties",支持 COMPOUND 或 LIST 格式
|
||||
String propertiesKey = tag.contains("Properties", CompoundTag.TAG_COMPOUND) ? "Properties"
|
||||
: (tag.contains("properties", CompoundTag.TAG_COMPOUND) ? "properties" : null);
|
||||
|
||||
// 如果没有 COMPOUND,尝试 LIST 格式
|
||||
if (propertiesKey == null) {
|
||||
String listKey = tag.contains("Properties", CompoundTag.TAG_LIST) ? "Properties"
|
||||
: (tag.contains("properties", CompoundTag.TAG_LIST) ? "properties" : null);
|
||||
if (listKey != null) {
|
||||
ListTag propertiesList = tag.getList(listKey, CompoundTag.TAG_COMPOUND);
|
||||
for (int i = 0; i < propertiesList.size(); i++) {
|
||||
CompoundTag propTag = propertiesList.getCompound(i);
|
||||
String propName = propTag.getString("name");
|
||||
String value = propTag.getString("value");
|
||||
String signature = propTag.contains("signature") ? propTag.getString("signature") : null;
|
||||
|
||||
if (signature != null) {
|
||||
profile.getProperties().put(propName, new Property(propName, value, signature));
|
||||
} else {
|
||||
profile.getProperties().put(propName, new Property(propName, value));
|
||||
}
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
|
||||
// COMPOUND 格式处理
|
||||
if (propertiesKey != null && tag.contains(propertiesKey, CompoundTag.TAG_COMPOUND)) {
|
||||
CompoundTag propertiesTag = tag.getCompound(propertiesKey);
|
||||
for (String key : propertiesTag.getAllKeys()) {
|
||||
ListTag listTag = propertiesTag.getList(key, CompoundTag.TAG_COMPOUND);
|
||||
for (int i = 0; i < listTag.size(); i++) {
|
||||
CompoundTag propTag = listTag.getCompound(i);
|
||||
String value = propTag.getString("Value");
|
||||
String signature = propTag.contains("Signature") ? propTag.getString("Signature") : null;
|
||||
if (signature != null) {
|
||||
profile.getProperties().put(key, new Property(key, value, signature));
|
||||
} else {
|
||||
profile.getProperties().put(key, new Property(key, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return profile;
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vec 3 nbt reader.
|
||||
*
|
||||
|
|
@ -468,31 +504,23 @@ public class NBTReader {
|
|||
* @param setter the setter
|
||||
* @return the nbt reader
|
||||
*/
|
||||
// Vec3支持
|
||||
public NBTReader vec3(String key, Consumer<Vec3> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<CompoundTag> vecTag = nbt.getCompound(key);
|
||||
if (checkOpt(vecTag)) {
|
||||
CompoundTag vec = vecTag.get();
|
||||
if (vec.contains("X") && vec.contains("Y") && vec.contains("Z")) {
|
||||
Optional<Double> x = vec.getDouble("X");
|
||||
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);
|
||||
}
|
||||
}
|
||||
CompoundTag vecTag = nbt.getCompound(key);
|
||||
if (vecTag.contains("X") && vecTag.contains("Y") && vecTag.contains("Z")) {
|
||||
setter.accept(new Vec3(
|
||||
vecTag.getDouble("X"),
|
||||
vecTag.getDouble("Y"),
|
||||
vecTag.getDouble("Z")
|
||||
));
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vec 3 nbt reader with default value.
|
||||
* Vec 3 nbt reader.
|
||||
*
|
||||
* @param key the key
|
||||
* @param setter the setter
|
||||
|
|
@ -501,23 +529,14 @@ public class NBTReader {
|
|||
*/
|
||||
public NBTReader vec3(String key, Consumer<Vec3> setter, Vec3 defaultValue) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<CompoundTag> vecTag = nbt.getCompound(key);
|
||||
if (checkOpt(vecTag)) {
|
||||
CompoundTag vec = vecTag.get();
|
||||
if (vec.contains("X") && vec.contains("Y") && vec.contains("Z")) {
|
||||
Optional<Double> x = vec.getDouble("X");
|
||||
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;
|
||||
}
|
||||
}
|
||||
CompoundTag vecTag = nbt.getCompound(key);
|
||||
if (vecTag.contains("X") && vecTag.contains("Y") && vecTag.contains("Z")) {
|
||||
setter.accept(new Vec3(
|
||||
vecTag.getDouble("X"),
|
||||
vecTag.getDouble("Y"),
|
||||
vecTag.getDouble("Z")
|
||||
));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
setter.accept(defaultValue);
|
||||
|
|
@ -533,24 +552,21 @@ public class NBTReader {
|
|||
* @param setter the setter
|
||||
* @return the nbt reader
|
||||
*/
|
||||
// 枚举支持
|
||||
public <T extends Enum<T>> NBTReader enumValue(String key, Class<T> enumClass, Consumer<T> setter) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<String> value = nbt.getString(key);
|
||||
if(checkOpt(value)) {
|
||||
try {
|
||||
T enumValue = Enum.valueOf(enumClass, value.get().toUpperCase());
|
||||
setter.accept(enumValue);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
// 保持setter的当前值
|
||||
}
|
||||
String value = nbt.getString(key);
|
||||
try {
|
||||
setter.accept(Enum.valueOf(enumClass, value.toUpperCase()));
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
// 保持setter的当前值
|
||||
}
|
||||
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum value nbt reader with default value.
|
||||
* Enum value nbt reader.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param key the key
|
||||
|
|
@ -561,21 +577,18 @@ public class NBTReader {
|
|||
*/
|
||||
public <T extends Enum<T>> NBTReader enumValue(String key, Class<T> enumClass, Consumer<T> setter, T defaultValue) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<String> value = nbt.getString(key);
|
||||
if (checkOpt(value)) {
|
||||
try {
|
||||
T enumValue = Enum.valueOf(enumClass, value.get().toUpperCase());
|
||||
setter.accept(enumValue);
|
||||
return this;
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
// 保持setter的当前值
|
||||
}
|
||||
String value = nbt.getString(key);
|
||||
try {
|
||||
setter.accept(Enum.valueOf(enumClass, value.toUpperCase()));
|
||||
return this;
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
setter.accept(defaultValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Nested nbt reader.
|
||||
*
|
||||
|
|
@ -583,18 +596,16 @@ public class NBTReader {
|
|||
* @param consumer the consumer
|
||||
* @return the nbt reader
|
||||
*/
|
||||
// 嵌套读取支持
|
||||
public NBTReader nested(String key, Consumer<NBTReader> consumer) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<CompoundTag> compound = nbt.getCompound(key);
|
||||
if (checkOpt(compound)) {
|
||||
consumer.accept(new NBTReader(compound.get()));
|
||||
}
|
||||
consumer.accept(new NBTReader(nbt.getCompound(key)));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nested nbt reader with orElse.
|
||||
* Nested nbt reader.
|
||||
*
|
||||
* @param key the key
|
||||
* @param consumer the consumer
|
||||
|
|
@ -603,10 +614,7 @@ public class NBTReader {
|
|||
*/
|
||||
public NBTReader nested(String key, Consumer<NBTReader> consumer, Runnable orElse) {
|
||||
if (nbt.contains(key)) {
|
||||
Optional<CompoundTag> compound = nbt.getCompound(key);
|
||||
if (checkOpt(compound)) {
|
||||
consumer.accept(new NBTReader(compound.get()));
|
||||
}
|
||||
consumer.accept(new NBTReader(nbt.getCompound(key)));
|
||||
} else {
|
||||
orElse.run();
|
||||
}
|
||||
|
|
@ -620,6 +628,7 @@ public class NBTReader {
|
|||
* @param action the action
|
||||
* @return the nbt reader
|
||||
*/
|
||||
// 条件读取
|
||||
public NBTReader ifPresent(String key, Runnable action) {
|
||||
if (nbt.contains(key)) {
|
||||
action.run();
|
||||
|
|
@ -646,6 +655,7 @@ public class NBTReader {
|
|||
*
|
||||
* @return the raw
|
||||
*/
|
||||
// 获取原始NBT
|
||||
@NotNull
|
||||
public CompoundTag getRaw() {
|
||||
return nbt;
|
||||
|
|
@ -657,20 +667,14 @@ public class NBTReader {
|
|||
* @param nbt the nbt
|
||||
* @return the vec 3
|
||||
*/
|
||||
// 便捷的静态方法(保持原有功能)
|
||||
@NotNull
|
||||
public static Vec3 readVec3(@NotNull CompoundTag nbt) {
|
||||
if (nbt.contains("X") && nbt.contains("Y") && nbt.contains("Z")) {
|
||||
Optional<Double> x = nbt.getDouble("X");
|
||||
Optional<Double> y = nbt.getDouble("Y");
|
||||
Optional<Double> 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."
|
||||
return new Vec3(
|
||||
nbt.getDouble("X"),
|
||||
nbt.getDouble("Y"),
|
||||
nbt.getDouble("Z")
|
||||
);
|
||||
} else {
|
||||
throw new IllegalArgumentException("NBT is missing X, Y, or Z value for Vec3");
|
||||
|
|
@ -686,16 +690,11 @@ public class NBTReader {
|
|||
@Nullable
|
||||
public static Vec3 readVec3Safe(@NotNull CompoundTag nbt) {
|
||||
if (nbt.contains("X") && nbt.contains("Y") && nbt.contains("Z")) {
|
||||
Optional<Double> x = nbt.getDouble("X");
|
||||
Optional<Double> y = nbt.getDouble("Y");
|
||||
Optional<Double> z = nbt.getDouble("Z");
|
||||
if (checkOpt(x, y, z)) {
|
||||
return new Vec3(
|
||||
x.get(),
|
||||
y.get(),
|
||||
z.get()
|
||||
);
|
||||
}
|
||||
return new Vec3(
|
||||
nbt.getDouble("X"),
|
||||
nbt.getDouble("Y"),
|
||||
nbt.getDouble("Z")
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -1,14 +1,15 @@
|
|||
package top.r3944realms.lib39.util.storage.nbt;
|
||||
package top.r3944realms.lib39.util.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.world.item.component.ResolvableProfile;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
|
@ -163,17 +164,6 @@ public class NBTWriter {
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -407,15 +397,47 @@ public class NBTWriter {
|
|||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uuid nbt writer.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
* @return the nbt writer
|
||||
*/
|
||||
// UUID支持
|
||||
public NBTWriter uuid(String key, UUID value) {
|
||||
if (value != null) {
|
||||
root.putUUID(key, value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uuid nbt writer.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
* @param defaultValue the default value
|
||||
* @return the nbt writer
|
||||
*/
|
||||
public NBTWriter uuid(String key, UUID value, UUID defaultValue) {
|
||||
if (value != null) {
|
||||
root.putUUID(key, value);
|
||||
} else if (defaultValue != null) {
|
||||
root.putUUID(key, defaultValue);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compound nbt writer.
|
||||
* 嵌套CompoundTag
|
||||
*
|
||||
* @param key the key
|
||||
* @param consumer the consumer
|
||||
* @return the nbt writer
|
||||
*/
|
||||
|
||||
// 嵌套CompoundTag
|
||||
public NBTWriter compound(String key, Consumer<NBTWriter> consumer) {
|
||||
if (consumer != null) {
|
||||
NBTWriter nestedBuilder = new NBTWriter();
|
||||
|
|
@ -474,12 +496,12 @@ public class NBTWriter {
|
|||
|
||||
/**
|
||||
* List nbt writer.
|
||||
* ListTag支持
|
||||
*
|
||||
* @param key the key
|
||||
* @param consumer the consumer
|
||||
* @return the nbt writer
|
||||
*/
|
||||
// ListTag支持
|
||||
public NBTWriter list(String key, Consumer<ListNBTBuilder> consumer) {
|
||||
if (consumer != null) {
|
||||
ListNBTBuilder listBuilder = new ListNBTBuilder();
|
||||
|
|
@ -550,6 +572,60 @@ public class NBTWriter {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Game profile nbt writer.
|
||||
*
|
||||
* @param key the key
|
||||
* @param profile the profile
|
||||
* @return the nbt writer
|
||||
*/
|
||||
public NBTWriter gameProfile(String key, @NotNull GameProfile profile) {
|
||||
root.put(key, writeGameProfile(profile));
|
||||
return this;
|
||||
}
|
||||
|
||||
private CompoundTag writeGameProfile(@NotNull GameProfile profile) {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
if (!StringUtil.isNullOrEmpty(profile.getName())) {
|
||||
tag.putString("Name", profile.getName());
|
||||
}
|
||||
if (profile.getId() != null) {
|
||||
tag.putUUID("Id", profile.getId());
|
||||
}
|
||||
if (!profile.getProperties().isEmpty()) {
|
||||
CompoundTag compoundTag = new CompoundTag();
|
||||
for(String keySet : profile.getProperties().keySet()) {
|
||||
ListTag propListTag = new ListTag();
|
||||
for(Property property : profile.getProperties().get(keySet)) {
|
||||
CompoundTag propTag = new CompoundTag();
|
||||
propTag.putString("Value", property.value());
|
||||
if (property.hasSignature()) {
|
||||
propTag.putString("Signature", property.signature());
|
||||
}
|
||||
propListTag.add(propTag);
|
||||
}
|
||||
compoundTag.put(keySet, propListTag);
|
||||
}
|
||||
tag.put("Properties", compoundTag);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* GameProfile if nbt writer.
|
||||
*
|
||||
* @param key the key
|
||||
* @param condition the condition
|
||||
* @param value the value
|
||||
* @return the nbt writer
|
||||
*/
|
||||
public NBTWriter gameProfileIf(String key, boolean condition, Supplier<GameProfile> value) {
|
||||
if (condition && value != null) {
|
||||
root.put(key, writeGameProfile(value.get()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* String if nbt writer.
|
||||
*
|
||||
|
|
@ -595,6 +671,21 @@ public class NBTWriter {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uuid value if nbt writer.
|
||||
*
|
||||
* @param key the key
|
||||
* @param condition the condition
|
||||
* @param value the value
|
||||
* @return the nbt writer
|
||||
*/
|
||||
public NBTWriter uuidValueIf(String key, boolean condition, Supplier<UUID> value) {
|
||||
if (condition && value != null) {
|
||||
root.putUUID(key, value.get());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Boolean value if nbt writer.
|
||||
*
|
||||
|
|
@ -1071,7 +1162,7 @@ public class NBTWriter {
|
|||
* @return the all keys
|
||||
*/
|
||||
public java.util.Set<String> getAllKeys() {
|
||||
return root.keySet();
|
||||
return root.getAllKeys();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package top.r3944realms.lib39.util.resolve;
|
||||
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -141,14 +141,14 @@ public abstract class EntityListResolve {
|
|||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isEntityInList(EntityType<?> type) {
|
||||
String entityId = type.builtInRegistryHolder().key().identifier().toString();
|
||||
String entityId = type.builtInRegistryHolder().key().location().toString();
|
||||
String modId = entityId.split(":")[0];
|
||||
for (String rs : result.entityList) {
|
||||
if (rs.equals(entityId)) return true;
|
||||
}
|
||||
for(String rs : result.tagList) {
|
||||
String body = rs.substring(1);
|
||||
Identifier tagId = Lib39.rl(body);
|
||||
ResourceLocation tagId = Lib39.rl(body);
|
||||
TagKey<EntityType<?>> tag = TagKey.create(Registries.ENTITY_TYPE, tagId);
|
||||
if (type.builtInRegistryHolder().is(tag)) return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package top.r3944realms.lib39.util.resolve;
|
||||
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -153,7 +153,7 @@ public abstract class EntityMapResolve<T> {
|
|||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private EntityMatchResult<T> findEntityMatch(EntityType<?> type) {
|
||||
String entityId = type.builtInRegistryHolder().key().identifier().toString();
|
||||
String entityId = type.builtInRegistryHolder().key().location().toString();
|
||||
String modId = entityId.split(":")[0];
|
||||
|
||||
// 检查实体ID匹配
|
||||
|
|
@ -166,7 +166,7 @@ public abstract class EntityMapResolve<T> {
|
|||
// 检查标签匹配
|
||||
for (String rs : result.tagMap.keySet()) {
|
||||
String body = rs.startsWith("#") ? rs.substring(1) : rs;
|
||||
Identifier tagId = Lib39.rl(body);
|
||||
ResourceLocation tagId = Lib39.rl(body);
|
||||
TagKey<EntityType<?>> tag = TagKey.create(Registries.ENTITY_TYPE, tagId);
|
||||
if (type.builtInRegistryHolder().is(tag)) {
|
||||
return new EntityMatchResult<>(EntityResolveResult.Type.TAG, rs, result.tagMap.get(rs));
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public class RidingApplier {
|
|||
if (RidingValidator.wouldCreateCycle(entity, vehicle)) {
|
||||
throw new RidingCycleException(entityId, vehicleId);
|
||||
}
|
||||
boolean success = entity.startRiding(vehicle, true, true);
|
||||
boolean success = entity.startRiding(vehicle, true);
|
||||
if (!success) {
|
||||
Lib39.LOGGER.error("Failed to mount entity {} to vehicle {}", entityId, vehicleId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,557 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,648 +0,0 @@
|
|||
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,11 +16,12 @@ import net.minecraft.util.Mth;
|
|||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.npc.villager.VillagerDataHolder;
|
||||
import net.minecraft.world.entity.npc.villager.VillagerTrades;
|
||||
import net.minecraft.world.entity.npc.villager.VillagerType;
|
||||
import net.minecraft.world.entity.npc.VillagerDataHolder;
|
||||
import net.minecraft.world.entity.npc.VillagerTrades;
|
||||
import net.minecraft.world.entity.npc.VillagerType;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.item.alchemy.Potion;
|
||||
import net.minecraft.world.item.alchemy.PotionBrewing;
|
||||
import net.minecraft.world.item.alchemy.PotionContents;
|
||||
import net.minecraft.world.item.component.DyedItemColor;
|
||||
import net.minecraft.world.item.component.SuspiciousStewEffects;
|
||||
|
|
@ -41,6 +42,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
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.CommandSourceStack;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import top.r3944realms.lib39.core.command.ICommandHelpManager;
|
||||
import top.r3944realms.lib39.core.command.model.CommandNode;
|
||||
import top.r3944realms.lib39.core.command.model.CommandPath;
|
||||
|
|
@ -50,7 +50,7 @@ public interface RegisterCommandHelpCallback {
|
|||
*
|
||||
* @return the id
|
||||
*/
|
||||
Identifier getID();
|
||||
ResourceLocation getID();
|
||||
|
||||
/**
|
||||
* Add child.
|
||||
|
|
@ -103,7 +103,7 @@ public interface RegisterCommandHelpCallback {
|
|||
*/
|
||||
record CommandHelpRegistrar(LiteralArgumentBuilder<CommandSourceStack> builder, ICommandHelpManager helpManager, CommandBuildContext context) implements Registrar {
|
||||
@Override
|
||||
public Identifier getID() {
|
||||
public ResourceLocation 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.EventFactory;
|
||||
import net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.core.sync.ISyncData;
|
||||
|
|
@ -62,7 +62,7 @@ public interface SyncManagerRegisterCallback {
|
|||
* @param dataClass the data class
|
||||
*/
|
||||
<T extends ISyncData<?>> void register(
|
||||
Identifier id,
|
||||
ResourceLocation id,
|
||||
ISyncManager<Entity, T> syncManager,
|
||||
Class<T> dataClass
|
||||
);
|
||||
|
|
@ -73,7 +73,7 @@ public interface SyncManagerRegisterCallback {
|
|||
* @param id the id
|
||||
* @param entityClasses the entity classes
|
||||
*/
|
||||
void allowEntityClass(Identifier id, Class<?>... entityClasses);
|
||||
void allowEntityClass(ResourceLocation id, Class<?>... entityClasses);
|
||||
|
||||
/**
|
||||
* 移除允许的实体类
|
||||
|
|
@ -81,7 +81,7 @@ public interface SyncManagerRegisterCallback {
|
|||
* @param id the id
|
||||
* @param entityClasses the entity classes
|
||||
*/
|
||||
void disallowEntityClass(Identifier id, Class<?>... entityClasses);
|
||||
void disallowEntityClass(ResourceLocation id, Class<?>... entityClasses);
|
||||
|
||||
/**
|
||||
* 绑定 EntityApiLookup(用于分离注册的情况)
|
||||
|
|
@ -91,7 +91,7 @@ public interface SyncManagerRegisterCallback {
|
|||
* @param apiLookup the EntityApiLookup
|
||||
*/
|
||||
<T extends ISyncData<?>> void bindApiLookup(
|
||||
Identifier id,
|
||||
ResourceLocation id,
|
||||
net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup<T, Void> apiLookup
|
||||
);
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ public interface SyncManagerRegisterCallback {
|
|||
*
|
||||
* @param id the id
|
||||
*/
|
||||
void unbindApiLookup(Identifier id);
|
||||
void unbindApiLookup(ResourceLocation id);
|
||||
|
||||
/**
|
||||
* 完整的类型安全注册
|
||||
|
|
@ -112,7 +112,7 @@ public interface SyncManagerRegisterCallback {
|
|||
* @param allowedEntityClasses the allowed entity classes
|
||||
*/
|
||||
default <T extends ISyncData<?>> void registerComplete(
|
||||
Identifier id,
|
||||
ResourceLocation id,
|
||||
ISyncManager<Entity, T> syncManager,
|
||||
Class<T> dataClass,
|
||||
Class<?>... allowedEntityClasses
|
||||
|
|
@ -132,7 +132,7 @@ public interface SyncManagerRegisterCallback {
|
|||
|
||||
@Override
|
||||
public <T extends ISyncData<?>> void register(
|
||||
@NotNull Identifier id,
|
||||
@NotNull ResourceLocation id,
|
||||
@NotNull ISyncManager<Entity, T> syncManager,
|
||||
@NotNull Class<T> dataClass
|
||||
) {
|
||||
|
|
@ -140,25 +140,25 @@ public interface SyncManagerRegisterCallback {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void allowEntityClass(@NotNull Identifier id, @NotNull Class<?>... entityClasses) {
|
||||
public void allowEntityClass(@NotNull ResourceLocation id, @NotNull Class<?>... entityClasses) {
|
||||
manager.allowEntityClass(id, entityClasses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disallowEntityClass(@NotNull Identifier id, @NotNull Class<?>... entityClasses) {
|
||||
public void disallowEntityClass(@NotNull ResourceLocation id, @NotNull Class<?>... entityClasses) {
|
||||
manager.disallowEntityClass(id, entityClasses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends ISyncData<?>> void bindApiLookup(
|
||||
@NotNull Identifier id,
|
||||
@NotNull ResourceLocation id,
|
||||
@NotNull EntityApiLookup<T, Void> apiLookup
|
||||
) {
|
||||
manager.bindApiLookup(id, apiLookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbindApiLookup(@NotNull Identifier id) {
|
||||
public void unbindApiLookup(@NotNull ResourceLocation id) {
|
||||
manager.unbindApiLookup(id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.base.compat.jade;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import snownee.jade.api.IWailaClientRegistration;
|
||||
import snownee.jade.api.IWailaPlugin;
|
||||
|
|
@ -18,7 +18,7 @@ public class FabricJadePlugin implements IWailaPlugin {
|
|||
/**
|
||||
* The constant UID.
|
||||
*/
|
||||
public static final Identifier UID = Lib39.rl("lib39");
|
||||
public static final ResourceLocation UID = Lib39.rl("lib39");
|
||||
|
||||
@Override
|
||||
public void registerClient(@NotNull IWailaClientRegistration registration) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package top.r3944realms.lib39.base.compat.jade.provider;
|
|||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import snownee.jade.api.BlockAccessor;
|
||||
import snownee.jade.api.IBlockComponentProvider;
|
||||
|
|
@ -16,7 +16,7 @@ import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
|
|||
*/
|
||||
public class FabricDollComponentProvider implements IBlockComponentProvider {
|
||||
@Override
|
||||
public Identifier getUid() {
|
||||
public ResourceLocation getUid() {
|
||||
return FabricJadePlugin.UID;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import net.minecraft.client.multiplayer.ClientLevel;
|
|||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.Services;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
|
@ -122,8 +122,8 @@ public class FabricCommonEventHandler {
|
|||
public static void onServerTick(MinecraftServer server) {
|
||||
if (syncData2Manager == null) return;
|
||||
if (server.getTickCount() % 10 == 0)
|
||||
syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
|
||||
syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
|
||||
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
|
||||
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -135,7 +135,7 @@ public class FabricCommonEventHandler {
|
|||
public static void onEntityJoinWorld(@NotNull Entity entity, ServerLevel level) {
|
||||
if (entity.level().isClientSide) return;
|
||||
|
||||
for (Identifier id : syncData2Manager.getRegisteredKeys()) {
|
||||
for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
|
||||
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
|
||||
syncData2Manager.trackEntityForManager(entity, id);
|
||||
}
|
||||
|
|
@ -151,7 +151,7 @@ public class FabricCommonEventHandler {
|
|||
public static void onEntityLeaveWorld(@NotNull Entity entity, ServerLevel level) {
|
||||
if (entity.level().isClientSide) return;
|
||||
|
||||
for (Identifier id : syncData2Manager.getRegisteredKeys()) {
|
||||
for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
|
||||
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
|
||||
syncData2Manager.untrackEntityForManager(entity, id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import net.minecraft.network.FriendlyByteBuf;
|
|||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -22,11 +22,11 @@ import java.util.Optional;
|
|||
/**
|
||||
* The type Sync nbt lookup data entity s 2 c payload.
|
||||
*/
|
||||
public record SyncNBTLookupDataEntityS2CPayload(int entityId, Identifier id, CompoundTag data) implements CustomPacketPayload {
|
||||
public record SyncNBTLookupDataEntityS2CPayload(int entityId, ResourceLocation id, CompoundTag data) implements CustomPacketPayload {
|
||||
/**
|
||||
* The constant SYNC_NBT_LOOKUP_PACKET_ID.
|
||||
*/
|
||||
public static final Identifier SYNC_NBT_LOOKUP_PACKET_ID =
|
||||
public static final ResourceLocation SYNC_NBT_LOOKUP_PACKET_ID =
|
||||
Lib39.rl("sync_nbt_lookup_data_entity");
|
||||
/**
|
||||
* The constant TYPE.
|
||||
|
|
@ -56,7 +56,7 @@ public record SyncNBTLookupDataEntityS2CPayload(int entityId, Identifier id, Com
|
|||
* @param buf the buffer
|
||||
*/
|
||||
public SyncNBTLookupDataEntityS2CPayload(RegistryFriendlyByteBuf buf) {
|
||||
this(buf.readInt(), buf.readIdentifier(), buf.readNbt());
|
||||
this(buf.readInt(), buf.readResourceLocation(), buf.readNbt());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -66,7 +66,7 @@ public record SyncNBTLookupDataEntityS2CPayload(int entityId, Identifier id, Com
|
|||
*/
|
||||
public void write(@NotNull FriendlyByteBuf friendlyByteBuf) {
|
||||
friendlyByteBuf.writeInt(entityId);
|
||||
friendlyByteBuf.writeIdentifier(id);
|
||||
friendlyByteBuf.writeResourceLocation(id);
|
||||
friendlyByteBuf.writeNbt(data);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package top.r3944realms.lib39.core.sync;
|
|||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
|
@ -17,10 +17,10 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
|
|||
/**
|
||||
* The Typed entries.
|
||||
*/
|
||||
protected final Map<Identifier, TypedSyncEntry<?>> typedEntries = Maps.newConcurrentMap();
|
||||
protected final Map<ResourceLocation, TypedSyncEntry<?>> typedEntries = Maps.newConcurrentMap();
|
||||
|
||||
@Override
|
||||
protected Map<Identifier, TypedSyncEntry<?>> getTypedEntries() {
|
||||
protected Map<ResourceLocation, TypedSyncEntry<?>> getTypedEntries() {
|
||||
return typedEntries;
|
||||
}
|
||||
|
||||
|
|
@ -57,11 +57,11 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
|
|||
* @param dataClass the data class
|
||||
*/
|
||||
public <T extends ISyncData<?>> void registerManager(
|
||||
Identifier key,
|
||||
ResourceLocation key,
|
||||
ISyncManager<Entity, T> manager,
|
||||
Class<T> dataClass
|
||||
) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
Objects.requireNonNull(manager, "Sync manager cannot be null");
|
||||
Objects.requireNonNull(dataClass, "Data class cannot be null");
|
||||
|
||||
|
|
@ -77,8 +77,8 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
|
|||
* @param key the key
|
||||
* @param apiLookup the EntityApiLookup
|
||||
*/
|
||||
public <T extends ISyncData<?>> void bindApiLookup(Identifier key, EntityApiLookup<T, Void> apiLookup) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
public <T extends ISyncData<?>> void bindApiLookup(ResourceLocation key, EntityApiLookup<T, Void> apiLookup) {
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
Objects.requireNonNull(apiLookup, "EntityApiLookup cannot be null");
|
||||
|
||||
TypedSyncEntry<?> entry = typedEntries.get(key);
|
||||
|
|
@ -94,8 +94,8 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
|
|||
*
|
||||
* @param key the key
|
||||
*/
|
||||
public void unbindApiLookup(Identifier key) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
public void unbindApiLookup(ResourceLocation key) {
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
|
||||
TypedSyncEntry<?> entry = typedEntries.get(key);
|
||||
if (entry != null) {
|
||||
|
|
@ -112,7 +112,7 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
|
|||
* @param newApiLookup the new api lookup
|
||||
*/
|
||||
protected <T extends ISyncData<?>> void updateApiLookupInEntry(
|
||||
Identifier id,
|
||||
ResourceLocation id,
|
||||
TypedSyncEntry<?> entry,
|
||||
EntityApiLookup<T, Void> newApiLookup
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package top.r3944realms.lib39.core.sync;
|
||||
|
||||
import net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import top.r3944realms.lib39.core.event.FabricCommonEventHandler;
|
||||
|
|
@ -25,7 +25,7 @@ public abstract class SyncLookupProvider<T extends NBTEntitySyncData> implements
|
|||
*
|
||||
* @return the id
|
||||
*/
|
||||
protected abstract Identifier getId();
|
||||
protected abstract ResourceLocation getId();
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
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.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.sync.IFabricUpdate;
|
||||
import top.r3944realms.lib39.util.storage.nbt.NBTReader;
|
||||
import top.r3944realms.lib39.util.storage.nbt.NBTWriter;
|
||||
import top.r3944realms.lib39.util.nbt.NBTReader;
|
||||
import top.r3944realms.lib39.util.nbt.NBTWriter;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
|
@ -23,7 +23,7 @@ public class FabricTestSyncData extends AbstractedTestSyncData implements IFabri
|
|||
/**
|
||||
* The constant ID.
|
||||
*/
|
||||
public static final Identifier ID = Lib39.rl(Lib39.MOD_ID, "test_sync_data");
|
||||
public static final ResourceLocation ID = Lib39.rl(Lib39.MOD_ID, "test_sync_data");
|
||||
|
||||
// NBT 键常量
|
||||
private static final String NBT_KEY_STRING = "test_string";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.example.content.data;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import top.r3944realms.lib39.core.sync.SyncLookupProvider;
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ public class FabricTestSyncLookupProvider extends SyncLookupProvider<AbstractedT
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Identifier getId() {
|
||||
protected ResourceLocation getId() {
|
||||
return FabricTestSyncData.ID;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package top.r3944realms.lib39.example.core.compat;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.compat.ICompat;
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ public class FabricLib39Compat implements ICompat {
|
|||
/**
|
||||
* The constant ID.
|
||||
*/
|
||||
public static Identifier ID = Lib39.rl("lib39");
|
||||
public static ResourceLocation ID = Lib39.rl("lib39");
|
||||
|
||||
@Override
|
||||
public void setInitialize(boolean initialize) {
|
||||
|
|
@ -33,7 +33,7 @@ public class FabricLib39Compat implements ICompat {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Identifier id() {
|
||||
public ResourceLocation id() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.example.core.compat;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.compat.CompatManager;
|
||||
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.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
|
|
@ -19,7 +19,7 @@ public record FabricClientDataPacket(AbstractedTestSyncData clientData, int targ
|
|||
/**
|
||||
* The constant CLIENT_TEST_DATA.
|
||||
*/
|
||||
public static final Identifier CLIENT_TEST_DATA =
|
||||
public static final ResourceLocation 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.CommandSourceStack;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.bus.api.Event;
|
||||
import top.r3944realms.lib39.core.command.ICommandHelpManager;
|
||||
import top.r3944realms.lib39.core.command.model.CommandNode;
|
||||
|
|
@ -37,7 +37,7 @@ public class RegisterCommandHelpEvent extends Event {
|
|||
*
|
||||
* @return the id
|
||||
*/
|
||||
public Identifier getID() {
|
||||
public ResourceLocation getID() {
|
||||
return helpManager.getID();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.api.event;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.bus.api.Event;
|
||||
import net.neoforged.neoforge.capabilities.EntityCapability;
|
||||
import top.r3944realms.lib39.core.sync.ISyncData;
|
||||
|
|
@ -45,7 +45,7 @@ public class SyncManagerRegisterEvent extends Event {
|
|||
* @param capability the capability
|
||||
*/
|
||||
public <K, T extends ISyncData<?>> void registerSyncManager(
|
||||
Identifier id,
|
||||
ResourceLocation id,
|
||||
ISyncManager<EntityCapability<T, Void>, T> syncManager,
|
||||
EntityCapability<T, Void> capability
|
||||
) {
|
||||
|
|
@ -57,7 +57,7 @@ public class SyncManagerRegisterEvent extends Event {
|
|||
*
|
||||
* @param id the id
|
||||
*/
|
||||
public void unregisterSyncManager(Identifier id) {
|
||||
public void unregisterSyncManager(ResourceLocation id) {
|
||||
syncs2Manager.removeManager(id);
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ public class SyncManagerRegisterEvent extends Event {
|
|||
* @param id the id
|
||||
* @param entityClasses the entity classes
|
||||
*/
|
||||
public final void addAllowEntityClass(Identifier id, Class<?>... entityClasses) {
|
||||
public final void addAllowEntityClass(ResourceLocation id, Class<?>... entityClasses) {
|
||||
syncs2Manager.allowEntityClass(id, entityClasses);
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ public class SyncManagerRegisterEvent extends Event {
|
|||
* @param id the id
|
||||
* @param entityClasses the entity classes
|
||||
*/
|
||||
public final void removeAllowEntityClass(Identifier id, Class<?>... entityClasses) {
|
||||
public final void removeAllowEntityClass(ResourceLocation id, Class<?>... entityClasses) {
|
||||
syncs2Manager.disallowEntityClass(id, entityClasses);
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ public class SyncManagerRegisterEvent extends Event {
|
|||
* @param id 必须先注册安全同步管理器,再绑定Cap,否则会抛出{@link IllegalStateException 未找到对应安全同步管理器}
|
||||
* @param capability the capability
|
||||
*/
|
||||
public <T extends ISyncData<?>> void bindCapability(Identifier id, EntityCapability<T, Void> capability) {
|
||||
public <T extends ISyncData<?>> void bindCapability(ResourceLocation id, EntityCapability<T, Void> capability) {
|
||||
syncs2Manager.bindCapability(id, capability);
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ public class SyncManagerRegisterEvent extends Event {
|
|||
*
|
||||
* @param id the id
|
||||
*/
|
||||
public void unbindCapability(Identifier id) {
|
||||
public void unbindCapability(ResourceLocation id) {
|
||||
syncs2Manager.unbindCapability(id);
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +112,7 @@ public class SyncManagerRegisterEvent extends Event {
|
|||
* @param allowedEntityClasses the allowed entity classes
|
||||
*/
|
||||
public <K, T extends ISyncData<?>> void registerComplete(
|
||||
Identifier id,
|
||||
ResourceLocation id,
|
||||
ISyncManager<EntityCapability<T, Void>, T> syncManager,
|
||||
EntityCapability<T, Void> capability,
|
||||
Class<?>... allowedEntityClasses
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.base.compat.jade;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import snownee.jade.api.IWailaClientRegistration;
|
||||
import snownee.jade.api.IWailaPlugin;
|
||||
|
|
@ -17,7 +17,7 @@ public class NeoForgeJadePlugin implements IWailaPlugin {
|
|||
/**
|
||||
* The constant UID.
|
||||
*/
|
||||
public static final Identifier UID = Lib39.rl("lib39");
|
||||
public static final ResourceLocation UID = Lib39.rl("lib39");
|
||||
|
||||
@Override
|
||||
public void registerClient(@NotNull IWailaClientRegistration registration) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package top.r3944realms.lib39.base.compat.jade.provider;
|
|||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import snownee.jade.api.BlockAccessor;
|
||||
import snownee.jade.api.IBlockComponentProvider;
|
||||
|
|
@ -17,7 +17,7 @@ import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
|
|||
*/
|
||||
public class NeoForgeDollComponentProvider implements IBlockComponentProvider {
|
||||
@Override
|
||||
public Identifier getUid() {
|
||||
public ResourceLocation getUid() {
|
||||
return NeoForgeJadePlugin.UID;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,37 +44,37 @@ public class Lib39BaseDataGenEvent {
|
|||
}
|
||||
private static void LanguageGenerator(@NotNull GatherDataEvent event, McLocale language) {
|
||||
event.getGenerator().addProvider(
|
||||
true,
|
||||
event.includeClient(),
|
||||
(DataProvider.Factory<SimpleLanguageProvider>) pOutput -> new SimpleLanguageProvider(pOutput, Lib39.MOD_ID ,language , Lib39LangKey.INSTANCE)
|
||||
);
|
||||
}
|
||||
private static void ItemModelDataGenerate(@NotNull GatherDataEvent event) {
|
||||
event.getGenerator().addProvider(
|
||||
true,
|
||||
event.includeClient(),
|
||||
(DataProvider.Factory<Lib39ItemModelProvider>) pOutput -> new Lib39ItemModelProvider(pOutput, event.getExistingFileHelper())
|
||||
);
|
||||
}
|
||||
private static void BlockModelDataGenerate(@NotNull GatherDataEvent event) {
|
||||
event.getGenerator().addProvider(
|
||||
true,
|
||||
event.includeClient(),
|
||||
(DataProvider.Factory<Lib39BlockModelProvider>) pOutput -> new Lib39BlockModelProvider(pOutput, event.getExistingFileHelper())
|
||||
);
|
||||
}
|
||||
private static void BlockStateDataGenerate(@NotNull GatherDataEvent event) {
|
||||
event.getGenerator().addProvider(
|
||||
true,
|
||||
event.includeClient(),
|
||||
(DataProvider.Factory<Lib39BlockStatesProvider>) pOutput -> new Lib39BlockStatesProvider(pOutput, event.getExistingFileHelper())
|
||||
);
|
||||
}
|
||||
private static void SoundDefinitionDataGenerate(@NotNull GatherDataEvent event) {
|
||||
event.getGenerator().addProvider(
|
||||
true,
|
||||
event.includeClient(),
|
||||
(DataProvider.Factory<Lib39SoundDefinitionsProvider>) pOutput -> new Lib39SoundDefinitionsProvider(pOutput, event.getExistingFileHelper())
|
||||
);
|
||||
}
|
||||
private static void LootTableDataGenerate(@NotNull GatherDataEvent event) {
|
||||
event.getGenerator().addProvider(
|
||||
true,
|
||||
event.includeServer(),
|
||||
(DataProvider.Factory<SimpleLootTableProvider>) pOutput -> {
|
||||
try {
|
||||
return new SimpleLootTableProvider(pOutput, new SubProvidersWrapper().addBlockEntry(new Lib39BlockLootTable(event.getLookupProvider())), event.getLookupProvider());
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package top.r3944realms.lib39.base.datagen.provider;
|
||||
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.neoforge.client.model.generators.BlockModelProvider;
|
||||
import net.neoforged.neoforge.common.data.ExistingFileHelper;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
|
|
@ -35,7 +35,7 @@ public class Lib39BlockModelProvider extends BlockModelProvider {
|
|||
}
|
||||
}
|
||||
private void createPlantsModel(PlantHelper.Plant plant) {
|
||||
Identifier rl = PlantHelper.getTextureRL(plant);
|
||||
ResourceLocation rl = PlantHelper.getTextureRL(plant);
|
||||
getBuilder("block/doll_item/" + plant)
|
||||
.parent(getExistingFile(Lib39.rl("block/base_doll_item")))
|
||||
.texture("item", rl)
|
||||
|
|
|
|||
|
|
@ -17,8 +17,10 @@ package top.r3944realms.lib39.base.datagen.provider;
|
|||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.neoforged.neoforge.client.model.generators.ItemModelProvider;
|
||||
import net.neoforged.neoforge.common.data.ExistingFileHelper;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.base.datagen.value.Lib39LangKey;
|
||||
import top.r3944realms.lib39.datagen.value.LangKeyValue;
|
||||
|
|
@ -78,7 +80,7 @@ public class Lib39ItemModelProvider extends ItemModelProvider {
|
|||
* @param item the item
|
||||
* @param location the location
|
||||
*/
|
||||
public void itemGenerateModel(Item item, Identifier location){
|
||||
public void itemGenerateModel(Item item, ResourceLocation location){
|
||||
withExistingParent(itemName(item), GENERATED).texture("layer0", location);
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +90,7 @@ public class Lib39ItemModelProvider extends ItemModelProvider {
|
|||
* @param item the item
|
||||
* @param location the location
|
||||
*/
|
||||
public void itemHandHeldModel(Item item, Identifier location){
|
||||
public void itemHandHeldModel(Item item, ResourceLocation location){
|
||||
withExistingParent(itemName(item), HANDHELD).texture("layer0", location);
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +118,7 @@ public class Lib39ItemModelProvider extends ItemModelProvider {
|
|||
* @param path the path
|
||||
* @return the resource location
|
||||
*/
|
||||
public Identifier resourceItem(String path){
|
||||
public ResourceLocation resourceItem(String path){
|
||||
return modLoc("item/" + path);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.core.compat;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
|
|
@ -30,7 +30,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
/**
|
||||
* The Compats.
|
||||
*/
|
||||
protected final Map<Identifier, INeoForgeCompat> compats = new HashMap<>();
|
||||
protected final Map<ResourceLocation, INeoForgeCompat> compats = new HashMap<>();
|
||||
/**
|
||||
* <pre>
|
||||
* 存储事件监听器配置
|
||||
|
|
@ -40,7 +40,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
protected final List<ListenerConfig> listenerConfigs = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Map<Identifier, INeoForgeCompat> getCompatMap() {
|
||||
public Map<ResourceLocation, INeoForgeCompat> getCompatMap() {
|
||||
return compats;
|
||||
}
|
||||
|
||||
|
|
@ -51,14 +51,14 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
* @param modEventBus the mod event bus
|
||||
* @param gameEventBus the game event bus
|
||||
*/
|
||||
public NeoForgeCompatManager(Identifier id, IEventBus modEventBus, IEventBus gameEventBus) {
|
||||
public NeoForgeCompatManager(ResourceLocation id, IEventBus modEventBus, IEventBus gameEventBus) {
|
||||
super(id);
|
||||
this.modEventBus = modEventBus;
|
||||
this.gameEventBus = gameEventBus;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doRegisterCompat(Identifier id, INeoForgeCompat compat) {
|
||||
protected void doRegisterCompat(ResourceLocation id, INeoForgeCompat compat) {
|
||||
super.doRegisterCompat(id, compat);
|
||||
addListenerForCompat(id);
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
* @param dists the dists
|
||||
* @param bus the bus
|
||||
*/
|
||||
public void addListenerForCompat(Identifier compatId, @Nullable Dist dists, EventBusSubscriber.Bus bus) {
|
||||
public void addListenerForCompat(ResourceLocation compatId, @Nullable Dist dists, EventBusSubscriber.Bus bus) {
|
||||
listenerConfigs.add(new ListenerConfig(compatId, dists, bus));
|
||||
}
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
*
|
||||
* @param compatId the compat id
|
||||
*/
|
||||
public void addListenerForCompat(Identifier compatId) {
|
||||
public void addListenerForCompat(ResourceLocation compatId) {
|
||||
addListenerForCompat(compatId, null, EventBusSubscriber.Bus.GAME);
|
||||
addListenerForCompat(compatId, null, EventBusSubscriber.Bus.MOD);
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
pendingTasks.clear();
|
||||
|
||||
// 初始化所有兼容模块
|
||||
for (Map.Entry<Identifier, INeoForgeCompat> entry : compats.entrySet()) {
|
||||
for (Map.Entry<ResourceLocation, INeoForgeCompat> entry : compats.entrySet()) {
|
||||
if (!entry.getValue().isInitialized() && entry.getValue().isModLoaded()) {
|
||||
try {
|
||||
entry.getValue().initialize();
|
||||
|
|
@ -178,7 +178,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
/**
|
||||
* 将监听器应用到特定兼容模块
|
||||
*/
|
||||
private void applyListenerToCompat(Identifier compatId, ListenerConfig config) {
|
||||
private void applyListenerToCompat(ResourceLocation compatId, ListenerConfig config) {
|
||||
INeoForgeCompat compat = compats.get(compatId);
|
||||
if (compat != null && config.shouldApply(compat)) {
|
||||
applyListenerToCompat(compat, config);
|
||||
|
|
@ -257,7 +257,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
* @param compatId the compat id
|
||||
* @param bus the bus
|
||||
*/
|
||||
public void addListenerForCompat(Identifier compatId, EventBusSubscriber.Bus bus) {
|
||||
public void addListenerForCompat(ResourceLocation compatId, EventBusSubscriber.Bus bus) {
|
||||
addListenerForCompat(compatId, null, bus);
|
||||
}
|
||||
|
||||
|
|
@ -268,7 +268,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
/**
|
||||
* The Compat id.
|
||||
*/
|
||||
final Identifier compatId;
|
||||
final ResourceLocation compatId;
|
||||
/**
|
||||
* The Dists.
|
||||
*/
|
||||
|
|
@ -285,7 +285,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
* @param dists the dists
|
||||
* @param bus the bus
|
||||
*/
|
||||
ListenerConfig(Identifier compatId, Dist dists, EventBusSubscriber.Bus bus) {
|
||||
ListenerConfig(ResourceLocation compatId, Dist dists, EventBusSubscriber.Bus bus) {
|
||||
this.compatId = compatId;
|
||||
this.dists = dists;
|
||||
this.bus = bus;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import net.minecraft.client.multiplayer.ClientLevel;
|
|||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
|
|
@ -143,8 +143,8 @@ public class CommonEventHandler {
|
|||
public static void onServerTick(ServerTickEvent.Post event) {
|
||||
if (syncData2Manager == null) return;
|
||||
if (event.getServer().getTickCount() % 10 == 0)
|
||||
syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
|
||||
syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
|
||||
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
|
||||
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -206,7 +206,7 @@ public class CommonEventHandler {
|
|||
Entity entity = event.getEntity();
|
||||
if (entity.level().isClientSide) return;
|
||||
|
||||
for (Identifier id : syncData2Manager.getRegisteredKeys()) {
|
||||
for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
|
||||
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
|
||||
syncData2Manager.trackEntityForManager(entity, id);
|
||||
}
|
||||
|
|
@ -223,7 +223,7 @@ public class CommonEventHandler {
|
|||
Entity entity = event.getEntity();
|
||||
if (entity.level().isClientSide) return;
|
||||
|
||||
for (Identifier id : syncData2Manager.getRegisteredKeys()) {
|
||||
for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
|
||||
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
|
||||
syncData2Manager.untrackEntityForManager(entity, id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import net.minecraft.network.FriendlyByteBuf;
|
|||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
|
@ -25,11 +25,11 @@ import java.util.function.Supplier;
|
|||
* The type Sync nbt data s 2 c payload.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public record SyncNBTCapDataEntityS2CPayload(int entityId, Identifier id, CompoundTag data) implements CustomPacketPayload {
|
||||
public record SyncNBTCapDataEntityS2CPayload(int entityId, ResourceLocation id, CompoundTag data) implements CustomPacketPayload {
|
||||
/**
|
||||
* The constant SYNC_NBT_CAP_PACKET_ID.
|
||||
*/
|
||||
public static final Identifier SYNC_NBT_CAP_PACKET_ID =
|
||||
public static final ResourceLocation SYNC_NBT_CAP_PACKET_ID =
|
||||
Lib39.rl("sync_nbt_cap_data_entity");
|
||||
/**
|
||||
* The constant TYPE.
|
||||
|
|
@ -60,7 +60,7 @@ public record SyncNBTCapDataEntityS2CPayload(int entityId, Identifier id, Compou
|
|||
*/
|
||||
public static void encode(@NotNull SyncNBTCapDataEntityS2CPayload msg, @NotNull FriendlyByteBuf buffer) {
|
||||
buffer.writeInt(msg.entityId);
|
||||
buffer.writeIdentifier(msg.id);
|
||||
buffer.writeResourceLocation(msg.id);
|
||||
buffer.writeNbt(msg.data);
|
||||
}
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ public record SyncNBTCapDataEntityS2CPayload(int entityId, Identifier id, Compou
|
|||
*/
|
||||
@Contract("_ -> new")
|
||||
public static @NotNull SyncNBTCapDataEntityS2CPayload decode(@NotNull FriendlyByteBuf buffer) {
|
||||
return new SyncNBTCapDataEntityS2CPayload(buffer.readInt(), buffer.readIdentifier(), buffer.readNbt());
|
||||
return new SyncNBTCapDataEntityS2CPayload(buffer.readInt(), buffer.readResourceLocation(), buffer.readNbt());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.core.sync;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.neoforged.neoforge.capabilities.ICapabilityProvider;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
|
@ -26,7 +26,7 @@ public abstract class SyncCapProvider<T extends NBTEntitySyncData> implements IC
|
|||
*
|
||||
* @return 能力 ID
|
||||
*/
|
||||
protected abstract Identifier getId();
|
||||
protected abstract ResourceLocation getId();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package top.r3944realms.lib39.core.sync;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.neoforge.capabilities.EntityCapability;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
|
@ -17,10 +17,10 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
|
|||
/**
|
||||
* The Typed entries.
|
||||
*/
|
||||
protected final Map<Identifier, TypedSyncEntry<?>> typedEntries = Maps.newConcurrentMap();
|
||||
protected final Map<ResourceLocation, TypedSyncEntry<?>> typedEntries = Maps.newConcurrentMap();
|
||||
|
||||
@Override
|
||||
protected Map<Identifier, TypedSyncEntry<?>> getTypedEntries() {
|
||||
protected Map<ResourceLocation, TypedSyncEntry<?>> getTypedEntries() {
|
||||
return typedEntries;
|
||||
}
|
||||
|
||||
|
|
@ -50,11 +50,11 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
|
|||
* @param capability the capability
|
||||
*/
|
||||
public <T extends ISyncData<?>> void registerManager(
|
||||
Identifier key,
|
||||
ResourceLocation key,
|
||||
ISyncManager<EntityCapability<T, Void>, T> manager,
|
||||
EntityCapability<T, Void> capability
|
||||
) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
Objects.requireNonNull(manager, "Sync manager cannot be null");
|
||||
Objects.requireNonNull(capability, "Capability cannot be null");
|
||||
|
||||
|
|
@ -69,8 +69,8 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
|
|||
* @param key the key
|
||||
* @param capability the capability
|
||||
*/
|
||||
public <T extends ISyncData<?>> void bindCapability(Identifier key, EntityCapability<T, Void> capability) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
public <T extends ISyncData<?>> void bindCapability(ResourceLocation key, EntityCapability<T, Void> capability) {
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
Objects.requireNonNull(capability, "Capability cannot be null");
|
||||
|
||||
TypedSyncEntry<?> entry = typedEntries.get(key);
|
||||
|
|
@ -85,8 +85,8 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
|
|||
*
|
||||
* @param key the key
|
||||
*/
|
||||
public void unbindCapability(Identifier key) {
|
||||
Objects.requireNonNull(key, "Identifier key cannot be null");
|
||||
public void unbindCapability(ResourceLocation key) {
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
|
||||
TypedSyncEntry<?> entry = typedEntries.get(key);
|
||||
if (entry != null) {
|
||||
|
|
@ -103,7 +103,7 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
|
|||
* @param entry the entry
|
||||
* @param newCapability the new capability
|
||||
*/
|
||||
protected <T extends ISyncData<?>> void updateCapabilityInEntry(Identifier id, TypedSyncEntry<?> entry, EntityCapability<T, Void> newCapability) {
|
||||
protected <T extends ISyncData<?>> void updateCapabilityInEntry(ResourceLocation id, TypedSyncEntry<?> entry, EntityCapability<T, Void> newCapability) {
|
||||
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.loot.LootTableProvider;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.ProblemReporter;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.world.level.storage.loot.ValidationContext;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.example.compat;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.ModList;
|
||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
|
|
@ -23,7 +23,7 @@ public class Lib39Compat implements INeoForgeCompat {
|
|||
/**
|
||||
* The constant ID.
|
||||
*/
|
||||
public static Identifier ID = Lib39.rl("lib39");
|
||||
public static ResourceLocation ID = Lib39.rl("lib39");
|
||||
|
||||
@Override
|
||||
public void setInitialize(boolean initialize) {
|
||||
|
|
@ -36,7 +36,7 @@ public class Lib39Compat implements INeoForgeCompat {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Identifier id() {
|
||||
public ResourceLocation id() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.example.content.data;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.sync.SyncCapProvider;
|
||||
|
|
@ -13,7 +13,7 @@ public class TestSyncCapProvider extends SyncCapProvider<AbstractedTestSyncData>
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Identifier getId() {
|
||||
protected ResourceLocation getId() {
|
||||
return Lib39.rl("test_data");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ package top.r3944realms.lib39.example.content.data;
|
|||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.sync.INeoForgeUpdate;
|
||||
import top.r3944realms.lib39.util.storage.nbt.NBTReader;
|
||||
import top.r3944realms.lib39.util.storage.nbt.NBTWriter;
|
||||
import top.r3944realms.lib39.util.nbt.NBTReader;
|
||||
import top.r3944realms.lib39.util.nbt.NBTWriter;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
|
@ -22,7 +22,7 @@ public class TestSyncData extends AbstractedTestSyncData implements INeoForgeUpd
|
|||
/**
|
||||
* The constant ID.
|
||||
*/
|
||||
public static final Identifier ID = Lib39.rl(Lib39.MOD_ID, "test_sync_data");
|
||||
public static final ResourceLocation ID = Lib39.rl(Lib39.MOD_ID, "test_sync_data");
|
||||
|
||||
// NBT 键常量
|
||||
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.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
|
|
@ -21,7 +21,7 @@ public record ClientDataPayload(AbstractedTestSyncData clientData, int targetEnt
|
|||
/**
|
||||
* The constant CLIENT_DATA_PACKET_ID.
|
||||
*/
|
||||
public static final Identifier CLIENT_DATA_PACKET_ID =
|
||||
public static final ResourceLocation CLIENT_DATA_PACKET_ID =
|
||||
Lib39.rl("client_data");
|
||||
/**
|
||||
* The constant TYPE.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package top.r3944realms.lib39.util;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.*;
|
||||
import net.minecraft.world.entity.animal.Animal;
|
||||
import net.minecraft.world.entity.monster.Monster;
|
||||
|
|
@ -85,7 +85,7 @@ public class EntityCapabilityHelper {
|
|||
|
||||
BuiltInRegistries.ENTITY_TYPE.stream()
|
||||
.filter(entityType -> {
|
||||
Identifier key = BuiltInRegistries.ENTITY_TYPE.getKey(entityType);
|
||||
ResourceLocation key = BuiltInRegistries.ENTITY_TYPE.getKey(entityType);
|
||||
return namespace.equals(key.getNamespace());
|
||||
})
|
||||
.forEach(entityType -> event.registerEntity(capability, entityType, provider));
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
# 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` 参数,指示实体是与方块相交还是在方块内部。
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -1,38 +0,0 @@
|
|||
# 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`
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
# 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` - 一个用于解决特定图形硬件问题的辅助工具。
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -1,135 +0,0 @@
|
|||
# 详细入门文档
|
||||
|
||||
这些章节按步骤保留了上游入门文档的内容。每个章节标题都直接链接到入门文档页面内的相应章节。
|
||||
|
||||
## 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