]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
Tidy up other minecraft imports
authorIrtimaled <irtimaled@gmail.com>
Sun, 24 Mar 2019 07:56:43 +0000 (00:56 -0700)
committerIrtimaled <irtimaled@gmail.com>
Mon, 25 Mar 2019 03:56:28 +0000 (20:56 -0700)
src/main/java/com/irtimaled/bbor/client/ClientProxy.java
src/main/java/com/irtimaled/bbor/common/CommonProxy.java
src/main/java/com/irtimaled/bbor/common/VillageProcessor.java
src/main/java/com/irtimaled/bbor/common/events/ChunkLoaded.java
src/main/java/com/irtimaled/bbor/common/events/ServerWorldTick.java
src/main/java/com/irtimaled/bbor/common/events/WorldLoaded.java

index 234edbc864b1da871434a47ccf3a768218692eb3..094d1722b382a8664cf8a9f799493519ca6f54da 100644 (file)
@@ -3,6 +3,7 @@ package com.irtimaled.bbor.client;
 import com.irtimaled.bbor.client.events.*;
 import com.irtimaled.bbor.client.gui.SettingsScreen;
 import com.irtimaled.bbor.client.keyboard.KeyListener;
+import com.irtimaled.bbor.common.BoundingBoxCache;
 import com.irtimaled.bbor.common.CommonProxy;
 import com.irtimaled.bbor.common.EventBus;
 import com.irtimaled.bbor.common.VillageColorCache;
@@ -39,12 +40,12 @@ public class ClientProxy extends CommonProxy {
     @Override
     public void init() {
         super.init();
-        EventBus.subscribe(Render.class, e -> render(e.getDimensionId()));
-        EventBus.subscribe(ConnectedToRemoteServer.class, e -> connectedToServer(e.getInternetAddress()));
+        EventBus.subscribe(Render.class, this::render);
+        EventBus.subscribe(ConnectedToRemoteServer.class, this::connectedToServer);
         EventBus.subscribe(DisconnectedFromRemoteServer.class, e -> disconnectedFromServer());
-        EventBus.subscribe(InitializeClientReceived.class, e -> setWorldData(e.getSeed(), e.getSpawnX(), e.getSpawnZ()));
-        EventBus.subscribe(AddBoundingBoxReceived.class, e -> addBoundingBox(e.getDimensionId(), e.getKey(), e.getBoundingBoxes()));
-        EventBus.subscribe(RemoveBoundingBoxReceived.class, e -> removeBoundingBox(e.getDimensionId(), e.getKey()));
+        EventBus.subscribe(InitializeClientReceived.class, this::onInitializeClientReceived);
+        EventBus.subscribe(AddBoundingBoxReceived.class, this::addBoundingBox);
+        EventBus.subscribe(RemoveBoundingBoxReceived.class, this::onRemoveBoundingBoxReceived);
 
         renderer = new ClientRenderer(this::getCache);
         KeyListener.init();
@@ -56,7 +57,8 @@ public class ClientProxy extends CommonProxy {
         }
     }
 
-    private void connectedToServer(InetSocketAddress internetAddress) {
+    private void connectedToServer(ConnectedToRemoteServer event) {
+        InetSocketAddress internetAddress = event.getInternetAddress();
         NBTFileParser.loadLocalDatFiles(internetAddress.getHostName(), internetAddress.getPort(), this::setWorldData, this::getOrCreateCache);
     }
 
@@ -67,6 +69,24 @@ public class ClientProxy extends CommonProxy {
         clearCaches();
     }
 
+    private void addBoundingBox(AddBoundingBoxReceived event) {
+        BoundingBoxCache cache = getCache(event.getDimensionId());
+        if (cache == null) return;
+
+        cache.addBoundingBoxes(event.getKey(), event.getBoundingBoxes());
+    }
+
+    private void onRemoveBoundingBoxReceived(RemoveBoundingBoxReceived event) {
+        super.removeBoundingBox(event.getDimensionId(), event.getKey());
+    }
+
+    private void onInitializeClientReceived(InitializeClientReceived event) {
+        long seed = event.getSeed();
+        int spawnX = event.getSpawnX();
+        int spawnZ = event.getSpawnZ();
+        setWorldData(seed, spawnX, spawnZ);
+    }
+
     @Override
     protected void setWorldData(long seed, int spawnX, int spawnZ) {
         super.setWorldData(seed, spawnX, spawnZ);
index 461d8f47235425a2c0077d86f474cf52d1622eec..3d84f1b864cef462cf3845081df588b2cddfe7c0 100644 (file)
@@ -10,9 +10,10 @@ import com.irtimaled.bbor.common.messages.AddBoundingBox;
 import com.irtimaled.bbor.common.messages.InitializeClient;
 import com.irtimaled.bbor.common.messages.PayloadBuilder;
 import com.irtimaled.bbor.common.messages.RemoveBoundingBox;
-import com.irtimaled.bbor.common.models.*;
-import net.minecraft.world.WorldServer;
-import net.minecraft.world.chunk.Chunk;
+import com.irtimaled.bbor.common.models.AbstractBoundingBox;
+import com.irtimaled.bbor.common.models.BoundingBoxMobSpawner;
+import com.irtimaled.bbor.common.models.ServerPlayer;
+import com.irtimaled.bbor.common.models.WorldData;
 
 import java.util.HashMap;
 import java.util.HashSet;
@@ -29,57 +30,65 @@ public class CommonProxy {
     private final Map<Integer, BoundingBoxCache> dimensionCache = new ConcurrentHashMap<>();
 
     public void init() {
-        EventBus.subscribe(WorldLoaded.class, e -> worldLoaded(e.getWorld()));
-        EventBus.subscribe(ChunkLoaded.class, e -> chunkLoaded(e.getChunk()));
-        EventBus.subscribe(MobSpawnerBroken.class, e -> mobSpawnerBroken(e.getDimensionId(), e.getPos()));
-        EventBus.subscribe(PlayerLoggedIn.class, e -> playerLoggedIn(e.getPlayer()));
-        EventBus.subscribe(PlayerLoggedOut.class, e -> playerLoggedOut(e.getPlayer()));
-        EventBus.subscribe(PlayerSubscribed.class, e -> sendBoundingBoxes(e.getPlayer()));
-        EventBus.subscribe(ServerWorldTick.class, e -> serverWorldTick(e.getWorld()));
+        EventBus.subscribe(WorldLoaded.class, this::worldLoaded);
+        EventBus.subscribe(ChunkLoaded.class, this::chunkLoaded);
+        EventBus.subscribe(MobSpawnerBroken.class, this::mobSpawnerBroken);
+        EventBus.subscribe(PlayerLoggedIn.class, this::playerLoggedIn);
+        EventBus.subscribe(PlayerLoggedOut.class, this::playerLoggedOut);
+        EventBus.subscribe(PlayerSubscribed.class, this::onPlayerSubscribed);
+        EventBus.subscribe(ServerWorldTick.class, this::serverWorldTick);
         EventBus.subscribe(ServerTick.class, e -> serverTick());
-        EventBus.subscribe(VillageRemoved.class, e -> sendRemoveBoundingBox(e.getDimensionId(), e.getVillage()));
+        EventBus.subscribe(VillageRemoved.class, this::onVillageRemoved);
     }
 
     protected void setWorldData(long seed, int spawnX, int spawnZ) {
         worldData = new WorldData(seed, spawnX, spawnZ);
     }
 
-    private void worldLoaded(WorldServer world) {
-        int dimensionId = world.dimension.getType().getId();
+    private void worldLoaded(WorldLoaded event) {
+        int dimensionId = event.getDimensionId();
+        long seed = event.getSeed();
         BoundingBoxCache boundingBoxCache = getOrCreateCache(dimensionId);
         AbstractChunkProcessor chunkProcessor = null;
-        if (dimensionId == Dimensions.OVERWORLD) {
-            setWorldData(world.getSeed(), world.getWorldInfo().getSpawnX(), world.getWorldInfo().getSpawnZ());
-            chunkProcessor = new OverworldChunkProcessor(boundingBoxCache);
+        switch (dimensionId) {
+            case Dimensions.OVERWORLD:
+                setWorldData(seed, event.getSpawnX(), event.getSpawnZ());
+                chunkProcessor = new OverworldChunkProcessor(boundingBoxCache);
+                break;
+            case Dimensions.NETHER:
+                chunkProcessor = new NetherChunkProcessor(boundingBoxCache);
+                break;
+            case Dimensions.THE_END:
+                chunkProcessor = new EndChunkProcessor(boundingBoxCache);
+                break;
         }
-        if (dimensionId == Dimensions.NETHER) {
-            chunkProcessor = new NetherChunkProcessor(boundingBoxCache);
-        }
-        if (dimensionId == Dimensions.THE_END) {
-            chunkProcessor = new EndChunkProcessor(boundingBoxCache);
-        }
-        Logger.info("create world dimension: %s, %s (seed: %d)", dimensionId, world.getClass().toString(), world.getSeed());
+        Logger.info("create world dimension: %s (seed: %d)", dimensionId, seed);
         chunkProcessors.put(dimensionId, chunkProcessor);
         villageProcessors.put(dimensionId, new VillageProcessor(dimensionId, boundingBoxCache));
     }
 
-    private void chunkLoaded(Chunk chunk) {
-        int dimensionId = chunk.getWorld().dimension.getType().getId();
-        AbstractChunkProcessor chunkProcessor = chunkProcessors.get(dimensionId);
-        if (chunkProcessor != null) {
-            chunkProcessor.process(chunk);
-        }
+    private void chunkLoaded(ChunkLoaded event) {
+        AbstractChunkProcessor chunkProcessor = chunkProcessors.get(event.getDimensionId());
+        if (chunkProcessor == null) return;
+
+        chunkProcessor.process(event.getChunk());
     }
 
-    private void playerLoggedIn(ServerPlayer player) {
+    private void playerLoggedIn(PlayerLoggedIn event) {
+        ServerPlayer player = event.getPlayer();
         player.sendPacket(InitializeClient.getPayload(worldData));
     }
 
-    private void playerLoggedOut(ServerPlayer player) {
+    private void playerLoggedOut(PlayerLoggedOut event) {
+        ServerPlayer player = event.getPlayer();
         players.remove(player);
         playerBoundingBoxesCache.remove(player);
     }
 
+    private void onVillageRemoved(VillageRemoved event) {
+        sendRemoveBoundingBox(event.getDimensionId(), event.getVillage());
+    }
+
     private void sendRemoveBoundingBox(int dimensionId, AbstractBoundingBox boundingBox) {
         PayloadBuilder payload = RemoveBoundingBox.getPayload(dimensionId, boundingBox);
         if (payload == null) return;
@@ -95,7 +104,8 @@ public class CommonProxy {
         }
     }
 
-    private void sendBoundingBoxes(ServerPlayer player) {
+    private void onPlayerSubscribed(PlayerSubscribed event) {
+        ServerPlayer player = event.getPlayer();
         players.add(player);
         sendToPlayer(player, getCache(player.getDimensionId()));
     }
@@ -128,13 +138,6 @@ public class CommonProxy {
         return cacheSubset;
     }
 
-    protected void addBoundingBox(int dimensionId, AbstractBoundingBox key, Set<AbstractBoundingBox> boundingBoxes) {
-        BoundingBoxCache cache = getCache(dimensionId);
-        if (cache == null) return;
-
-        cache.addBoundingBoxes(key, boundingBoxes);
-    }
-
     protected void removeBoundingBox(int dimensionId, AbstractBoundingBox key) {
         BoundingBoxCache cache = getCache(dimensionId);
         if (cache == null) return;
@@ -142,8 +145,9 @@ public class CommonProxy {
         cache.removeBoundingBox(key);
     }
 
-    private void mobSpawnerBroken(int dimensionId, Coords pos) {
-        AbstractBoundingBox boundingBox = BoundingBoxMobSpawner.from(pos);
+    private void mobSpawnerBroken(MobSpawnerBroken event) {
+        int dimensionId = event.getDimensionId();
+        AbstractBoundingBox boundingBox = BoundingBoxMobSpawner.from(event.getPos());
         removeBoundingBox(dimensionId, boundingBox);
         sendRemoveBoundingBox(dimensionId, boundingBox);
     }
@@ -154,12 +158,11 @@ public class CommonProxy {
         }
     }
 
-    private void serverWorldTick(WorldServer world) {
-        int dimensionId = world.dimension.getType().getId();
-        VillageProcessor villageProcessor = villageProcessors.get(dimensionId);
+    private void serverWorldTick(ServerWorldTick event) {
+        VillageProcessor villageProcessor = villageProcessors.get(event.getDimensionId());
         if (villageProcessor == null) return;
 
-        villageProcessor.process(world.getVillageCollection());
+        villageProcessor.process(event.getWorld());
     }
 
     protected BoundingBoxCache getCache(int dimensionId) {
index d3871ad4e843b67af31c093e3721b652bff6fbdd..2e954ca8ae9fb3ea5cb4a5a85bc8a53aff1b8698 100644 (file)
@@ -6,6 +6,7 @@ import com.irtimaled.bbor.common.models.Coords;
 import net.minecraft.village.Village;
 import net.minecraft.village.VillageCollection;
 import net.minecraft.village.VillageDoorInfo;
+import net.minecraft.world.WorldServer;
 
 import java.util.*;
 
@@ -20,9 +21,10 @@ class VillageProcessor {
         this.boundingBoxCache = boundingBoxCache;
     }
 
-    void process(VillageCollection villageCollection) {
+    void process(WorldServer world) {
         Map<Integer, BoundingBoxVillage> oldVillages = new HashMap<>(villageCache);
         Map<Integer, BoundingBoxVillage> newVillages = new HashMap<>();
+        VillageCollection villageCollection = world.getVillageCollection();
         for (Village village : villageCollection.getVillageList()) {
             int villageId = village.hashCode();
             BoundingBoxVillage newVillage = oldVillages.get(villageId);
index 6dc6492449fafed2d009b5f60efd629660944e4f..fa3d677f2c3525a0ddf00c56534afde7a0203428 100644 (file)
@@ -4,12 +4,18 @@ import net.minecraft.world.chunk.Chunk;
 
 public class ChunkLoaded {
     private final Chunk chunk;
+    private final int dimensionId;
 
     public ChunkLoaded(Chunk chunk) {
         this.chunk = chunk;
+        this.dimensionId = chunk.getWorld().getDimension().getType().getId();
     }
 
     public Chunk getChunk() {
         return chunk;
     }
+
+    public int getDimensionId() {
+        return dimensionId;
+    }
 }
index f3f317b77135d12410384342a62ca965f3b276b3..8b20b87e9d349ea4aefe7fe6fad69c0947eb3784 100644 (file)
@@ -3,13 +3,19 @@ package com.irtimaled.bbor.common.events;
 import net.minecraft.world.WorldServer;
 
 public class ServerWorldTick {
+    private final int dimensionId;
     private WorldServer world;
 
     public ServerWorldTick(WorldServer world) {
         this.world = world;
+        this.dimensionId = world.getDimension().getType().getId();
     }
 
     public WorldServer getWorld() {
         return world;
     }
+
+    public int getDimensionId() {
+        return dimensionId;
+    }
 }
index 0315004a7faa85376f38ffa75f5978c856b0e43e..12596b341a94d0a169eefd2c3dd83fd050bce7f7 100644 (file)
@@ -1,15 +1,35 @@
 package com.irtimaled.bbor.common.events;
 
 import net.minecraft.world.WorldServer;
+import net.minecraft.world.storage.WorldInfo;
 
 public class WorldLoaded {
-    private final WorldServer world;
+    private final int dimensionId;
+    private final long seed;
+    private final int spawnX;
+    private final int spawnZ;
 
     public WorldLoaded(WorldServer world) {
-        this.world = world;
+        WorldInfo info = world.getWorldInfo();
+        this.dimensionId = world.getDimension().getType().getId();
+        this.seed = info.getSeed();
+        this.spawnX = info.getSpawnX();
+        this.spawnZ = info.getSpawnZ();
     }
 
-    public WorldServer getWorld() {
-        return world;
+    public int getDimensionId() {
+        return dimensionId;
+    }
+
+    public long getSeed() {
+        return seed;
+    }
+
+    public int getSpawnX() {
+        return spawnX;
+    }
+
+    public int getSpawnZ() {
+        return spawnZ;
     }
 }