Kajetan Johannes Hammerle 3 anos atrás
pai
commit
4667b45a3f

+ 10 - 0
src/main/java/me/km/KajetansMod.java

@@ -1,8 +1,10 @@
 package me.km;
 
 import java.util.function.Supplier;
+import me.kcm.Hooks;
 import me.km.blocks.ModBlocks;
 import me.km.networking.ModPacketHandler;
+import me.km.overrides.ModPlayerList;
 import net.minecraft.block.Block;
 import net.minecraft.block.Blocks;
 import net.minecraft.server.dedicated.DedicatedServer;
@@ -15,6 +17,7 @@ import net.minecraftforge.common.MinecraftForge;
 import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder;
 import net.minecraftforge.event.world.BiomeLoadingEvent;
 import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
+import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
 import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
 import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
 import net.minecraftforge.fml.common.Mod;
@@ -35,6 +38,7 @@ public class KajetansMod {
         IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
         bus.addListener(this::init);
         bus.addListener(this::clientInit);
+        bus.addListener(this::serverInit);
 
         MinecraftForge.EVENT_BUS.register(this);
     }
@@ -49,6 +53,12 @@ public class KajetansMod {
         Client.init();
     }
 
+    private void serverInit(FMLDedicatedServerSetupEvent e) {
+        Hooks.setPlayerListFunction((ds, impl, pd) -> {
+            ds.setPlayerList(new ModPlayerList(ds, impl, pd));
+        });
+    }
+
     @SubscribeEvent
     public void onServerStart(FMLServerStartingEvent e) {
         if(e.getServer().isDedicatedServer()) {

+ 0 - 6
src/main/java/me/km/Server.java

@@ -28,7 +28,6 @@ import me.km.snuviscript.MinecraftFunctions;
 import me.km.snuviscript.ScriptBank;
 import me.km.snuviscript.ScriptEvents;
 import me.km.snuviscript.Scripts;
-import net.minecraft.util.registry.DynamicRegistries;
 
 @OnlyIn(Dist.DEDICATED_SERVER)
 public class Server {
@@ -64,11 +63,6 @@ public class Server {
         // scheduler
         scheduler = new SnuviScheduler(logger);
 
-        // mod player list hook
-        Hooks.setPlayerListFunction((ds, impl, pd) -> {
-            ds.setPlayerList(new ModPlayerList(ds, impl, pd));
-        });
-
         // scripts
         scripts = new Scripts(logger, scheduler);
         scriptEvents = new ScriptEvents(scripts, server);

+ 2 - 1
src/main/java/me/km/snuviscript/commands/BlockCommands.java

@@ -6,6 +6,7 @@ import me.hammerle.snuviscript.code.SnuviUtils;
 import me.km.inventory.InventoryUtils;
 import me.km.utils.Location;
 import me.km.utils.Mapper;
+import me.km.utils.ReflectionUtils;
 import net.minecraft.block.*;
 import net.minecraft.command.arguments.BlockStateParser;
 import net.minecraft.entity.EntityType;
@@ -181,7 +182,7 @@ public class BlockCommands {
             if(te == null || !(te instanceof SignTileEntity)) {
                 return null;
             }
-            return ((SignTileEntity) te).getText(in[1].getInt(sc)).getString();
+            return ReflectionUtils.getSignText((SignTileEntity) te, in[1].getInt(sc)).getString();
         });
         sm.registerConsumer("block.setdoorstatus", (sc, in) -> {
             Location l = (Location) in[0].get(sc);

+ 1 - 1
src/main/java/me/km/snuviscript/commands/LivingCommands.java

@@ -16,7 +16,7 @@ import net.minecraftforge.registries.ForgeRegistries;
 public class LivingCommands {
     private static String getName(Attribute attribute) {
         String name = attribute.getAttributeName();
-        int index = name.indexOf(".");
+        int index = name.lastIndexOf(".");
         if(index != -1) {
             name = name.substring(index + 1);
         }

+ 1 - 1
src/main/java/me/km/utils/Location.java

@@ -55,7 +55,7 @@ public class Location {
         try {
             String[] parts = location.split(":");
             if(parts.length >= 6) {
-                this.w = Utils.getWorldFromName(server, location);
+                this.w = Utils.getWorldFromName(server, parts[0]);
                 this.x = Double.parseDouble(parts[1]);
                 this.y = Double.parseDouble(parts[2]);
                 this.z = Double.parseDouble(parts[3]);

+ 8 - 0
src/main/java/me/km/utils/ReflectionUtils.java

@@ -17,7 +17,9 @@ import net.minecraft.resources.DataPackRegistries;
 import net.minecraft.server.MinecraftServer;
 import net.minecraft.server.management.PlayerInteractionManager;
 import net.minecraft.server.management.PlayerList;
+import net.minecraft.tileentity.SignTileEntity;
 import net.minecraft.util.FoodStats;
+import net.minecraft.util.text.ITextComponent;
 import net.minecraft.world.Explosion;
 import net.minecraft.world.GameRules;
 import net.minecraft.world.GameType;
@@ -220,4 +222,10 @@ public class ReflectionUtils {
             LogManager.getLogger().warn("setFireInfo - " + ex);
         }
     }
+    
+    private final static Field SIGN_TEXT = getField(SignTileEntity.class, "field_145915_a");
+
+    public static ITextComponent getSignText(SignTileEntity ent, int index) {
+        return getFieldValue(ITextComponent[].class, ent, SIGN_TEXT)[index];
+    }
 }

+ 7 - 2
src/main/java/me/km/utils/Utils.java

@@ -17,6 +17,7 @@ import net.minecraft.util.math.RayTraceResult;
 import net.minecraft.util.math.vector.Vector3d;
 import net.minecraft.util.registry.Registry;
 import net.minecraft.world.World;
+import net.minecraft.world.server.ServerWorld;
 
 public class Utils {
     public static Entity getEntityFromProjectile(Entity ent) {
@@ -181,8 +182,12 @@ public class Utils {
     public static String getWorldName(World w) {
         return w.getDimensionKey().getLocation().getPath();
     }
-    
+
     public static World getWorldFromName(MinecraftServer server, String name) {
-        return server.getWorld(RegistryKey.getOrCreateKey(Registry.WORLD_KEY, new ResourceLocation(name)));
+        ServerWorld sw = server.getWorld(RegistryKey.getOrCreateKey(Registry.WORLD_KEY, new ResourceLocation(name)));
+        if(sw != null) {
+            return sw;
+        }
+        return server.getWorld(RegistryKey.getOrCreateKey(Registry.WORLD_KEY, new ResourceLocation("km", name)));
     }
 }