fix proxy
This commit is contained in:
@@ -61,7 +61,7 @@ public class ClientEventHandler {
|
||||
for (int i = 0; i < n; i++) {
|
||||
Component comp = list.get(i);
|
||||
Component lit;
|
||||
if (comp.getContents() instanceof PlainTextContents.LiteralContents txt && comp.getSiblings().size() == 1) {
|
||||
if (comp.getContents() instanceof PlainTextContents txt && !comp.getSiblings().isEmpty()) {
|
||||
comp = comp.getSiblings().getFirst();
|
||||
lit = Component.literal(txt.text());
|
||||
} else lit = Component.empty();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.xkmc.l2core.init.reg.registrate;
|
||||
|
||||
import dev.xkmc.l2serial.util.Wrappers;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@@ -46,4 +47,8 @@ public class NamedEntry<T extends NamedEntry<T>> {
|
||||
return Wrappers.cast(this);
|
||||
}
|
||||
|
||||
public Holder<T> holder() {
|
||||
return registry.get().wrapAsHolder(getThis());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.fml.loading.FMLEnvironment;
|
||||
import net.neoforged.neoforge.server.ServerLifecycleHooks;
|
||||
|
||||
@@ -23,21 +24,6 @@ public class Proxy {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static RegistryAccess getRegistryAccess() {
|
||||
if (FMLEnvironment.dist == Dist.CLIENT) {
|
||||
var level = Minecraft.getInstance().level;
|
||||
if (level != null) {
|
||||
return Minecraft.getInstance().level.registryAccess();
|
||||
}
|
||||
}
|
||||
var server = ServerLifecycleHooks.getCurrentServer();
|
||||
if (server != null) {
|
||||
return server.registryAccess();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Level getLevel() {
|
||||
if (FMLEnvironment.dist == Dist.CLIENT) {
|
||||
|
||||
28
src/main/java/dev/xkmc/l2core/util/ServerProxy.java
Normal file
28
src/main/java/dev/xkmc/l2core/util/ServerProxy.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package dev.xkmc.l2core.util;
|
||||
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.fml.loading.FMLEnvironment;
|
||||
import net.neoforged.neoforge.server.ServerLifecycleHooks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ServerProxy {
|
||||
|
||||
@Nullable
|
||||
public static RegistryAccess getRegistryAccess() {
|
||||
if (FMLEnvironment.dist == Dist.CLIENT) {
|
||||
Level level = Proxy.getLevel();
|
||||
if (level != null) {
|
||||
return level.registryAccess();
|
||||
}
|
||||
}
|
||||
var server = ServerLifecycleHooks.getCurrentServer();
|
||||
if (server != null) {
|
||||
return server.registryAccess();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user