]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
SpawnX and SpawnZ are not reliable
authorIrtimaled <irtimaled@gmail.com>
Wed, 4 Feb 2015 20:03:38 +0000 (20:03 +0000)
committerIrtimaled <irtimaled@gmail.com>
Wed, 4 Feb 2015 21:18:16 +0000 (21:18 +0000)
On the client these fields can change randomly so are not reliable - instead we send to the client from the server during initialize

java/com/irtimaled/bbor/ClientProxy.java
java/com/irtimaled/bbor/CommonProxy.java
java/com/irtimaled/bbor/IWorldData.java [new file with mode: 0644]
java/com/irtimaled/bbor/messages/InitializeClientMessage.java
java/com/irtimaled/bbor/messages/InitializeClientMessageHandler.java

index 389318d4139b055e23594e58749c970b5ccf350d..062c300d1311699ae321bf2c6933e45c35e438ad 100644 (file)
@@ -372,23 +372,24 @@ public class ClientProxy extends CommonProxy {
 
     private Set<BoundingBox> getClientBoundingBoxes() {
         Set<BoundingBox> boundingBoxes = new HashSet<BoundingBox>();
-        World world = Minecraft.getMinecraft().theWorld;
-        int dimensionId = world.provider.getDimensionId();
-        if (dimensionId == 0) {
-            if (configManager.drawWorldSpawn.getBoolean()) {
-                int spawnX = world.getWorldInfo().getSpawnX();
-                int spawnZ = world.getWorldInfo().getSpawnZ();
-                boundingBoxes.add(getSpawnBoundingBox(spawnX, spawnZ));
-                boundingBoxes.add(getSpawnChunksBoundingBox(spawnX, spawnZ));
+        if (initialized) {
+            World world = Minecraft.getMinecraft().theWorld;
+            int dimensionId = world.provider.getDimensionId();
+            if (dimensionId == 0) {
+                if (configManager.drawWorldSpawn.getBoolean()) {
+                    int spawnX = world.getWorldInfo().getSpawnX();
+                    int spawnZ = world.getWorldInfo().getSpawnZ();
+                    boundingBoxes.add(getSpawnBoundingBox(spawnX, spawnZ));
+                    boundingBoxes.add(getSpawnChunksBoundingBox(spawnX, spawnZ));
 
-            }
+                }
 
-            if (initialized &&
-                    configManager.drawSlimeChunks.getBoolean()) {
-                Set<ChunkCoordIntPair> activeChunks = getActiveChunks(world);
-                for (ChunkCoordIntPair chunk : activeChunks) {
-                    if (isSlimeChunk(chunk.chunkXPos, chunk.chunkZPos)) {
-                        boundingBoxes.add(BoundingBoxSlimeChunk.from(chunk, Color.GREEN));
+                if (configManager.drawSlimeChunks.getBoolean()) {
+                    Set<ChunkCoordIntPair> activeChunks = getActiveChunks(world);
+                    for (ChunkCoordIntPair chunk : activeChunks) {
+                        if (isSlimeChunk(chunk.chunkXPos, chunk.chunkZPos)) {
+                            boundingBoxes.add(BoundingBoxSlimeChunk.from(chunk, Color.GREEN));
+                        }
                     }
                 }
             }
index c3446c1c7b774d8412f5f7135c329222b4a464e0..dd46e52458a98de1a3e03d17026ba06dcf684870 100644 (file)
@@ -32,6 +32,8 @@ public class CommonProxy {
     public ConfigManager configManager;
     protected SimpleNetworkWrapper network;
     protected long seed;
+    protected int spawnX;
+    protected int spawnZ;
     protected boolean initialized;
 
     public void init() {
@@ -46,7 +48,7 @@ public class CommonProxy {
         IChunkProvider chunkProvider = event.world.getChunkProvider();
         if (chunkProvider instanceof ChunkProviderServer) {
             chunkProvider = ((ChunkProviderServer) chunkProvider).serverChunkGenerator;
-            setSeed(event.world.getSeed());
+            setWorldData(event.world.getSeed(), event.world.getWorldInfo().getSpawnX(), event.world.getWorldInfo().getSpawnZ());
             int dimensionId = event.world.provider.getDimensionId();
             FMLLog.info("create world dimension: %d, %s (chunkprovider: %s) (seed: %d)", dimensionId, event.world.getClass().toString(), chunkProvider.getClass().toString(), seed);
             boundingBoxCacheMap.put(dimensionId, new DimensionProcessor(configManager, event.world, dimensionId, chunkProvider));
@@ -113,7 +115,7 @@ public class CommonProxy {
     }
 
     private void initializeClient(EntityPlayerMP player) {
-        network.sendTo(InitializeClientMessage.from(seed), player);
+        network.sendTo(InitializeClientMessage.from(seed, spawnX, spawnZ), player);
     }
 
     private void sendToPlayer(EntityPlayerMP player, BoundingBoxCache boundingBoxCache) {
@@ -162,8 +164,14 @@ public class CommonProxy {
         }
     }
 
-    public void setSeed(long seed) {
+    public void setWorldData(long seed, int spawnX, int spawnZ) {
         this.seed = seed;
+        this.spawnX = spawnX;
+        this.spawnZ = spawnZ;
         this.initialized = true;
     }
+
+    public void setWorldData(IWorldData worldData) {
+        setWorldData(worldData.getSeed(), worldData.getSpawnX(), worldData.getSpawnZ());
+    }
 }
diff --git a/java/com/irtimaled/bbor/IWorldData.java b/java/com/irtimaled/bbor/IWorldData.java
new file mode 100644 (file)
index 0000000..7d514c1
--- /dev/null
@@ -0,0 +1,12 @@
+package com.irtimaled.bbor;
+
+/**
+ * Created by richard on 04/02/15.
+ */
+public interface IWorldData {
+    long getSeed();
+
+    int getSpawnX();
+
+    int getSpawnZ();
+}
index cfd9ecfc3023cd9df47a36149a35319a32be7ea6..1f4a41c7360c1e0d447f22d0bb7fe9f1ca8bc2fb 100644 (file)
@@ -1,29 +1,45 @@
 package com.irtimaled.bbor.messages;
 
+import com.irtimaled.bbor.IWorldData;
 import io.netty.buffer.ByteBuf;
 import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
 
-public class InitializeClientMessage implements IMessage {
+public class InitializeClientMessage implements IMessage, IWorldData {
 
     private long seed;
+    private int spawnX;
+    private int spawnZ;
 
-    public static InitializeClientMessage from(long seed) {
+    public static InitializeClientMessage from(long seed, int spawnX, int spawnZ) {
         InitializeClientMessage message = new InitializeClientMessage();
         message.seed = seed;
+        message.spawnX = spawnX;
+        message.spawnZ = spawnZ;
         return message;
     }
 
     @Override
     public void fromBytes(ByteBuf buf) {
         seed = buf.readLong();
+        spawnX = buf.readInt();
+        spawnZ = buf.readInt();
     }
 
     @Override
     public void toBytes(ByteBuf buf) {
         buf.writeLong(seed);
+        buf.writeInt(spawnX);
+        buf.writeInt(spawnZ);
     }
 
+    @Override
     public long getSeed() {
         return seed;
     }
+
+    @Override
+    public int getSpawnX() { return spawnX; }
+
+    @Override
+    public int getSpawnZ() { return spawnZ; }
 }
index cb65e1976a64b8a20b6f96347d1e5de4254e9835..03df7e52833ec2e4fef822a7b38bd7bc913de45a 100644 (file)
@@ -8,7 +8,7 @@ import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
 public class InitializeClientMessageHandler implements IMessageHandler<InitializeClientMessage, IMessage> {
     @Override
     public IMessage onMessage(InitializeClientMessage message, MessageContext ctx) {
-        BoundingBoxOutlineReloaded.proxy.setSeed(message.getSeed());
+        BoundingBoxOutlineReloaded.proxy.setWorldData(message);
         return null;
     }
 }