feat: 删除NBT工具类部分方法

This commit is contained in:
叁玖领域 2026-05-24 00:59:26 +08:00
parent fe3d3478a9
commit fe186cd36b
61 changed files with 491 additions and 637 deletions

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
@ -48,8 +48,8 @@ public class Lib39 {
* @return the resource location
*/
@Contract("_ -> new")
public static @NotNull ResourceLocation rl(String path) {
return ResourceLocation.fromNamespaceAndPath(Lib39.MOD_ID, path);
public static @NotNull Identifier rl(String path) {
return Identifier.fromNamespaceAndPath(Lib39.MOD_ID, path);
}
/**
@ -60,8 +60,8 @@ public class Lib39 {
* @return the resource location
*/
@Contract("_, _ -> new")
public static @NotNull ResourceLocation rl(String modId, String path) {
return ResourceLocation.fromNamespaceAndPath(modId, path);
public static @NotNull Identifier rl(String modId, String path) {
return Identifier.fromNamespaceAndPath(modId, path);
}
/**
@ -71,8 +71,8 @@ public class Lib39 {
* @return the resource location
*/
@Contract("_ -> new")
public static @NotNull ResourceLocation mrl(String path) {
return ResourceLocation.withDefaultNamespace(path);
public static @NotNull Identifier mrl(String path) {
return Identifier.withDefaultNamespace(path);
}
/**

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.base.command;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.core.command.SimpleCommandHelpManager;
@ -18,7 +18,7 @@ public class Lib39CommandHelpManager extends SimpleCommandHelpManager {
/**
* 作为唯一标识符
*/
ResourceLocation ID = Lib39.rl("command_helper");
Identifier ID = Lib39.rl("command_helper");
/**
* <pre>
@ -31,7 +31,7 @@ public class Lib39CommandHelpManager extends SimpleCommandHelpManager {
}
@Override
public ResourceLocation getID() {
public Identifier getID() {
return ID;
}

View File

@ -11,7 +11,7 @@ import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerPlayer;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.Lib39;
@ -19,6 +19,7 @@ import top.r3944realms.lib39.core.command.ICommandHelpManager;
import top.r3944realms.lib39.core.command.SimpleHelpCommand;
import java.util.Map;
import java.util.Set;
/**
* <pre>
@ -92,7 +93,7 @@ public class Lib39HelpCommand extends SimpleHelpCommand {
.executes(this::executeCalculate)))
)
.then(Commands.literal("teleport")
.requires(source -> source.hasPermission(2)) // 需要OP權限
.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)) // 需要游戏管理员權限
.then(Commands.argument("target", EntityArgument.player())
.executes(this::executeTeleport))
)
@ -284,12 +285,14 @@ public class Lib39HelpCommand extends SimpleHelpCommand {
if (source.getEntity() instanceof ServerPlayer player) {
player.teleportTo(
target.serverLevel(),
target.level(),
target.getX(),
target.getY(),
target.getZ(),
Set.of(),
target.getYRot(),
target.getXRot()
target.getXRot(),
true
);
source.sendSuccess(() ->
@ -304,7 +307,7 @@ public class Lib39HelpCommand extends SimpleHelpCommand {
private int executeInfo(CommandContext<CommandSourceStack> context) {
CommandSourceStack source = context.getSource();
ResourceLocation dimension = source.getLevel().dimension().location();
Identifier dimension = source.getLevel().dimension().identifier();
source.sendSuccess(() ->
Component.translatable("commands.lib39.info.message")

View File

@ -19,16 +19,16 @@ public class Lib39RecipeProvider extends RecipeProvider {
* @param output the output
* @param registries the registries
*/
public Lib39RecipeProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) {
super(output, registries);
public Lib39RecipeProvider(HolderLookup.Provider output, RecipeOutput recipeOutput) {
super(output, recipeOutput);
}
@Override
public void buildRecipes(RecipeOutput recipeOutput) {
ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, Lib39Items.DOLL.get())
protected void buildRecipes() {
this.shapeless(RecipeCategory.MISC, Lib39Items.DOLL.get())
.requires(ItemTags.WOOL)
.requires(Items.ARMOR_STAND)
.unlockedBy("has_armor_stand",has(Items.ARMOR_STAND))
.save(recipeOutput);
.save(this.output);
}
}

View File

@ -3,7 +3,6 @@ package top.r3944realms.lib39.client.gui.component;
import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;
@ -12,6 +11,7 @@ import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.network.chat.Component;
import org.joml.Matrix4f;
import org.joml.Vector2f;
import org.jspecify.annotations.NonNull;
import top.r3944realms.lib39.client.shader.Lib39Shaders;
import top.r3944realms.lib39.util.MathUtil;
import top.r3944realms.lib39.util.lang.FourConsumer;
@ -681,7 +681,7 @@ public class WheelWidget extends AbstractWidget {
* @param radius the radius
*/
public static void renderSelectionEffect(
GuiGraphics guiGraphics,
@NonNull GuiGraphics guiGraphics,
float centerX,
float centerY,
int color,

View File

@ -1,7 +1,7 @@
package top.r3944realms.lib39.client.model;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.Lib39;
@ -23,7 +23,7 @@ public enum DollPoses implements IDollPose{
PartPose.offsetAndRotation(2.0F, 19.0F, -2.0F, -1.5708F, -0.3927F, 0.0F)
);
// 注册全局
private final ResourceLocation id;
private final Identifier id;
private final Vec3 offset;
private final PartPose headPose;
private final PartPose bodyPose;
@ -52,7 +52,7 @@ public enum DollPoses implements IDollPose{
}
@Override
public @NotNull ResourceLocation getId() {
public @NotNull Identifier getId() {
return id;
}

View File

@ -1,7 +1,7 @@
package top.r3944realms.lib39.client.model;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
@ -14,7 +14,7 @@ public interface IDollPose {
*
* @return the id
*/
@NotNull ResourceLocation getId();
@NotNull Identifier getId();
/**
* Gets total offset.

View File

@ -14,7 +14,7 @@ import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.client.resources.PlayerSkin;
import net.minecraft.client.resources.SkinManager;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.component.ResolvableProfile;
import net.minecraft.world.level.block.SkullBlock;
import net.minecraft.world.level.block.WallSkullBlock;

View File

@ -12,7 +12,7 @@ import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.client.resources.PlayerSkin;
import net.minecraft.client.resources.SkinManager;
import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ResolvableProfile;
@ -75,7 +75,7 @@ public class DollItemRenderer extends BlockEntityWithoutLevelRenderer {
// 直接从 DataComponents.PROFILE 获取 ResolvableProfile
ResolvableProfile profile = stack.get(DataComponents.PROFILE);
Pair<ResourceLocation, PlayerSkin.Model> skinInfo = getSkinInfo(profile);
Pair<Identifier, 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<ResourceLocation, PlayerSkin.Model> getSkinInfo(@NotNull ResolvableProfile profile) {
public static @NotNull Pair<Identifier, PlayerSkin.Model> getSkinInfo(@NotNull ResolvableProfile profile) {
SkinManager skinManager = Minecraft.getInstance().getSkinManager();
if (profile != null && profile.gameProfile() != null) {

View File

@ -3,7 +3,7 @@ package top.r3944realms.lib39.core.command;
import net.minecraft.ChatFormatting;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.r3944realms.lib39.base.datagen.value.Lib39LangKey;
@ -31,7 +31,7 @@ public interface ICommandHelpManager {
*
* @return the id
*/
ResourceLocation getID();
Identifier getID();
/**
* Gets head key.

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.command;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.core.command.model.CommandNode;
import top.r3944realms.lib39.core.command.model.Parameter;
@ -28,7 +28,7 @@ public abstract class SimpleCommandHelpManager implements ICommandHelpManager {
public void initialize() {
if (root == null) {
// 現在子類的字段已經初始化完成
ResourceLocation id = getID();
Identifier id = getID();
if (id == null) {
throw new IllegalStateException("getID() must return non-null");
}

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.compat;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -22,7 +22,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
* @return the id
*/
@Override
public ResourceLocation getId() {
public Identifier getId() {
return id;
}
@ -33,7 +33,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
/**
* The Id.
*/
protected final ResourceLocation id;
protected final Identifier id;
/**
* The Initialized.
@ -58,7 +58,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
*
* @param id the id
*/
public CompatManager(@NotNull ResourceLocation id) {
public CompatManager(@NotNull Identifier id) {
this.id = id;
this.logger = LoggerFactory.getLogger(id.toString());
}
@ -70,7 +70,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
* @param compat the compat
*/
@Override
public void registerCompat(ResourceLocation id, C compat) {
public void registerCompat(Identifier id, C compat) {
if (initialized) {
// 已初始化直接注册
doRegisterCompat(id, compat);
@ -87,7 +87,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
* @param id the id
* @param compat the compat
*/
protected void doRegisterCompat(ResourceLocation id, C compat) {
protected void doRegisterCompat(Identifier id, C compat) {
if (getCompatMap().containsKey(id)) {
logger.warn("Compat with id {} is already registered!", id);
return;
@ -122,7 +122,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
pendingTasks.clear();
// 初始化所有兼容模块
for (Map.Entry<ResourceLocation, C> entry : getCompatMap().entrySet()) {
for (Map.Entry<Identifier, C> entry : getCompatMap().entrySet()) {
if (!entry.getValue().isInitialized() && entry.getValue().isModLoaded()) {
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(ResourceLocation id) {
public Optional<C> getCompat(Identifier 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(ResourceLocation id) {
public boolean hasCompat(Identifier 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(ResourceLocation id) {
public void unregisterCompat(Identifier id) {
C removed = getCompatMap().remove(id);
if (removed != null) {
logger.debug("Unregistered compat: {}", id);
@ -187,7 +187,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
*/
public void onLoadComplete() {
logger.info("Calling onLoadComplete for {} compatibility modules", getCompatMap().size());
for (Map.Entry<ResourceLocation, C> entry : getCompatMap().entrySet()) {
for (Map.Entry<Identifier, C> entry : getCompatMap().entrySet()) {
try {
entry.getValue().onLoadComplete();
} catch (Exception e) {

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.compat;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import java.util.concurrent.Callable;
@ -27,7 +27,7 @@ public interface ICompat {
*
* @return the resource location
*/
ResourceLocation id();
Identifier id();
/**
* Initialize.

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.compat;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import java.util.Map;
import java.util.Optional;
@ -16,14 +16,14 @@ public interface ICompatManager<C extends ICompat> {
*
* @return the id
*/
ResourceLocation getId();
Identifier getId();
/**
* Gets compat map.
*
* @return the compat map
*/
Map<ResourceLocation, C> getCompatMap();
Map<Identifier, C> getCompatMap();
/**
* Initialize.
@ -36,7 +36,7 @@ public interface ICompatManager<C extends ICompat> {
* @param id the id
* @param compat the compat
*/
void registerCompat(ResourceLocation id, C compat);
void registerCompat(Identifier id, C compat);
/**
* Register compat.
@ -53,7 +53,7 @@ public interface ICompatManager<C extends ICompat> {
* @param id the id
* @return the compat
*/
Optional<C> getCompat(ResourceLocation id);
Optional<C> getCompat(Identifier id);
/**
* Has compat boolean.
@ -61,12 +61,12 @@ public interface ICompatManager<C extends ICompat> {
* @param id the id
* @return the boolean
*/
boolean hasCompat(ResourceLocation id);
boolean hasCompat(Identifier id);
/**
* Unregister compat.
*
* @param id the id
*/
void unregisterCompat(ResourceLocation id);
void unregisterCompat(Identifier id);
}

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.compat;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
@ -13,19 +13,19 @@ public class SimpleCompatManager extends CompatManager<ICompat> {
/**
* The Compats.
*/
Map<ResourceLocation, ICompat> compats = new HashMap<>();
Map<Identifier, ICompat> compats = new HashMap<>();
/**
* Instantiates a new Compat manager.
*
* @param id the id
*/
public SimpleCompatManager(@NotNull ResourceLocation id) {
public SimpleCompatManager(@NotNull Identifier id) {
super(id);
}
@Override
public Map<ResourceLocation, ICompat> getCompatMap() {
public Map<Identifier, ICompat> getCompatMap() {
return compats;
}
}

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.register;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.sounds.SoundEvent;
import top.r3944realms.lib39.Lib39;
@ -13,7 +13,7 @@ public class Lib39SoundEvents {
/**
* The constant RL_DUCK_TOY.
*/
public static final ResourceLocation RL_DUCK_TOY = Lib39.rl("duck_toy");
public static final Identifier RL_DUCK_TOY = Lib39.rl("duck_toy");
/**
* The constant DUCK_TOY.
*/

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.sync;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
/**
* The interface Sync data.
@ -13,7 +13,7 @@ public interface ISyncData<T> {
*
* @return the resource location
*/
ResourceLocation id();
Identifier id();
/**
* Is dirty boolean.

View File

@ -1,7 +1,7 @@
package top.r3944realms.lib39.core.sync;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
/**
@ -15,19 +15,19 @@ public abstract class NBTEntitySyncData implements IEntity, ISyncData<NBTEntityS
/**
* The Id.
*/
protected final ResourceLocation id;
protected final Identifier id;
/**
* Instantiates a new Nbt sync data.
*
* @param id the id
*/
protected NBTEntitySyncData(ResourceLocation id) {
protected NBTEntitySyncData(Identifier id) {
this.id = id;
}
@Override
public ResourceLocation id() {
public Identifier id() {
return id;
}

View File

@ -1,7 +1,7 @@
package top.r3944realms.lib39.core.sync;
import com.google.common.collect.Sets;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
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<ResourceLocation, V> getTypedEntries();
protected abstract Map<Identifier, V> getTypedEntries();
/**
* 数据提供者接口 - 用于通过键获取数据
@ -86,11 +86,11 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
*/
@SuppressWarnings("unchecked")
public <K, T extends ISyncData<?>> void registerManagerWithProvider(
ResourceLocation key,
Identifier key,
ISyncManager<K, T> manager,
DataProvider<Entity, T> dataProvider
) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(manager, "Sync manager cannot be null");
Objects.requireNonNull(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(
ResourceLocation key,
Identifier key,
ISyncManager<K, T> manager,
Function<Entity, Optional<T>> getter
) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(manager, "Sync manager cannot be null");
Objects.requireNonNull(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(ResourceLocation key, ISyncManager<?, ? extends ISyncData<?>> manager) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
public void registerManager(Identifier key, ISyncManager<?, ? extends ISyncData<?>> manager) {
Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(manager, "Sync manager cannot be null");
// 创建一个没有数据提供者的 TypedSyncEntry
@ -146,7 +146,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
* @return the manager
*/
@SuppressWarnings("unchecked")
public <K, T extends ISyncData<?>> Optional<ISyncManager<K, T>> getManager(ResourceLocation key) {
public <K, T extends ISyncData<?>> Optional<ISyncManager<K, T>> getManager(Identifier key) {
TypedSyncEntry<?,?> entry = getTypedEntries().get(key);
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(ResourceLocation key) {
public <T extends ISyncData<?>> Optional<DataProvider<Entity, T>> getDataProvider(Identifier 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(ResourceLocation key, Entity entity) {
public <T extends ISyncData<?>> Optional<T> getEntityData(Identifier 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(ResourceLocation key, Class<?>... classes) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
public final void allowEntityClass(Identifier key, Class<?>... classes) {
Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(classes, "Classes array cannot be null");
if (classes.length == 0) {
@ -210,8 +210,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
* @param key the key
* @param classes the classes
*/
public final void disallowEntityClass(ResourceLocation key, Class<?>... classes) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
public final void disallowEntityClass(Identifier key, Class<?>... classes) {
Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(classes, "Classes array cannot be null");
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
@ -227,8 +227,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
* @param key the key
* @param dataProvider the data provider
*/
public <T extends ISyncData<?>> void bindDataProvider(ResourceLocation key, DataProvider<Entity, T> dataProvider) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
public <T extends ISyncData<?>> void bindDataProvider(Identifier key, DataProvider<Entity, T> dataProvider) {
Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(dataProvider, "Data provider cannot be null");
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
@ -247,7 +247,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
* @param key the key
* @param getter the data getter function
*/
public <T extends ISyncData<?>> void bindDataGetter(ResourceLocation key, @NotNull Function<Entity, Optional<T>> getter) {
public <T extends ISyncData<?>> void bindDataGetter(Identifier key, @NotNull Function<Entity, Optional<T>> getter) {
bindDataProvider(key, getter::apply);
}
@ -256,8 +256,8 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
*
* @param key the key
*/
public void unbindDataProvider(ResourceLocation key) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
public void unbindDataProvider(Identifier key) {
Objects.requireNonNull(key, "Identifier 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(ResourceLocation key) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
public void clearAllowedEntityClasses(Identifier key) {
Objects.requireNonNull(key, "Identifier 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(ResourceLocation key, Class<?> entityClass) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
public boolean isEntityClassAllowed(Identifier key, Class<?> entityClass) {
Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(entityClass, "Entity class cannot be null");
TypedSyncEntry<?, ?> entry = getTypedEntries().get(key);
@ -311,7 +311,7 @@ public abstract class SyncData2Manager<V extends SyncData2Manager.TypedSyncEntry
* @param managerId the manager id
*/
@SuppressWarnings("unchecked")
public void trackEntityForManager(Entity entity, ResourceLocation managerId) {
public void trackEntityForManager(Entity entity, Identifier 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, ResourceLocation managerId) {
public void untrackEntityForManager(Entity entity, Identifier 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 (ResourceLocation id : getRegisteredKeys()) {
for (Identifier 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, ResourceLocation managerId) {
public void untrackEntitiesForManager(@NotNull Iterable<Entity> entities, Identifier 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(ResourceLocation managerId) {
public void clearAllTrackedData(Identifier 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 (ResourceLocation id : getRegisteredKeys()) {
for (Identifier 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(
ResourceLocation id,
Identifier 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<ResourceLocation> getRegisteredKeys() {
public Set<Identifier> 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<ResourceLocation, ISyncManager<?,?>> consumer) {
public void forEach(BiConsumer<Identifier, 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(ResourceLocation key) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
public void removeManager(Identifier key) {
Objects.requireNonNull(key, "Identifier key cannot be null");
getTypedEntries().remove(key);
}
}

View File

@ -1,7 +1,7 @@
package top.r3944realms.lib39.example.content.data;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
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(ResourceLocation id) {
protected AbstractedTestSyncData(Identifier id) {
super(id);
}

View File

@ -14,6 +14,7 @@ import top.r3944realms.lib39.content.item.DollItem;
import top.r3944realms.lib39.util.GameProfileHelper;
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.concurrent.atomic.AtomicReference;
@ -26,40 +27,27 @@ import java.util.concurrent.atomic.AtomicReference;
@Mixin(value = CarriedObjectRender.class, remap = false)
public class MixinCarriedObjectRender {
@ModifyVariable(
method = "drawFirstPersonBlock",
method = "drawBlock",
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"
)
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
)
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()));
private static ItemStack modifyRenderStack(ItemStack renderStack, @Local(argsOnly = true) Player player) {
if (renderStack.getItem() instanceof DollItem) {
CarryOnData carry = CarryOnDataManager.getCarryData(player);
if (carry != null) {
var compound = carry.getNbt().getCompound("tile");
var profileHolder = new AtomicReference<GameProfile>();
NBTReader.ofOpt(compound).gameProfile("profile", profileHolder::set);
if (profileHolder.get() != null) {
GameProfileHelper.saveProfileToItemStack(renderStack, new ResolvableProfile(profileHolder.get()));
}
}
}
return stack;
}
@ModifyVariable(
method = "drawThirdPerson",
at = @At(
value = "LOAD",
target = "Ltschipp/carryon/client/render/CarryRenderHelper;renderBakedModel(Lnet/minecraft/world/item/ItemStack;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/resources/model/BakedModel;)V"
)
)
private static ItemStack warpDollItem$2(ItemStack tileItem, @Local(ordinal = 0) Player player) {
if (tileItem.getItem() instanceof DollItem) {
CompoundTag compound = CarryOnDataManager.getCarryData(player).getNbt().getCompound("tile");
AtomicReference<GameProfile> gameProfileAtomicReference = new AtomicReference<>();
NBTReader.of(compound).gameProfile("profile", gameProfileAtomicReference::set);
if (gameProfileAtomicReference.get() != null) {
GameProfileHelper.saveProfileToItemStack(tileItem, new ResolvableProfile(gameProfileAtomicReference.get()));
}
}
return tileItem;
return renderStack;
}
}

View File

@ -7,12 +7,8 @@ import com.mojang.authlib.properties.Property;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.Services;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ResolvableProfile;
@ -20,33 +16,28 @@ import net.minecraft.world.level.block.entity.SkullBlockEntity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.util.nbt.NBTReader;
import top.r3944realms.lib39.util.nbt.NBTWriter;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicReference;
/**
* The type GameProfile helper.
*/
public class GameProfileHelper {
/**
* 异步获取 GameProfile通过玩家名
* 直接复用 SkullBlockEntity 的实现
* 获取 GameProfile通过玩家名
*/
public static CompletableFuture<Optional<GameProfile>> fetchGameProfileByName(String name) {
return SkullBlockEntity.fetchGameProfile(name);
public static ResolvableProfile fetchGameProfileByName(String name) {
return ResolvableProfile.createUnresolved(name);
}
/**
* 异步获取 GameProfile通过 UUID
* 获取 GameProfile通过 UUID
* 直接复用 SkullBlockEntity 的实现
*/
public static CompletableFuture<Optional<GameProfile>> fetchGameProfileByUUID(UUID uuid) {
return SkullBlockEntity.fetchGameProfile(uuid);
public static ResolvableProfile fetchGameProfileByUUID(UUID uuid) {
return ResolvableProfile.createUnresolved(uuid);
}
/**
@ -93,7 +84,7 @@ public class GameProfileHelper {
* @param gameProfile the game profile
* @return the resource location
*/
public static @NotNull ResourceLocation resolveSkinTexture(@NotNull GameProfile gameProfile) {
public static @NotNull Identifier resolveSkinTexture(@NotNull GameProfile gameProfile) {
return IClientOnly.check(() ->
Minecraft.getInstance().getSkinManager()
.getInsecureSkin(gameProfile)).texture();
@ -105,7 +96,7 @@ public class GameProfileHelper {
* @param gameProfile the game profile
* @return the skin texture
*/
public static ResourceLocation getSkinTexture(@Nullable GameProfile gameProfile) {
public static Identifier getSkinTexture(@Nullable GameProfile gameProfile) {
return IClientOnly.check(() -> {
if (gameProfile == null) {
return Lib39.mrl("textures/entity/player/wide/steve.png");
@ -162,7 +153,7 @@ public class GameProfileHelper {
* @param gameProfile the game profile
* @return the skin texture
*/
public static ResourceLocation getSkinTexture(@Nullable GameProfile gameProfile) {
public static Identifier getSkinTexture(@Nullable GameProfile gameProfile) {
return ClientOpt.getSkinTexture(gameProfile);
}
@ -173,7 +164,7 @@ public class GameProfileHelper {
* @param gameProfile the game profile
* @return the resource location
*/
public static @NotNull ResourceLocation resolveSkinTexture(@NotNull GameProfile gameProfile) {
public static @NotNull Identifier resolveSkinTexture(@NotNull GameProfile gameProfile) {
return ClientOpt.resolveSkinTexture(gameProfile);
}

View File

@ -145,7 +145,10 @@ public class MathUtil {
* @return the direction
*/
public static Direction getDirection(BlockPos from, BlockPos to) {
return Direction.fromDelta(from.getX() - to.getX(), from.getY() - to.getY(), from.getZ() - to.getZ());
int dx = from.getX() - to.getX();
int dy = from.getY() - to.getY();
int dz = from.getZ() - to.getZ();
return Direction.getNearest(dx, dy, dz, null);
}
private static final Int2DoubleMap FACTORIAL_CACHE = new Int2DoubleOpenHashMap();

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.util;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
@ -268,7 +268,7 @@ public class PlantHelper {
* @return the texture rl
*/
@Contract("_ -> new")
public static @NotNull ResourceLocation getTextureRL(@NotNull Plant plant) {
public static @NotNull Identifier getTextureRL(@NotNull Plant plant) {
return Lib39.mrl("block/" + plant.name);
}
@ -279,7 +279,7 @@ public class PlantHelper {
* @return the directly texture rl
*/
@Contract("_ -> new")
public static @NotNull ResourceLocation getDirectlyTextureRL(@NotNull Plant plant) {
public static @NotNull Identifier getDirectlyTextureRL(@NotNull Plant plant) {
return Lib39.mrl("textures/block/" + plant.name + ".png");
}
}

View File

@ -20,9 +20,12 @@ import com.mojang.authlib.properties.Property;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NonNull;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Consumer;
@ -47,24 +50,33 @@ public class NBTReader {
public static NBTReader of(@NotNull CompoundTag nbt) {
return new NBTReader(nbt);
}
/**
* String nbt reader.
* 从CompoundTag创建读取器
*
* @param key the key
* @param setter the setter
* @param nbt the nbt opt
* @return the nbt reader
*/
// 基本读取方法 - 直接赋值给成员变量
public NBTReader string(String key, Consumer<String> setter) {
if (nbt.contains(key)) {
setter.accept(nbt.getString(key));
@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;
}
}
return this;
return true;
}
/**
* String nbt reader.
* String nbt reader with default value.
*
* @param key the key
* @param setter the setter
@ -72,7 +84,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader string(String key, @NotNull Consumer<String> setter, String defaultValue) {
setter.accept(nbt.contains(key) ? nbt.getString(key) : defaultValue);
if (nbt.contains(key)) {
Optional<String> value = nbt.getString(key);
if (checkOpt(value)) {
setter.accept(value.get());
return this;
}
}
setter.accept(defaultValue);
return this;
}
@ -85,13 +104,14 @@ public class NBTReader {
*/
public NBTReader byteValue(String key, Consumer<Byte> setter) {
if (nbt.contains(key)) {
setter.accept(nbt.getByte(key));
Optional<Byte> value = nbt.getByte(key);
if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
* Byte value nbt reader.
* Byte value nbt reader with default value.
*
* @param key the key
* @param setter the setter
@ -99,7 +119,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader byteValue(String key, @NotNull Consumer<Byte> setter, byte defaultValue) {
setter.accept(nbt.contains(key) ? nbt.getByte(key) : defaultValue);
if (nbt.contains(key)) {
Optional<Byte> value = nbt.getByte(key);
if (checkOpt(value)) {
setter.accept(value.get());
return this;
}
}
setter.accept(defaultValue);
return this;
}
@ -112,13 +139,14 @@ public class NBTReader {
*/
public NBTReader shortValue(String key, Consumer<Short> setter) {
if (nbt.contains(key)) {
setter.accept(nbt.getShort(key));
Optional<Short> value = nbt.getShort(key);
if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
* Short value nbt reader.
* Short value nbt reader with default value.
*
* @param key the key
* @param setter the setter
@ -126,7 +154,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader shortValue(String key, @NotNull Consumer<Short> setter, short defaultValue) {
setter.accept(nbt.contains(key) ? nbt.getShort(key) : defaultValue);
if (nbt.contains(key)) {
Optional<Short> value = nbt.getShort(key);
if (checkOpt(value)) {
setter.accept(value.get());
return this;
}
}
setter.accept(defaultValue);
return this;
}
@ -139,13 +174,14 @@ public class NBTReader {
*/
public NBTReader intValue(String key, Consumer<Integer> setter) {
if (nbt.contains(key)) {
setter.accept(nbt.getInt(key));
Optional<Integer> value = nbt.getInt(key);
if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
* Int value nbt reader.
* Int value nbt reader with default value.
*
* @param key the key
* @param setter the setter
@ -153,7 +189,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader intValue(String key, @NotNull Consumer<Integer> setter, int defaultValue) {
setter.accept(nbt.contains(key) ? nbt.getInt(key) : defaultValue);
if (nbt.contains(key)) {
Optional<Integer> value = nbt.getInt(key);
if (checkOpt(value)) {
setter.accept(value.get());
return this;
}
}
setter.accept(defaultValue);
return this;
}
@ -166,13 +209,14 @@ public class NBTReader {
*/
public NBTReader longValue(String key, Consumer<Long> setter) {
if (nbt.contains(key)) {
setter.accept(nbt.getLong(key));
Optional<Long> value = nbt.getLong(key);
if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
* Long value nbt reader.
* Long value nbt reader with default value.
*
* @param key the key
* @param setter the setter
@ -180,7 +224,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader longValue(String key, @NotNull Consumer<Long> setter, long defaultValue) {
setter.accept(nbt.contains(key) ? nbt.getLong(key) : defaultValue);
if (nbt.contains(key)) {
Optional<Long> value = nbt.getLong(key);
if (checkOpt(value)) {
setter.accept(value.get());
return this;
}
}
setter.accept(defaultValue);
return this;
}
@ -193,13 +244,14 @@ public class NBTReader {
*/
public NBTReader floatValue(String key, Consumer<Float> setter) {
if (nbt.contains(key)) {
setter.accept(nbt.getFloat(key));
Optional<Float> value = nbt.getFloat(key);
if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
* Float value nbt reader.
* Float value nbt reader with default value.
*
* @param key the key
* @param setter the setter
@ -207,7 +259,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader floatValue(String key, @NotNull Consumer<Float> setter, float defaultValue) {
setter.accept(nbt.contains(key) ? nbt.getFloat(key) : defaultValue);
if (nbt.contains(key)) {
Optional<Float> value = nbt.getFloat(key);
if (checkOpt(value)) {
setter.accept(value.get());
return this;
}
}
setter.accept(defaultValue);
return this;
}
@ -220,13 +279,14 @@ public class NBTReader {
*/
public NBTReader doubleValue(String key, Consumer<Double> setter) {
if (nbt.contains(key)) {
setter.accept(nbt.getDouble(key));
Optional<Double> value = nbt.getDouble(key);
if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
* Double value nbt reader.
* Double value nbt reader with default value.
*
* @param key the key
* @param setter the setter
@ -234,7 +294,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader doubleValue(String key, @NotNull Consumer<Double> setter, double defaultValue) {
setter.accept(nbt.contains(key) ? nbt.getDouble(key) : defaultValue);
if (nbt.contains(key)) {
Optional<Double> value = nbt.getDouble(key);
if (checkOpt(value)) {
setter.accept(value.get());
return this;
}
}
setter.accept(defaultValue);
return this;
}
@ -247,13 +314,14 @@ public class NBTReader {
*/
public NBTReader booleanValue(String key, Consumer<Boolean> setter) {
if (nbt.contains(key)) {
setter.accept(nbt.getBoolean(key));
Optional<Boolean> value = nbt.getBoolean(key);
if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
* Boolean value nbt reader.
* Boolean value nbt reader with default value.
*
* @param key the key
* @param setter the setter
@ -261,7 +329,14 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader booleanValue(String key, @NotNull Consumer<Boolean> setter, boolean defaultValue) {
setter.accept(nbt.contains(key) ? nbt.getBoolean(key) : defaultValue);
if (nbt.contains(key)) {
Optional<Boolean> value = nbt.getBoolean(key);
if (checkOpt(value)) {
setter.accept(value.get());
return this;
}
}
setter.accept(defaultValue);
return this;
}
@ -272,10 +347,10 @@ public class NBTReader {
* @param setter the setter
* @return the nbt reader
*/
// 数组类型
public NBTReader byteArray(String key, Consumer<byte[]> setter) {
if (nbt.contains(key)) {
setter.accept(nbt.getByteArray(key));
Optional<byte[]> value = nbt.getByteArray(key);
if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
@ -289,7 +364,8 @@ public class NBTReader {
*/
public NBTReader intArray(String key, Consumer<int[]> setter) {
if (nbt.contains(key)) {
setter.accept(nbt.getIntArray(key));
Optional<int[]> value = nbt.getIntArray(key);
if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
@ -303,39 +379,12 @@ public class NBTReader {
*/
public NBTReader longArray(String key, Consumer<long[]> setter) {
if (nbt.contains(key)) {
setter.accept(nbt.getLongArray(key));
Optional<long[]> value = nbt.getLongArray(key);
if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
* Uuid nbt reader.
*
* @param key the key
* @param setter the setter
* @return the nbt reader
*/
// UUID
public NBTReader uuid(String key, Consumer<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.
*
@ -343,16 +392,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)) {
setter.accept(nbt.getCompound(key));
Optional<CompoundTag> value = nbt.getCompound(key);
if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
* Compound nbt reader.
* Compound nbt reader with default value.
*
* @param key the key
* @param setter the setter
@ -360,58 +409,10 @@ public class NBTReader {
* @return the nbt reader
*/
public NBTReader compound(String key, @NotNull Consumer<CompoundTag> setter, CompoundTag defaultValue) {
setter.accept(nbt.contains(key) ? nbt.getCompound(key) : defaultValue);
return this;
}
/**
* List nbt reader.
*
* @param key the key
* @param type the type
* @param setter the setter
* @return the nbt reader
*/
// ListTag
public NBTReader list(String key, int type, Consumer<ListTag> setter) {
if (nbt.contains(key)) {
setter.accept(nbt.getList(key, type));
}
return this;
}
/**
* Game profile nbt reader.
*
* @param key the key
* @param setter the setter
* @return the nbt reader
*/
public NBTReader gameProfile(String key, Consumer<GameProfile> setter) {
if (nbt.contains(key, CompoundTag.TAG_COMPOUND)) {
CompoundTag tag = nbt.getCompound(key);
GameProfile profile = readGameProfileFromTag(tag);
if (profile != null) {
setter.accept(profile);
}
}
return this;
}
/**
* Game profile nbt reader with default value.
*
* @param key the key
* @param setter the setter
* @param defaultValue the default value
* @return the nbt reader
*/
public NBTReader gameProfile(String key, Consumer<GameProfile> setter, GameProfile defaultValue) {
if (nbt.contains(key, CompoundTag.TAG_COMPOUND)) {
CompoundTag tag = nbt.getCompound(key);
GameProfile profile = readGameProfileFromTag(tag);
if (profile != null) {
setter.accept(profile);
Optional<CompoundTag> value = nbt.getCompound(key);
if (checkOpt(value)) {
setter.accept(value.get());
return this;
}
}
@ -420,83 +421,19 @@ public class NBTReader {
}
/**
* Read GameProfile from CompoundTag.
* List nbt reader.
*
* @param tag the tag
* @return the game profile, or null if invalid
* @param key the key
* @param setter the setter
* @return the nbt reader
*/
@Nullable
private static GameProfile readGameProfileFromTag(@NotNull CompoundTag tag) {
String name = null;
UUID uuid = null;
// 支持 "Name" "name"
if (tag.contains("Name", CompoundTag.TAG_STRING)) {
name = tag.getString("Name");
} else if (tag.contains("name", CompoundTag.TAG_STRING)) {
name = tag.getString("name");
}
// 支持 "Id" "id"
if (tag.hasUUID("Id")) {
uuid = tag.getUUID("Id");
} else if (tag.hasUUID("id")) {
uuid = tag.getUUID("id");
}
try {
GameProfile profile = new GameProfile(uuid, name);
// 支持 "Properties" "properties"支持 COMPOUND LIST 格式
String propertiesKey = tag.contains("Properties", CompoundTag.TAG_COMPOUND) ? "Properties"
: (tag.contains("properties", CompoundTag.TAG_COMPOUND) ? "properties" : null);
// 如果没有 COMPOUND尝试 LIST 格式
if (propertiesKey == null) {
String listKey = tag.contains("Properties", CompoundTag.TAG_LIST) ? "Properties"
: (tag.contains("properties", CompoundTag.TAG_LIST) ? "properties" : null);
if (listKey != null) {
ListTag propertiesList = tag.getList(listKey, CompoundTag.TAG_COMPOUND);
for (int i = 0; i < propertiesList.size(); i++) {
CompoundTag propTag = propertiesList.getCompound(i);
String propName = propTag.getString("name");
String value = propTag.getString("value");
String signature = propTag.contains("signature") ? propTag.getString("signature") : null;
if (signature != null) {
profile.getProperties().put(propName, new Property(propName, value, signature));
} else {
profile.getProperties().put(propName, new Property(propName, value));
}
}
return profile;
}
}
// COMPOUND 格式处理
if (propertiesKey != null && tag.contains(propertiesKey, CompoundTag.TAG_COMPOUND)) {
CompoundTag propertiesTag = tag.getCompound(propertiesKey);
for (String key : propertiesTag.getAllKeys()) {
ListTag listTag = propertiesTag.getList(key, CompoundTag.TAG_COMPOUND);
for (int i = 0; i < listTag.size(); i++) {
CompoundTag propTag = listTag.getCompound(i);
String value = propTag.getString("Value");
String signature = propTag.contains("Signature") ? propTag.getString("Signature") : null;
if (signature != null) {
profile.getProperties().put(key, new Property(key, value, signature));
} else {
profile.getProperties().put(key, new Property(key, value));
}
}
}
}
return profile;
} catch (Throwable e) {
return null;
public NBTReader list(String key, Consumer<ListTag> setter) {
if (nbt.contains(key)) {
Optional<ListTag> value = nbt.getList(key);
if (checkOpt(value)) setter.accept(value.get());
}
return this;
}
/**
* Vec 3 nbt reader.
*
@ -504,23 +441,31 @@ public class NBTReader {
* @param setter the setter
* @return the nbt reader
*/
// Vec3支持
public NBTReader vec3(String key, Consumer<Vec3> setter) {
if (nbt.contains(key)) {
CompoundTag vecTag = nbt.getCompound(key);
if (vecTag.contains("X") && vecTag.contains("Y") && vecTag.contains("Z")) {
setter.accept(new Vec3(
vecTag.getDouble("X"),
vecTag.getDouble("Y"),
vecTag.getDouble("Z")
));
Optional<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;
}
/**
* Vec 3 nbt reader.
* Vec 3 nbt reader with default value.
*
* @param key the key
* @param setter the setter
@ -529,14 +474,23 @@ public class NBTReader {
*/
public NBTReader vec3(String key, Consumer<Vec3> setter, Vec3 defaultValue) {
if (nbt.contains(key)) {
CompoundTag vecTag = nbt.getCompound(key);
if (vecTag.contains("X") && vecTag.contains("Y") && vecTag.contains("Z")) {
setter.accept(new Vec3(
vecTag.getDouble("X"),
vecTag.getDouble("Y"),
vecTag.getDouble("Z")
));
return this;
Optional<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;
}
}
}
}
setter.accept(defaultValue);
@ -552,21 +506,24 @@ 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)) {
String value = nbt.getString(key);
try {
setter.accept(Enum.valueOf(enumClass, value.toUpperCase()));
} catch (IllegalArgumentException ignored) {
// 保持setter的当前值
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的当前值
}
}
}
return this;
}
/**
* Enum value nbt reader.
* Enum value nbt reader with default value.
*
* @param <T> the type parameter
* @param key the key
@ -577,18 +534,21 @@ public class NBTReader {
*/
public <T extends Enum<T>> NBTReader enumValue(String key, Class<T> enumClass, Consumer<T> setter, T defaultValue) {
if (nbt.contains(key)) {
String value = nbt.getString(key);
try {
setter.accept(Enum.valueOf(enumClass, value.toUpperCase()));
return this;
} catch (IllegalArgumentException ignored) {
Optional<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的当前值
}
}
}
setter.accept(defaultValue);
return this;
}
/**
* Nested nbt reader.
*
@ -596,16 +556,18 @@ public class NBTReader {
* @param consumer the consumer
* @return the nbt reader
*/
// 嵌套读取支持
public NBTReader nested(String key, Consumer<NBTReader> consumer) {
if (nbt.contains(key)) {
consumer.accept(new NBTReader(nbt.getCompound(key)));
Optional<CompoundTag> compound = nbt.getCompound(key);
if (checkOpt(compound)) {
consumer.accept(new NBTReader(compound.get()));
}
}
return this;
}
/**
* Nested nbt reader.
* Nested nbt reader with orElse.
*
* @param key the key
* @param consumer the consumer
@ -614,7 +576,10 @@ public class NBTReader {
*/
public NBTReader nested(String key, Consumer<NBTReader> consumer, Runnable orElse) {
if (nbt.contains(key)) {
consumer.accept(new NBTReader(nbt.getCompound(key)));
Optional<CompoundTag> compound = nbt.getCompound(key);
if (checkOpt(compound)) {
consumer.accept(new NBTReader(compound.get()));
}
} else {
orElse.run();
}
@ -628,7 +593,6 @@ public class NBTReader {
* @param action the action
* @return the nbt reader
*/
// 条件读取
public NBTReader ifPresent(String key, Runnable action) {
if (nbt.contains(key)) {
action.run();
@ -655,7 +619,6 @@ public class NBTReader {
*
* @return the raw
*/
// 获取原始NBT
@NotNull
public CompoundTag getRaw() {
return nbt;
@ -667,14 +630,20 @@ public class NBTReader {
* @param nbt the nbt
* @return the vec 3
*/
// 便捷的静态方法保持原有功能
@NotNull
public static Vec3 readVec3(@NotNull CompoundTag nbt) {
if (nbt.contains("X") && nbt.contains("Y") && nbt.contains("Z")) {
return new Vec3(
nbt.getDouble("X"),
nbt.getDouble("Y"),
nbt.getDouble("Z")
Optional<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."
);
} else {
throw new IllegalArgumentException("NBT is missing X, Y, or Z value for Vec3");
@ -690,11 +659,16 @@ public class NBTReader {
@Nullable
public static Vec3 readVec3Safe(@NotNull CompoundTag nbt) {
if (nbt.contains("X") && nbt.contains("Y") && nbt.contains("Z")) {
return new Vec3(
nbt.getDouble("X"),
nbt.getDouble("Y"),
nbt.getDouble("Z")
);
Optional<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 null;
}

View File

@ -397,47 +397,15 @@ public class NBTWriter {
}
return this;
}
/**
* Uuid nbt writer.
*
* @param key the key
* @param value the value
* @return the nbt writer
*/
// UUID支持
public NBTWriter uuid(String key, UUID value) {
if (value != null) {
root.putUUID(key, value);
}
return this;
}
/**
* Uuid nbt writer.
*
* @param key the key
* @param value the value
* @param defaultValue the default value
* @return the nbt writer
*/
public NBTWriter uuid(String key, UUID value, UUID defaultValue) {
if (value != null) {
root.putUUID(key, value);
} else if (defaultValue != null) {
root.putUUID(key, defaultValue);
}
return this;
}
/**
* Compound nbt writer.
* 嵌套CompoundTag
*
* @param key the key
* @param consumer the consumer
* @return the nbt writer
*/
// 嵌套CompoundTag
public NBTWriter compound(String key, Consumer<NBTWriter> consumer) {
if (consumer != null) {
NBTWriter nestedBuilder = new NBTWriter();
@ -496,12 +464,12 @@ public class NBTWriter {
/**
* List nbt writer.
* ListTag支持
*
* @param key the key
* @param consumer the consumer
* @return the nbt writer
*/
// ListTag支持
public NBTWriter list(String key, Consumer<ListNBTBuilder> consumer) {
if (consumer != null) {
ListNBTBuilder listBuilder = new ListNBTBuilder();
@ -572,60 +540,6 @@ public class NBTWriter {
return this;
}
/**
* Game profile nbt writer.
*
* @param key the key
* @param profile the profile
* @return the nbt writer
*/
public NBTWriter gameProfile(String key, @NotNull GameProfile profile) {
root.put(key, writeGameProfile(profile));
return this;
}
private CompoundTag writeGameProfile(@NotNull GameProfile profile) {
CompoundTag tag = new CompoundTag();
if (!StringUtil.isNullOrEmpty(profile.getName())) {
tag.putString("Name", profile.getName());
}
if (profile.getId() != null) {
tag.putUUID("Id", profile.getId());
}
if (!profile.getProperties().isEmpty()) {
CompoundTag compoundTag = new CompoundTag();
for(String keySet : profile.getProperties().keySet()) {
ListTag propListTag = new ListTag();
for(Property property : profile.getProperties().get(keySet)) {
CompoundTag propTag = new CompoundTag();
propTag.putString("Value", property.value());
if (property.hasSignature()) {
propTag.putString("Signature", property.signature());
}
propListTag.add(propTag);
}
compoundTag.put(keySet, propListTag);
}
tag.put("Properties", compoundTag);
}
return tag;
}
/**
* GameProfile if nbt writer.
*
* @param key the key
* @param condition the condition
* @param value the value
* @return the nbt writer
*/
public NBTWriter gameProfileIf(String key, boolean condition, Supplier<GameProfile> value) {
if (condition && value != null) {
root.put(key, writeGameProfile(value.get()));
}
return this;
}
/**
* String if nbt writer.
*
@ -671,21 +585,6 @@ public class NBTWriter {
return this;
}
/**
* Uuid value if nbt writer.
*
* @param key the key
* @param condition the condition
* @param value the value
* @return the nbt writer
*/
public NBTWriter uuidValueIf(String key, boolean condition, Supplier<UUID> value) {
if (condition && value != null) {
root.putUUID(key, value.get());
}
return this;
}
/**
* Boolean value if nbt writer.
*
@ -1162,7 +1061,7 @@ public class NBTWriter {
* @return the all keys
*/
public java.util.Set<String> getAllKeys() {
return root.getAllKeys();
return root.keySet();
}
/**

View File

@ -1,7 +1,7 @@
package top.r3944realms.lib39.util.resolve;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.EntityType;
import org.jetbrains.annotations.NotNull;
@ -141,14 +141,14 @@ public abstract class EntityListResolve {
*/
@SuppressWarnings("deprecation")
public boolean isEntityInList(EntityType<?> type) {
String entityId = type.builtInRegistryHolder().key().location().toString();
String entityId = type.builtInRegistryHolder().key().identifier().toString();
String modId = entityId.split(":")[0];
for (String rs : result.entityList) {
if (rs.equals(entityId)) return true;
}
for(String rs : result.tagList) {
String body = rs.substring(1);
ResourceLocation tagId = Lib39.rl(body);
Identifier tagId = Lib39.rl(body);
TagKey<EntityType<?>> tag = TagKey.create(Registries.ENTITY_TYPE, tagId);
if (type.builtInRegistryHolder().is(tag)) return true;
}

View File

@ -1,7 +1,7 @@
package top.r3944realms.lib39.util.resolve;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.EntityType;
import org.jetbrains.annotations.NotNull;
@ -153,7 +153,7 @@ public abstract class EntityMapResolve<T> {
*/
@SuppressWarnings("deprecation")
private EntityMatchResult<T> findEntityMatch(EntityType<?> type) {
String entityId = type.builtInRegistryHolder().key().location().toString();
String entityId = type.builtInRegistryHolder().key().identifier().toString();
String modId = entityId.split(":")[0];
// 检查实体ID匹配
@ -166,7 +166,7 @@ public abstract class EntityMapResolve<T> {
// 检查标签匹配
for (String rs : result.tagMap.keySet()) {
String body = rs.startsWith("#") ? rs.substring(1) : rs;
ResourceLocation tagId = Lib39.rl(body);
Identifier tagId = Lib39.rl(body);
TagKey<EntityType<?>> tag = TagKey.create(Registries.ENTITY_TYPE, tagId);
if (type.builtInRegistryHolder().is(tag)) {
return new EntityMatchResult<>(EntityResolveResult.Type.TAG, rs, result.tagMap.get(rs));

View File

@ -75,7 +75,7 @@ public class RidingApplier {
if (RidingValidator.wouldCreateCycle(entity, vehicle)) {
throw new RidingCycleException(entityId, vehicleId);
}
boolean success = entity.startRiding(vehicle, true);
boolean success = entity.startRiding(vehicle, true, true);
if (!success) {
Lib39.LOGGER.error("Failed to mount entity {} to vehicle {}", entityId, vehicleId);
}

View File

@ -16,12 +16,11 @@ import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.npc.VillagerDataHolder;
import net.minecraft.world.entity.npc.VillagerTrades;
import net.minecraft.world.entity.npc.VillagerType;
import net.minecraft.world.entity.npc.villager.VillagerDataHolder;
import net.minecraft.world.entity.npc.villager.VillagerTrades;
import net.minecraft.world.entity.npc.villager.VillagerType;
import net.minecraft.world.item.*;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionBrewing;
import net.minecraft.world.item.alchemy.PotionContents;
import net.minecraft.world.item.component.DyedItemColor;
import net.minecraft.world.item.component.SuspiciousStewEffects;
@ -42,7 +41,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* 村民交易构建器

View File

@ -6,7 +6,7 @@ import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import top.r3944realms.lib39.core.command.ICommandHelpManager;
import top.r3944realms.lib39.core.command.model.CommandNode;
import top.r3944realms.lib39.core.command.model.CommandPath;
@ -50,7 +50,7 @@ public interface RegisterCommandHelpCallback {
*
* @return the id
*/
ResourceLocation getID();
Identifier getID();
/**
* Add child.
@ -103,7 +103,7 @@ public interface RegisterCommandHelpCallback {
*/
record CommandHelpRegistrar(LiteralArgumentBuilder<CommandSourceStack> builder, ICommandHelpManager helpManager, CommandBuildContext context) implements Registrar {
@Override
public ResourceLocation getID() {
public Identifier getID() {
return helpManager.getID();
}

View File

@ -3,7 +3,7 @@ package top.r3944realms.lib39.api.callback;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.core.sync.ISyncData;
@ -62,7 +62,7 @@ public interface SyncManagerRegisterCallback {
* @param dataClass the data class
*/
<T extends ISyncData<?>> void register(
ResourceLocation id,
Identifier 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(ResourceLocation id, Class<?>... entityClasses);
void allowEntityClass(Identifier id, Class<?>... entityClasses);
/**
* 移除允许的实体类
@ -81,7 +81,7 @@ public interface SyncManagerRegisterCallback {
* @param id the id
* @param entityClasses the entity classes
*/
void disallowEntityClass(ResourceLocation id, Class<?>... entityClasses);
void disallowEntityClass(Identifier id, Class<?>... entityClasses);
/**
* 绑定 EntityApiLookup用于分离注册的情况
@ -91,7 +91,7 @@ public interface SyncManagerRegisterCallback {
* @param apiLookup the EntityApiLookup
*/
<T extends ISyncData<?>> void bindApiLookup(
ResourceLocation id,
Identifier 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(ResourceLocation id);
void unbindApiLookup(Identifier id);
/**
* 完整的类型安全注册
@ -112,7 +112,7 @@ public interface SyncManagerRegisterCallback {
* @param allowedEntityClasses the allowed entity classes
*/
default <T extends ISyncData<?>> void registerComplete(
ResourceLocation id,
Identifier 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 ResourceLocation id,
@NotNull Identifier id,
@NotNull ISyncManager<Entity, T> syncManager,
@NotNull Class<T> dataClass
) {
@ -140,25 +140,25 @@ public interface SyncManagerRegisterCallback {
}
@Override
public void allowEntityClass(@NotNull ResourceLocation id, @NotNull Class<?>... entityClasses) {
public void allowEntityClass(@NotNull Identifier id, @NotNull Class<?>... entityClasses) {
manager.allowEntityClass(id, entityClasses);
}
@Override
public void disallowEntityClass(@NotNull ResourceLocation id, @NotNull Class<?>... entityClasses) {
public void disallowEntityClass(@NotNull Identifier id, @NotNull Class<?>... entityClasses) {
manager.disallowEntityClass(id, entityClasses);
}
@Override
public <T extends ISyncData<?>> void bindApiLookup(
@NotNull ResourceLocation id,
@NotNull Identifier id,
@NotNull EntityApiLookup<T, Void> apiLookup
) {
manager.bindApiLookup(id, apiLookup);
}
@Override
public void unbindApiLookup(@NotNull ResourceLocation id) {
public void unbindApiLookup(@NotNull Identifier id) {
manager.unbindApiLookup(id);
}
}

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.base.compat.jade;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import snownee.jade.api.IWailaClientRegistration;
import snownee.jade.api.IWailaPlugin;
@ -18,7 +18,7 @@ public class FabricJadePlugin implements IWailaPlugin {
/**
* The constant UID.
*/
public static final ResourceLocation UID = Lib39.rl("lib39");
public static final Identifier UID = Lib39.rl("lib39");
@Override
public void registerClient(@NotNull IWailaClientRegistration registration) {

View File

@ -2,7 +2,7 @@ package top.r3944realms.lib39.base.compat.jade.provider;
import com.mojang.authlib.GameProfile;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import snownee.jade.api.BlockAccessor;
import snownee.jade.api.IBlockComponentProvider;
@ -16,7 +16,7 @@ import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
*/
public class FabricDollComponentProvider implements IBlockComponentProvider {
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return FabricJadePlugin.UID;
}

View File

@ -12,7 +12,7 @@ import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.Services;
import net.minecraft.server.level.ServerLevel;
@ -122,8 +122,8 @@ public class FabricCommonEventHandler {
public static void onServerTick(MinecraftServer server) {
if (syncData2Manager == null) return;
if (server.getTickCount() % 10 == 0)
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
}
/**
@ -135,7 +135,7 @@ public class FabricCommonEventHandler {
public static void onEntityJoinWorld(@NotNull Entity entity, ServerLevel level) {
if (entity.level().isClientSide) return;
for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
for (Identifier id : syncData2Manager.getRegisteredKeys()) {
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
syncData2Manager.trackEntityForManager(entity, id);
}
@ -151,7 +151,7 @@ public class FabricCommonEventHandler {
public static void onEntityLeaveWorld(@NotNull Entity entity, ServerLevel level) {
if (entity.level().isClientSide) return;
for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
for (Identifier id : syncData2Manager.getRegisteredKeys()) {
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
syncData2Manager.untrackEntityForManager(entity, id);
}

View File

@ -7,7 +7,7 @@ import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
@ -22,11 +22,11 @@ import java.util.Optional;
/**
* The type Sync nbt lookup data entity s 2 c payload.
*/
public record SyncNBTLookupDataEntityS2CPayload(int entityId, ResourceLocation id, CompoundTag data) implements CustomPacketPayload {
public record SyncNBTLookupDataEntityS2CPayload(int entityId, Identifier id, CompoundTag data) implements CustomPacketPayload {
/**
* The constant SYNC_NBT_LOOKUP_PACKET_ID.
*/
public static final ResourceLocation SYNC_NBT_LOOKUP_PACKET_ID =
public static final Identifier SYNC_NBT_LOOKUP_PACKET_ID =
Lib39.rl("sync_nbt_lookup_data_entity");
/**
* The constant TYPE.
@ -56,7 +56,7 @@ public record SyncNBTLookupDataEntityS2CPayload(int entityId, ResourceLocation i
* @param buf the buffer
*/
public SyncNBTLookupDataEntityS2CPayload(RegistryFriendlyByteBuf buf) {
this(buf.readInt(), buf.readResourceLocation(), buf.readNbt());
this(buf.readInt(), buf.readIdentifier(), buf.readNbt());
}
/**
@ -66,7 +66,7 @@ public record SyncNBTLookupDataEntityS2CPayload(int entityId, ResourceLocation i
*/
public void write(@NotNull FriendlyByteBuf friendlyByteBuf) {
friendlyByteBuf.writeInt(entityId);
friendlyByteBuf.writeResourceLocation(id);
friendlyByteBuf.writeIdentifier(id);
friendlyByteBuf.writeNbt(data);
}

View File

@ -2,7 +2,7 @@ package top.r3944realms.lib39.core.sync;
import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.Nullable;
@ -17,10 +17,10 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
/**
* The Typed entries.
*/
protected final Map<ResourceLocation, TypedSyncEntry<?>> typedEntries = Maps.newConcurrentMap();
protected final Map<Identifier, TypedSyncEntry<?>> typedEntries = Maps.newConcurrentMap();
@Override
protected Map<ResourceLocation, TypedSyncEntry<?>> getTypedEntries() {
protected Map<Identifier, 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(
ResourceLocation key,
Identifier key,
ISyncManager<Entity, T> manager,
Class<T> dataClass
) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(manager, "Sync manager cannot be null");
Objects.requireNonNull(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(ResourceLocation key, EntityApiLookup<T, Void> apiLookup) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
public <T extends ISyncData<?>> void bindApiLookup(Identifier key, EntityApiLookup<T, Void> apiLookup) {
Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(apiLookup, "EntityApiLookup cannot be null");
TypedSyncEntry<?> entry = typedEntries.get(key);
@ -94,8 +94,8 @@ public class SyncData2LookupManager extends SyncData2Manager<SyncData2LookupMana
*
* @param key the key
*/
public void unbindApiLookup(ResourceLocation key) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
public void unbindApiLookup(Identifier key) {
Objects.requireNonNull(key, "Identifier 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(
ResourceLocation id,
Identifier id,
TypedSyncEntry<?> entry,
EntityApiLookup<T, Void> newApiLookup
) {

View File

@ -1,7 +1,7 @@
package top.r3944realms.lib39.core.sync;
import net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.Nullable;
import top.r3944realms.lib39.core.event.FabricCommonEventHandler;
@ -25,7 +25,7 @@ public abstract class SyncLookupProvider<T extends NBTEntitySyncData> implements
*
* @return the id
*/
protected abstract ResourceLocation getId();
protected abstract Identifier getId();
@SuppressWarnings("unchecked")
@Override
public @Nullable T find(Entity entity, Void context) {

View File

@ -2,7 +2,7 @@ package top.r3944realms.lib39.example.content.data;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
@ -23,7 +23,7 @@ public class FabricTestSyncData extends AbstractedTestSyncData implements IFabri
/**
* The constant ID.
*/
public static final ResourceLocation ID = Lib39.rl(Lib39.MOD_ID, "test_sync_data");
public static final Identifier ID = Lib39.rl(Lib39.MOD_ID, "test_sync_data");
// NBT 键常量
private static final String NBT_KEY_STRING = "test_string";

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.example.content.data;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import top.r3944realms.lib39.core.sync.SyncLookupProvider;
@ -19,7 +19,7 @@ public class FabricTestSyncLookupProvider extends SyncLookupProvider<AbstractedT
}
@Override
protected ResourceLocation getId() {
protected Identifier getId() {
return FabricTestSyncData.ID;
}
}

View File

@ -1,7 +1,7 @@
package top.r3944realms.lib39.example.core.compat;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.core.compat.ICompat;
@ -20,7 +20,7 @@ public class FabricLib39Compat implements ICompat {
/**
* The constant ID.
*/
public static ResourceLocation ID = Lib39.rl("lib39");
public static Identifier ID = Lib39.rl("lib39");
@Override
public void setInitialize(boolean initialize) {
@ -33,7 +33,7 @@ public class FabricLib39Compat implements ICompat {
}
@Override
public ResourceLocation id() {
public Identifier id() {
return ID;
}

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.example.core.compat;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.core.compat.CompatManager;
import top.r3944realms.lib39.core.compat.ICompat;

View File

@ -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.ResourceLocation;
import net.minecraft.resources.Identifier;
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 ResourceLocation CLIENT_TEST_DATA =
public static final Identifier CLIENT_TEST_DATA =
Lib39.rl("client_test_data");
/**

View File

@ -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.ResourceLocation;
import net.minecraft.resources.Identifier;
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 ResourceLocation getID() {
public Identifier getID() {
return helpManager.getID();
}

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.api.event;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.neoforged.bus.api.Event;
import net.neoforged.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(
ResourceLocation id,
Identifier 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(ResourceLocation id) {
public void unregisterSyncManager(Identifier id) {
syncs2Manager.removeManager(id);
}
@ -67,7 +67,7 @@ public class SyncManagerRegisterEvent extends Event {
* @param id the id
* @param entityClasses the entity classes
*/
public final void addAllowEntityClass(ResourceLocation id, Class<?>... entityClasses) {
public final void addAllowEntityClass(Identifier id, Class<?>... entityClasses) {
syncs2Manager.allowEntityClass(id, entityClasses);
}
@ -77,7 +77,7 @@ public class SyncManagerRegisterEvent extends Event {
* @param id the id
* @param entityClasses the entity classes
*/
public final void removeAllowEntityClass(ResourceLocation id, Class<?>... entityClasses) {
public final void removeAllowEntityClass(Identifier id, Class<?>... entityClasses) {
syncs2Manager.disallowEntityClass(id, entityClasses);
}
@ -88,7 +88,7 @@ public class SyncManagerRegisterEvent extends Event {
* @param id 必须先注册安全同步管理器再绑定Cap否则会抛出{@link IllegalStateException 未找到对应安全同步管理器}
* @param capability the capability
*/
public <T extends ISyncData<?>> void bindCapability(ResourceLocation id, EntityCapability<T, Void> capability) {
public <T extends ISyncData<?>> void bindCapability(Identifier id, EntityCapability<T, Void> capability) {
syncs2Manager.bindCapability(id, capability);
}
@ -97,7 +97,7 @@ public class SyncManagerRegisterEvent extends Event {
*
* @param id the id
*/
public void unbindCapability(ResourceLocation id) {
public void unbindCapability(Identifier id) {
syncs2Manager.unbindCapability(id);
}
@ -112,7 +112,7 @@ public class SyncManagerRegisterEvent extends Event {
* @param allowedEntityClasses the allowed entity classes
*/
public <K, T extends ISyncData<?>> void registerComplete(
ResourceLocation id,
Identifier id,
ISyncManager<EntityCapability<T, Void>, T> syncManager,
EntityCapability<T, Void> capability,
Class<?>... allowedEntityClasses

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.base.compat.jade;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import snownee.jade.api.IWailaClientRegistration;
import snownee.jade.api.IWailaPlugin;
@ -17,7 +17,7 @@ public class NeoForgeJadePlugin implements IWailaPlugin {
/**
* The constant UID.
*/
public static final ResourceLocation UID = Lib39.rl("lib39");
public static final Identifier UID = Lib39.rl("lib39");
@Override
public void registerClient(@NotNull IWailaClientRegistration registration) {

View File

@ -2,7 +2,7 @@ package top.r3944realms.lib39.base.compat.jade.provider;
import com.mojang.authlib.GameProfile;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import snownee.jade.api.BlockAccessor;
import snownee.jade.api.IBlockComponentProvider;
@ -17,7 +17,7 @@ import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
*/
public class NeoForgeDollComponentProvider implements IBlockComponentProvider {
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return NeoForgeJadePlugin.UID;
}

View File

@ -44,37 +44,37 @@ public class Lib39BaseDataGenEvent {
}
private static void LanguageGenerator(@NotNull GatherDataEvent event, McLocale language) {
event.getGenerator().addProvider(
event.includeClient(),
true,
(DataProvider.Factory<SimpleLanguageProvider>) pOutput -> new SimpleLanguageProvider(pOutput, Lib39.MOD_ID ,language , Lib39LangKey.INSTANCE)
);
}
private static void ItemModelDataGenerate(@NotNull GatherDataEvent event) {
event.getGenerator().addProvider(
event.includeClient(),
true,
(DataProvider.Factory<Lib39ItemModelProvider>) pOutput -> new Lib39ItemModelProvider(pOutput, event.getExistingFileHelper())
);
}
private static void BlockModelDataGenerate(@NotNull GatherDataEvent event) {
event.getGenerator().addProvider(
event.includeClient(),
true,
(DataProvider.Factory<Lib39BlockModelProvider>) pOutput -> new Lib39BlockModelProvider(pOutput, event.getExistingFileHelper())
);
}
private static void BlockStateDataGenerate(@NotNull GatherDataEvent event) {
event.getGenerator().addProvider(
event.includeClient(),
true,
(DataProvider.Factory<Lib39BlockStatesProvider>) pOutput -> new Lib39BlockStatesProvider(pOutput, event.getExistingFileHelper())
);
}
private static void SoundDefinitionDataGenerate(@NotNull GatherDataEvent event) {
event.getGenerator().addProvider(
event.includeClient(),
true,
(DataProvider.Factory<Lib39SoundDefinitionsProvider>) pOutput -> new Lib39SoundDefinitionsProvider(pOutput, event.getExistingFileHelper())
);
}
private static void LootTableDataGenerate(@NotNull GatherDataEvent event) {
event.getGenerator().addProvider(
event.includeServer(),
true,
(DataProvider.Factory<SimpleLootTableProvider>) pOutput -> {
try {
return new SimpleLootTableProvider(pOutput, new SubProvidersWrapper().addBlockEntry(new Lib39BlockLootTable(event.getLookupProvider())), event.getLookupProvider());

View File

@ -1,7 +1,7 @@
package top.r3944realms.lib39.base.datagen.provider;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.neoforged.neoforge.client.model.generators.BlockModelProvider;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import top.r3944realms.lib39.Lib39;
@ -35,7 +35,7 @@ public class Lib39BlockModelProvider extends BlockModelProvider {
}
}
private void createPlantsModel(PlantHelper.Plant plant) {
ResourceLocation rl = PlantHelper.getTextureRL(plant);
Identifier rl = PlantHelper.getTextureRL(plant);
getBuilder("block/doll_item/" + plant)
.parent(getExistingFile(Lib39.rl("block/base_doll_item")))
.texture("item", rl)

View File

@ -17,10 +17,8 @@ package top.r3944realms.lib39.base.datagen.provider;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.Item;
import net.neoforged.neoforge.client.model.generators.ItemModelProvider;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.base.datagen.value.Lib39LangKey;
import top.r3944realms.lib39.datagen.value.LangKeyValue;
@ -80,7 +78,7 @@ public class Lib39ItemModelProvider extends ItemModelProvider {
* @param item the item
* @param location the location
*/
public void itemGenerateModel(Item item, ResourceLocation location){
public void itemGenerateModel(Item item, Identifier location){
withExistingParent(itemName(item), GENERATED).texture("layer0", location);
}
@ -90,7 +88,7 @@ public class Lib39ItemModelProvider extends ItemModelProvider {
* @param item the item
* @param location the location
*/
public void itemHandHeldModel(Item item, ResourceLocation location){
public void itemHandHeldModel(Item item, Identifier location){
withExistingParent(itemName(item), HANDHELD).texture("layer0", location);
}
@ -118,7 +116,7 @@ public class Lib39ItemModelProvider extends ItemModelProvider {
* @param path the path
* @return the resource location
*/
public ResourceLocation resourceItem(String path){
public Identifier resourceItem(String path){
return modLoc("item/" + path);
}
}

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.compat;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.EventBusSubscriber;
@ -30,7 +30,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
/**
* The Compats.
*/
protected final Map<ResourceLocation, INeoForgeCompat> compats = new HashMap<>();
protected final Map<Identifier, 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<ResourceLocation, INeoForgeCompat> getCompatMap() {
public Map<Identifier, 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(ResourceLocation id, IEventBus modEventBus, IEventBus gameEventBus) {
public NeoForgeCompatManager(Identifier id, IEventBus modEventBus, IEventBus gameEventBus) {
super(id);
this.modEventBus = modEventBus;
this.gameEventBus = gameEventBus;
}
@Override
protected void doRegisterCompat(ResourceLocation id, INeoForgeCompat compat) {
protected void doRegisterCompat(Identifier 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(ResourceLocation compatId, @Nullable Dist dists, EventBusSubscriber.Bus bus) {
public void addListenerForCompat(Identifier compatId, @Nullable Dist dists, EventBusSubscriber.Bus bus) {
listenerConfigs.add(new ListenerConfig(compatId, dists, bus));
}
@ -89,7 +89,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
*
* @param compatId the compat id
*/
public void addListenerForCompat(ResourceLocation compatId) {
public void addListenerForCompat(Identifier compatId) {
addListenerForCompat(compatId, null, EventBusSubscriber.Bus.GAME);
addListenerForCompat(compatId, null, EventBusSubscriber.Bus.MOD);
@ -129,7 +129,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
pendingTasks.clear();
// 初始化所有兼容模块
for (Map.Entry<ResourceLocation, INeoForgeCompat> entry : compats.entrySet()) {
for (Map.Entry<Identifier, INeoForgeCompat> entry : compats.entrySet()) {
if (!entry.getValue().isInitialized() && entry.getValue().isModLoaded()) {
try {
entry.getValue().initialize();
@ -178,7 +178,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
/**
* 将监听器应用到特定兼容模块
*/
private void applyListenerToCompat(ResourceLocation compatId, ListenerConfig config) {
private void applyListenerToCompat(Identifier compatId, ListenerConfig config) {
INeoForgeCompat compat = compats.get(compatId);
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(ResourceLocation compatId, EventBusSubscriber.Bus bus) {
public void addListenerForCompat(Identifier compatId, EventBusSubscriber.Bus bus) {
addListenerForCompat(compatId, null, bus);
}
@ -268,7 +268,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
/**
* The Compat id.
*/
final ResourceLocation compatId;
final Identifier compatId;
/**
* The Dists.
*/
@ -285,7 +285,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
* @param dists the dists
* @param bus the bus
*/
ListenerConfig(ResourceLocation compatId, Dist dists, EventBusSubscriber.Bus bus) {
ListenerConfig(Identifier compatId, Dist dists, EventBusSubscriber.Bus bus) {
this.compatId = compatId;
this.dists = dists;
this.bus = bus;

View File

@ -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.ResourceLocation;
import net.minecraft.resources.Identifier;
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(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
syncData2Manager.forEach(((Identifier, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
}
/**
@ -206,7 +206,7 @@ public class CommonEventHandler {
Entity entity = event.getEntity();
if (entity.level().isClientSide) return;
for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
for (Identifier id : syncData2Manager.getRegisteredKeys()) {
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
syncData2Manager.trackEntityForManager(entity, id);
}
@ -223,7 +223,7 @@ public class CommonEventHandler {
Entity entity = event.getEntity();
if (entity.level().isClientSide) return;
for (ResourceLocation id : syncData2Manager.getRegisteredKeys()) {
for (Identifier id : syncData2Manager.getRegisteredKeys()) {
if (syncData2Manager.isEntityClassAllowed(id, entity.getClass())) {
syncData2Manager.untrackEntityForManager(entity, id);
}

View File

@ -7,7 +7,7 @@ import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import net.neoforged.neoforge.network.handling.IPayloadContext;
import org.jetbrains.annotations.Contract;
@ -25,11 +25,11 @@ import java.util.function.Supplier;
* The type Sync nbt data s 2 c payload.
*/
@SuppressWarnings("unused")
public record SyncNBTCapDataEntityS2CPayload(int entityId, ResourceLocation id, CompoundTag data) implements CustomPacketPayload {
public record SyncNBTCapDataEntityS2CPayload(int entityId, Identifier id, CompoundTag data) implements CustomPacketPayload {
/**
* The constant SYNC_NBT_CAP_PACKET_ID.
*/
public static final ResourceLocation SYNC_NBT_CAP_PACKET_ID =
public static final Identifier SYNC_NBT_CAP_PACKET_ID =
Lib39.rl("sync_nbt_cap_data_entity");
/**
* The constant TYPE.
@ -60,7 +60,7 @@ public record SyncNBTCapDataEntityS2CPayload(int entityId, ResourceLocation id,
*/
public static void encode(@NotNull SyncNBTCapDataEntityS2CPayload msg, @NotNull FriendlyByteBuf buffer) {
buffer.writeInt(msg.entityId);
buffer.writeResourceLocation(msg.id);
buffer.writeIdentifier(msg.id);
buffer.writeNbt(msg.data);
}
@ -72,7 +72,7 @@ public record SyncNBTCapDataEntityS2CPayload(int entityId, ResourceLocation id,
*/
@Contract("_ -> new")
public static @NotNull SyncNBTCapDataEntityS2CPayload decode(@NotNull FriendlyByteBuf buffer) {
return new SyncNBTCapDataEntityS2CPayload(buffer.readInt(), buffer.readResourceLocation(), buffer.readNbt());
return new SyncNBTCapDataEntityS2CPayload(buffer.readInt(), buffer.readIdentifier(), buffer.readNbt());
}
/**

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.core.sync;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import net.neoforged.neoforge.capabilities.ICapabilityProvider;
import org.jetbrains.annotations.Nullable;
@ -26,7 +26,7 @@ public abstract class SyncCapProvider<T extends NBTEntitySyncData> implements IC
*
* @return 能力 ID
*/
protected abstract ResourceLocation getId();
protected abstract Identifier getId();
@SuppressWarnings("unchecked")
@Override

View File

@ -1,7 +1,7 @@
package top.r3944realms.lib39.core.sync;
import com.google.common.collect.Maps;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.neoforged.neoforge.capabilities.EntityCapability;
import org.jetbrains.annotations.Nullable;
@ -17,10 +17,10 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
/**
* The Typed entries.
*/
protected final Map<ResourceLocation, TypedSyncEntry<?>> typedEntries = Maps.newConcurrentMap();
protected final Map<Identifier, TypedSyncEntry<?>> typedEntries = Maps.newConcurrentMap();
@Override
protected Map<ResourceLocation, TypedSyncEntry<?>> getTypedEntries() {
protected Map<Identifier, 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(
ResourceLocation key,
Identifier key,
ISyncManager<EntityCapability<T, Void>, T> manager,
EntityCapability<T, Void> capability
) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(manager, "Sync manager cannot be null");
Objects.requireNonNull(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(ResourceLocation key, EntityCapability<T, Void> capability) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
public <T extends ISyncData<?>> void bindCapability(Identifier key, EntityCapability<T, Void> capability) {
Objects.requireNonNull(key, "Identifier key cannot be null");
Objects.requireNonNull(capability, "Capability cannot be null");
TypedSyncEntry<?> entry = typedEntries.get(key);
@ -85,8 +85,8 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
*
* @param key the key
*/
public void unbindCapability(ResourceLocation key) {
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
public void unbindCapability(Identifier key) {
Objects.requireNonNull(key, "Identifier 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(ResourceLocation id, TypedSyncEntry<?> entry, EntityCapability<T, Void> newCapability) {
protected <T extends ISyncData<?>> void updateCapabilityInEntry(Identifier id, TypedSyncEntry<?> entry, EntityCapability<T, Void> newCapability) {
updateDataProviderInEntry(id, entry, key -> newCapability != null ? Optional.ofNullable(key.getCapability(newCapability)) : Optional.empty());
}
}

View File

@ -5,7 +5,7 @@ import net.minecraft.core.WritableRegistry;
import net.minecraft.data.PackOutput;
import net.minecraft.data.loot.LootTableProvider;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.util.ProblemReporter;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.ValidationContext;

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.example.compat;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModList;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
@ -23,7 +23,7 @@ public class Lib39Compat implements INeoForgeCompat {
/**
* The constant ID.
*/
public static ResourceLocation ID = Lib39.rl("lib39");
public static Identifier ID = Lib39.rl("lib39");
@Override
public void setInitialize(boolean initialize) {
@ -36,7 +36,7 @@ public class Lib39Compat implements INeoForgeCompat {
}
@Override
public ResourceLocation id() {
public Identifier id() {
return ID;
}

View File

@ -1,6 +1,6 @@
package top.r3944realms.lib39.example.content.data;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.core.sync.SyncCapProvider;
@ -13,7 +13,7 @@ public class TestSyncCapProvider extends SyncCapProvider<AbstractedTestSyncData>
}
@Override
protected ResourceLocation getId() {
protected Identifier getId() {
return Lib39.rl("test_data");
}

View File

@ -2,7 +2,7 @@ package top.r3944realms.lib39.example.content.data;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.Lib39;
@ -22,7 +22,7 @@ public class TestSyncData extends AbstractedTestSyncData implements INeoForgeUpd
/**
* The constant ID.
*/
public static final ResourceLocation ID = Lib39.rl(Lib39.MOD_ID, "test_sync_data");
public static final Identifier ID = Lib39.rl(Lib39.MOD_ID, "test_sync_data");
// NBT 键常量
private static final String NBT_KEY_STRING = "test_string";

View File

@ -4,7 +4,7 @@ import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.neoforged.neoforge.network.handling.IPayloadContext;
@ -21,7 +21,7 @@ public record ClientDataPayload(AbstractedTestSyncData clientData, int targetEnt
/**
* The constant CLIENT_DATA_PACKET_ID.
*/
public static final ResourceLocation CLIENT_DATA_PACKET_ID =
public static final Identifier CLIENT_DATA_PACKET_ID =
Lib39.rl("client_data");
/**
* The constant TYPE.

View File

@ -1,7 +1,7 @@
package top.r3944realms.lib39.util;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.monster.Monster;
@ -85,7 +85,7 @@ public class EntityCapabilityHelper {
BuiltInRegistries.ENTITY_TYPE.stream()
.filter(entityType -> {
ResourceLocation key = BuiltInRegistries.ENTITY_TYPE.getKey(entityType);
Identifier key = BuiltInRegistries.ENTITY_TYPE.getKey(entityType);
return namespace.equals(key.getNamespace());
})
.forEach(entityType -> event.registerEntity(capability, entityType, provider));