diff --git a/java/com/irtimaled/bbor/ReflectionHelper.java b/java/com/irtimaled/bbor/ReflectionHelper.java deleted file mode 100644 index 2bd0a416..00000000 --- a/java/com/irtimaled/bbor/ReflectionHelper.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.irtimaled.bbor; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; - -public class ReflectionHelper { - public static R getPrivateValue(Class sourceClass, T instance, Class resultClass) { - try { - Field f = getField(sourceClass, resultClass); - if (f != null) { - return (R) f.get(instance); - } - } catch (Exception ignored) { - } - return null; - } - - private static Map> fieldMap = new HashMap<>(); - - private static Field getField(Class sourceClass, Class resultClass) { - Map map = fieldMap.computeIfAbsent(sourceClass, k -> new HashMap<>()); - Field field = map.get(resultClass); - if (field == null) { - field = getFieldUsingReflection(sourceClass, resultClass); - if (field != null) { - field.setAccessible(true); - map.put(resultClass, field); - } - } - return field; - } - - private static Field getFieldUsingReflection(Class sourceClass, Class resultClass) { - Field[] fields = sourceClass.getDeclaredFields(); - for (Field field : fields) { - if (field.getType().equals(resultClass)) - return field; - } - for (Field field : fields) { - if (resultClass.isAssignableFrom(field.getType())) - return field; - } - return null; - } -} diff --git a/java/com/irtimaled/bbor/client/BoundingBoxOutlineReloaded.java b/java/com/irtimaled/bbor/client/BoundingBoxOutlineReloaded.java index 06a26035..134710b5 100644 --- a/java/com/irtimaled/bbor/client/BoundingBoxOutlineReloaded.java +++ b/java/com/irtimaled/bbor/client/BoundingBoxOutlineReloaded.java @@ -12,7 +12,7 @@ public class BoundingBoxOutlineReloaded { private static ClientProxy proxy; public static void init() { - ConfigManager.loadConfig(new File(Minecraft.getMinecraft().mcDataDir, "config")); + ConfigManager.loadConfig(new File(Minecraft.getInstance().gameDir, "config")); proxy = new ClientProxy(); proxy.init(); } diff --git a/java/com/irtimaled/bbor/client/ClientBoundingBoxProvider.java b/java/com/irtimaled/bbor/client/ClientBoundingBoxProvider.java index 423df090..b535a104 100644 --- a/java/com/irtimaled/bbor/client/ClientBoundingBoxProvider.java +++ b/java/com/irtimaled/bbor/client/ClientBoundingBoxProvider.java @@ -11,7 +11,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.MathHelper; -import net.minecraft.world.DimensionType; +import net.minecraft.world.dimension.DimensionType; import java.awt.*; import java.util.HashSet; @@ -64,7 +64,7 @@ private Set getClientBoundingBoxes(DimensionType dimensionType) { } private Set getSlimeChunks() { - Minecraft minecraft = Minecraft.getMinecraft(); + Minecraft minecraft = Minecraft.getInstance(); int renderDistanceChunks = minecraft.gameSettings.renderDistanceChunks; int playerChunkX = MathHelper.floor(minecraft.player.posX / 16.0D); int playerChunkZ = MathHelper.floor(minecraft.player.posZ / 16.0D); diff --git a/java/com/irtimaled/bbor/client/ClientProxy.java b/java/com/irtimaled/bbor/client/ClientProxy.java index 22eb4ff2..f905eeb4 100644 --- a/java/com/irtimaled/bbor/client/ClientProxy.java +++ b/java/com/irtimaled/bbor/client/ClientProxy.java @@ -8,9 +8,8 @@ import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.NetworkManager; -import net.minecraft.world.DimensionType; +import net.minecraft.world.dimension.DimensionType; import org.apache.commons.lang3.ArrayUtils; -import org.lwjgl.input.Keyboard; import java.net.InetSocketAddress; import java.net.SocketAddress; @@ -36,16 +35,16 @@ public void keyPressed() { @Override public void init() { String category = "Bounding Box Outline Reloaded"; - activeHotKey = new KeyBinding("Toggle On/Off", Keyboard.KEY_B, category); - outerBoxOnlyHotKey = new KeyBinding("Toggle Display Outer Box Only", Keyboard.KEY_O, category); - Minecraft.getMinecraft().gameSettings.keyBindings = ArrayUtils.addAll(Minecraft.getMinecraft().gameSettings.keyBindings, activeHotKey, outerBoxOnlyHotKey); + activeHotKey = new KeyBinding("Toggle On/Off", 0x42, category); + outerBoxOnlyHotKey = new KeyBinding("Toggle Display Outer Box Only", 0x4f, category); + Minecraft.getInstance().gameSettings.keyBindings = ArrayUtils.addAll(Minecraft.getInstance().gameSettings.keyBindings, activeHotKey, outerBoxOnlyHotKey); ClientDimensionCache clientDimensionCache = new ClientDimensionCache(); renderer = new ClientRenderer(clientDimensionCache); dimensionCache = clientDimensionCache; } public void render(float partialTicks) { - EntityPlayer entityPlayer = Minecraft.getMinecraft().player; + EntityPlayer entityPlayer = Minecraft.getInstance().player; PlayerData.setPlayerPosition(partialTicks, entityPlayer); if (this.active) { diff --git a/java/com/irtimaled/bbor/client/ClientRenderer.java b/java/com/irtimaled/bbor/client/ClientRenderer.java index 697c26b7..61ba3921 100644 --- a/java/com/irtimaled/bbor/client/ClientRenderer.java +++ b/java/com/irtimaled/bbor/client/ClientRenderer.java @@ -4,7 +4,7 @@ import com.irtimaled.bbor.common.models.*; import com.irtimaled.bbor.config.ConfigManager; import net.minecraft.client.Minecraft; -import net.minecraft.world.DimensionType; +import net.minecraft.world.dimension.DimensionType; import org.lwjgl.opengl.GL11; import java.util.HashMap; @@ -24,7 +24,7 @@ public class ClientRenderer { } public void render(DimensionType dimensionType, Boolean outerBoxesOnly) { - Set boundingBoxes = clientBoundingBoxProvider.getBoundingBoxes(dimensionType, outerBoxesOnly, Minecraft.getMinecraft().world); + Set boundingBoxes = clientBoundingBoxProvider.getBoundingBoxes(dimensionType, outerBoxesOnly, Minecraft.getInstance().world); if (boundingBoxes == null || boundingBoxes.size() == 0) return; diff --git a/java/com/irtimaled/bbor/client/NBTFileParser.java b/java/com/irtimaled/bbor/client/NBTFileParser.java index f647d9c1..719fb189 100644 --- a/java/com/irtimaled/bbor/client/NBTFileParser.java +++ b/java/com/irtimaled/bbor/client/NBTFileParser.java @@ -12,7 +12,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.DimensionType; +import net.minecraft.world.dimension.DimensionType; import java.awt.*; import java.io.File; @@ -180,8 +180,8 @@ private static NBTTagCompound loadNbtFile(File file) { private static NBTTagCompound[] getChildCompoundTags(NBTTagCompound parent, String key) { NBTTagList tagList = parent.getTagList(key, 10); - NBTTagCompound[] result = new NBTTagCompound[tagList.tagCount()]; - for (int index = 0; index < tagList.tagCount(); index++) { + NBTTagCompound[] result = new NBTTagCompound[tagList.size()]; + for (int index = 0; index < tagList.size(); index++) { result[index] = tagList.getCompoundTagAt(index); } return result; diff --git a/java/com/irtimaled/bbor/client/renderers/SlimeChunkRenderer.java b/java/com/irtimaled/bbor/client/renderers/SlimeChunkRenderer.java index 1ba37657..173007ac 100644 --- a/java/com/irtimaled/bbor/client/renderers/SlimeChunkRenderer.java +++ b/java/com/irtimaled/bbor/client/renderers/SlimeChunkRenderer.java @@ -1,7 +1,7 @@ package com.irtimaled.bbor.client.renderers; -import com.irtimaled.bbor.common.models.BoundingBoxSlimeChunk; import com.irtimaled.bbor.client.PlayerData; +import com.irtimaled.bbor.common.models.BoundingBoxSlimeChunk; import com.irtimaled.bbor.config.ConfigManager; import net.minecraft.util.math.AxisAlignedBB; diff --git a/java/com/irtimaled/bbor/client/renderers/VillageRenderer.java b/java/com/irtimaled/bbor/client/renderers/VillageRenderer.java index d5bee1f4..88392e00 100644 --- a/java/com/irtimaled/bbor/client/renderers/VillageRenderer.java +++ b/java/com/irtimaled/bbor/client/renderers/VillageRenderer.java @@ -1,7 +1,7 @@ package com.irtimaled.bbor.client.renderers; -import com.irtimaled.bbor.common.models.BoundingBoxVillage; import com.irtimaled.bbor.client.PlayerData; +import com.irtimaled.bbor.common.models.BoundingBoxVillage; import com.irtimaled.bbor.config.ConfigManager; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Tessellator; diff --git a/java/com/irtimaled/bbor/client/renderers/WorldSpawnRenderer.java b/java/com/irtimaled/bbor/client/renderers/WorldSpawnRenderer.java index 98ac02d9..96e07acc 100644 --- a/java/com/irtimaled/bbor/client/renderers/WorldSpawnRenderer.java +++ b/java/com/irtimaled/bbor/client/renderers/WorldSpawnRenderer.java @@ -1,7 +1,7 @@ package com.irtimaled.bbor.client.renderers; -import com.irtimaled.bbor.common.models.BoundingBoxWorldSpawn; import com.irtimaled.bbor.client.PlayerData; +import com.irtimaled.bbor.common.models.BoundingBoxWorldSpawn; import com.irtimaled.bbor.config.ConfigManager; import net.minecraft.util.math.AxisAlignedBB; diff --git a/java/com/irtimaled/bbor/common/CommonProxy.java b/java/com/irtimaled/bbor/common/CommonProxy.java index 68e338b6..115cf2be 100644 --- a/java/com/irtimaled/bbor/common/CommonProxy.java +++ b/java/com/irtimaled/bbor/common/CommonProxy.java @@ -1,14 +1,13 @@ package com.irtimaled.bbor.common; + import com.irtimaled.bbor.Logger; -import com.irtimaled.bbor.ReflectionHelper; import com.irtimaled.bbor.config.ConfigManager; -import net.minecraft.world.DimensionType; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.gen.ChunkProviderServer; -import net.minecraft.world.gen.IChunkGenerator; import java.util.HashSet; import java.util.Set; @@ -22,11 +21,10 @@ public class CommonProxy { public void worldLoaded(World world) { IChunkProvider chunkProvider = world.getChunkProvider(); if (chunkProvider instanceof ChunkProviderServer) { - IChunkGenerator chunkGenerator = ReflectionHelper.getPrivateValue(ChunkProviderServer.class, (ChunkProviderServer) chunkProvider, IChunkGenerator.class); dimensionCache.setWorldData(world.getSeed(), world.getWorldInfo().getSpawnX(), world.getWorldInfo().getSpawnZ()); - DimensionType dimensionType = world.provider.getDimensionType(); - Logger.info("create world dimension: %s, %s (chunkprovider: %s) (seed: %d)", dimensionType, world.getClass().toString(), chunkGenerator.getClass().toString(), world.getSeed()); - DimensionProcessor boundingBoxCache = new DimensionProcessor(dimensionType, chunkGenerator); + DimensionType dimensionType = world.dimension.getType(); + Logger.info("create world dimension: %s, %s (seed: %d)", dimensionType, world.getClass().toString(), world.getSeed()); + DimensionProcessor boundingBoxCache = new DimensionProcessor(dimensionType, (ChunkProviderServer)chunkProvider); dimensionCache.put(dimensionType, boundingBoxCache); if (ConfigManager.drawVillages.getBoolean()) { villageProcessors.add(new VillageProcessor(world, dimensionType, eventHandler, boundingBoxCache)); @@ -35,7 +33,7 @@ public void worldLoaded(World world) { } public void chunkLoaded(Chunk chunk) { - DimensionType dimensionType = chunk.getWorld().provider.getDimensionType(); + DimensionType dimensionType = chunk.getWorld().dimension.getType(); dimensionCache.refresh(dimensionType); } diff --git a/java/com/irtimaled/bbor/common/DimensionCache.java b/java/com/irtimaled/bbor/common/DimensionCache.java index a6c8f24d..86004d57 100644 --- a/java/com/irtimaled/bbor/common/DimensionCache.java +++ b/java/com/irtimaled/bbor/common/DimensionCache.java @@ -1,7 +1,7 @@ package com.irtimaled.bbor.common; import com.irtimaled.bbor.common.models.WorldData; -import net.minecraft.world.DimensionType; +import net.minecraft.world.dimension.DimensionType; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; diff --git a/java/com/irtimaled/bbor/common/DimensionProcessor.java b/java/com/irtimaled/bbor/common/DimensionProcessor.java index 7ea59c41..c9ed1c44 100644 --- a/java/com/irtimaled/bbor/common/DimensionProcessor.java +++ b/java/com/irtimaled/bbor/common/DimensionProcessor.java @@ -1,122 +1,92 @@ package com.irtimaled.bbor.common; import com.irtimaled.bbor.Logger; -import com.irtimaled.bbor.ReflectionHelper; import com.irtimaled.bbor.common.models.BoundingBox; import com.irtimaled.bbor.common.models.BoundingBoxStructure; import com.irtimaled.bbor.config.ConfigManager; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.DimensionType; -import net.minecraft.world.gen.ChunkGeneratorEnd; -import net.minecraft.world.gen.ChunkGeneratorHell; -import net.minecraft.world.gen.ChunkGeneratorOverworld; -import net.minecraft.world.gen.IChunkGenerator; -import net.minecraft.world.gen.structure.*; +import com.irtimaled.bbor.config.Setting; +import net.minecraft.util.math.MutableBoundingBox; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.dimension.DimensionType; +import net.minecraft.world.gen.ChunkProviderServer; +import net.minecraft.world.gen.feature.structure.StructurePiece; +import net.minecraft.world.gen.feature.structure.StructureStart; import java.awt.*; import java.util.*; public class DimensionProcessor extends BoundingBoxCache { - DimensionProcessor(DimensionType dimensionType, IChunkGenerator chunkGenerator) { + DimensionProcessor(DimensionType dimensionType, ChunkProviderServer chunkProvider) { this.dimensionType = dimensionType; - this.chunkGenerator = chunkGenerator; + this.chunkProvider = chunkProvider; } private DimensionType dimensionType; - private IChunkGenerator chunkGenerator; + private ChunkProviderServer chunkProvider; private boolean closed = false; @Override public void close() { closed = true; - chunkGenerator = null; super.close(); } - private static Collection getStructures(T chunkGenerator, Class generatorClass) { - Class chunkGeneratorClass = (Class) chunkGenerator.getClass(); - R structureGenerator = ReflectionHelper.getPrivateValue(chunkGeneratorClass, chunkGenerator, generatorClass); - if (structureGenerator != null) { - Map structureMap = ReflectionHelper.getPrivateValue(MapGenStructure.class, structureGenerator, Map.class); - return structureMap.values(); - } - return Collections.emptyList(); - } - - private Map> getStructures() { - Map> structureMap = new HashMap<>(); - if (chunkGenerator instanceof ChunkGeneratorOverworld) { - if (ConfigManager.drawDesertTemples.getBoolean()) { - structureMap.put(StructureType.DesertTemple, getStructuresWithComponent(getStructures(chunkGenerator, MapGenScatteredFeature.class), ComponentScatteredFeaturePieces.DesertPyramid.class)); - } + private void addStructures(Setting drawStructure, StructureType structureType, Map> structureMap) { + if (!drawStructure.getBoolean()) return; - if (ConfigManager.drawJungleTemples.getBoolean()) { - structureMap.put(StructureType.JungleTemple, getStructuresWithComponent(getStructures(chunkGenerator, MapGenScatteredFeature.class), ComponentScatteredFeaturePieces.JunglePyramid.class)); - } + Collection structureStarts = structureMap.get(structureType.getName()); + if (structureStarts == null || structureStarts.size() == 0) return; + Color color = structureType.getColor(); + for (StructureStart structureStart : structureStarts) { - if (ConfigManager.drawWitchHuts.getBoolean()) { - structureMap.put(StructureType.WitchHut, getStructuresWithComponent(getStructures(chunkGenerator, MapGenScatteredFeature.class), ComponentScatteredFeaturePieces.SwampHut.class)); - } + MutableBoundingBox bb = structureStart.getBoundingBox(); + if(bb == null) + continue; - if (ConfigManager.drawOceanMonuments.getBoolean()) { - structureMap.put(StructureType.OceanMonument, getStructures(chunkGenerator, StructureOceanMonument.class)); - } + BoundingBox boundingBox = BoundingBoxStructure.from(bb, color); + if (isCached(boundingBox)) continue; - if (ConfigManager.drawStrongholds.getBoolean()) { - structureMap.put(StructureType.Stronghold, getStructures(chunkGenerator, MapGenStronghold.class)); - } - - if (ConfigManager.drawMansions.getBoolean()) { - structureMap.put(StructureType.Mansion, getStructures(chunkGenerator, WoodlandMansion.class)); - } - - if (ConfigManager.drawMineShafts.getBoolean()) { - structureMap.put(StructureType.MineShaft, getStructures(chunkGenerator, MapGenMineshaft.class)); - } - } else if (chunkGenerator instanceof ChunkGeneratorHell) { - if (ConfigManager.drawNetherFortresses.getBoolean()) { - structureMap.put(StructureType.NetherFortress, getStructures(chunkGenerator, MapGenNetherBridge.class)); - } - } else if (chunkGenerator instanceof ChunkGeneratorEnd) { - if (ConfigManager.drawEndCities.getBoolean()) { - structureMap.put(StructureType.EndCity, getStructures(chunkGenerator, MapGenEndCity.class)); + Set structureBoundingBoxes = new HashSet<>(); + for (StructurePiece structureComponent : structureStart.getComponents()) { + structureBoundingBoxes.add(BoundingBoxStructure.from(structureComponent.getBoundingBox(), color)); } + addBoundingBoxes(boundingBox, structureBoundingBoxes); + Logger.info("[%s] new dimensionCache entries: %d", dimensionType, structureBoundingBoxes.size()); } - - return structureMap; } - private Collection getStructuresWithComponent(Collection structures, Class structureComponent) { - Collection validStructures = new HashSet<>(); - for (StructureStart structure : structures) { - if (structure.getComponents().get(0).getClass().equals(structureComponent)) { - validStructures.add(structure); + private Map> getStructureMap(ChunkProviderServer chunkProvider) { + Map> map = new HashMap<>(); + for (Chunk chunk : chunkProvider.getLoadedChunks()) { + Map structureStarts = chunk.getStructureStarts(); + for (String key : structureStarts.keySet()) { + map.computeIfAbsent(key, s -> new HashSet<>()) + .add(structureStarts.get(key)); } } - return validStructures; + return map; } @Override public synchronized void refresh() { if (closed) return; - Map> structureMap = getStructures(); - for (StructureType structureType : structureMap.keySet()) { - Color color = structureType.getColor(); - for (StructureStart structureStart : structureMap.get(structureType)) { - if (structureStart.getBoundingBox() != null) { - BoundingBox boundingBox = BoundingBoxStructure.from(structureStart.getBoundingBox(), color); - if (!isCached(boundingBox)) { - Set structureBoundingBoxes = new HashSet<>(); - for (StructureComponent structureComponent : structureStart.getComponents()) { - structureBoundingBoxes.add(BoundingBoxStructure.from(structureComponent.getBoundingBox(), color)); - } - addBoundingBoxes(boundingBox, structureBoundingBoxes); - Logger.info("[%s] new dimensionCache entries: %d", dimensionType, structureBoundingBoxes.size()); - } - } - } + Map> structureMap = getStructureMap(chunkProvider); + if (structureMap.size() > 0) { + addStructures(ConfigManager.drawDesertTemples, StructureType.DesertTemple, structureMap); + addStructures(ConfigManager.drawJungleTemples, StructureType.JungleTemple, structureMap); + addStructures(ConfigManager.drawWitchHuts, StructureType.WitchHut, structureMap); + addStructures(ConfigManager.drawOceanMonuments, StructureType.OceanMonument, structureMap); + addStructures(ConfigManager.drawStrongholds, StructureType.Stronghold, structureMap); + addStructures(ConfigManager.drawMansions, StructureType.Mansion, structureMap); + addStructures(ConfigManager.drawMineShafts, StructureType.MineShaft, structureMap); + addStructures(ConfigManager.drawShipwrecks, StructureType.Shipwreck, structureMap); + addStructures(ConfigManager.drawOceanRuins, StructureType.OceanRuin, structureMap); + addStructures(ConfigManager.drawBuriedTreasure, StructureType.BuriedTreasure, structureMap); + addStructures(ConfigManager.drawIgloos, StructureType.Igloo, structureMap); + addStructures(ConfigManager.drawNetherFortresses, StructureType.NetherFortress, structureMap); + addStructures(ConfigManager.drawEndCities, StructureType.EndCity, structureMap); } } } diff --git a/java/com/irtimaled/bbor/common/IVillageEventHandler.java b/java/com/irtimaled/bbor/common/IVillageEventHandler.java index b8df1c8e..d28efffc 100644 --- a/java/com/irtimaled/bbor/common/IVillageEventHandler.java +++ b/java/com/irtimaled/bbor/common/IVillageEventHandler.java @@ -1,7 +1,7 @@ package com.irtimaled.bbor.common; import com.irtimaled.bbor.common.models.BoundingBox; -import net.minecraft.world.DimensionType; +import net.minecraft.world.dimension.DimensionType; public interface IVillageEventHandler { void villageRemoved(DimensionType dimensionType, BoundingBox bb); diff --git a/java/com/irtimaled/bbor/common/StructureType.java b/java/com/irtimaled/bbor/common/StructureType.java index 9f7e87a6..a1493ad4 100644 --- a/java/com/irtimaled/bbor/common/StructureType.java +++ b/java/com/irtimaled/bbor/common/StructureType.java @@ -1,55 +1,34 @@ package com.irtimaled.bbor.common; - import java.awt.*; public class StructureType { - private static final int JUNGLE_TEMPLE = 1; - private static final int DESERT_TEMPLE = 2; - private static final int WITCH_HUT = 3; - private static final int OCEAN_MONUMENT = 4; - private static final int STRONGHOLD = 5; - private static final int MINE_SHAFT = 6; - private static final int NETHER_FORTRESS = 7; - private static final int END_CITY = 8; - private static final int MANSION = 9; - - public final static StructureType JungleTemple = new StructureType(JUNGLE_TEMPLE); - public final static StructureType DesertTemple = new StructureType(DESERT_TEMPLE); - public final static StructureType WitchHut = new StructureType(WITCH_HUT); - public final static StructureType OceanMonument = new StructureType(OCEAN_MONUMENT); - public final static StructureType Stronghold = new StructureType(STRONGHOLD); - public final static StructureType MineShaft = new StructureType(MINE_SHAFT); - public final static StructureType NetherFortress = new StructureType(NETHER_FORTRESS); - public final static StructureType EndCity = new StructureType(END_CITY); - public final static StructureType Mansion = new StructureType(MANSION); + public final static StructureType JungleTemple = new StructureType(Color.GREEN, "Jungle_Pyramid"); + public final static StructureType DesertTemple = new StructureType(Color.ORANGE, "Desert_Pyramid"); + public final static StructureType WitchHut = new StructureType(Color.BLUE, "Swamp_Hut"); + public final static StructureType OceanMonument = new StructureType(Color.CYAN, "Monument"); + public final static StructureType Shipwreck = new StructureType(Color.CYAN, "Shipwreck"); + public final static StructureType OceanRuin = new StructureType(Color.CYAN, "Ocean_Ruin"); + public final static StructureType BuriedTreasure = new StructureType(Color.CYAN, "Buried_Treasure"); + public final static StructureType Stronghold = new StructureType(Color.YELLOW, "Stronghold"); + public final static StructureType MineShaft = new StructureType(Color.LIGHT_GRAY, "Mineshaft"); + public final static StructureType NetherFortress = new StructureType(Color.RED, "Fortress"); + public final static StructureType EndCity = new StructureType(Color.MAGENTA, "EndCity"); + public final static StructureType Mansion = new StructureType(new Color(139, 69, 19), "Mansion"); + public final static StructureType Igloo = new StructureType(Color.WHITE, "Igloo"); - private final int type; + private final Color color; + private String name; - private StructureType(int type) { - this.type = type; + private StructureType(Color color, String name) { + this.color = color; + this.name = name; } public Color getColor() { - switch (type) { - case DESERT_TEMPLE: - return Color.ORANGE; - case JUNGLE_TEMPLE: - return Color.GREEN; - case WITCH_HUT: - return Color.BLUE; - case MINE_SHAFT: - return Color.LIGHT_GRAY; - case NETHER_FORTRESS: - return Color.RED; - case OCEAN_MONUMENT: - return Color.CYAN; - case STRONGHOLD: - return Color.YELLOW; - case END_CITY: - return Color.MAGENTA; - case MANSION: - return new Color(139, 69, 19); - } - return Color.WHITE; + return color; + } + + public String getName() { + return name; } } diff --git a/java/com/irtimaled/bbor/common/VillageProcessor.java b/java/com/irtimaled/bbor/common/VillageProcessor.java index ce4cd7f0..2bdbe6ea 100644 --- a/java/com/irtimaled/bbor/common/VillageProcessor.java +++ b/java/com/irtimaled/bbor/common/VillageProcessor.java @@ -3,8 +3,8 @@ import com.irtimaled.bbor.common.models.BoundingBoxVillage; import net.minecraft.village.Village; import net.minecraft.village.VillageCollection; -import net.minecraft.world.DimensionType; import net.minecraft.world.World; +import net.minecraft.world.dimension.DimensionType; import java.util.HashMap; import java.util.List; diff --git a/java/com/irtimaled/bbor/common/models/BoundingBoxStructure.java b/java/com/irtimaled/bbor/common/models/BoundingBoxStructure.java index 97f2602f..50c53a05 100644 --- a/java/com/irtimaled/bbor/common/models/BoundingBoxStructure.java +++ b/java/com/irtimaled/bbor/common/models/BoundingBoxStructure.java @@ -1,7 +1,7 @@ package com.irtimaled.bbor.common.models; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.gen.structure.StructureBoundingBox; +import net.minecraft.util.math.MutableBoundingBox; import java.awt.*; @@ -10,7 +10,7 @@ private BoundingBoxStructure(BlockPos minBlockPos, BlockPos maxBlockPos, Color c super(minBlockPos, maxBlockPos, color); } - public static BoundingBoxStructure from(StructureBoundingBox bb, Color color) { + public static BoundingBoxStructure from(MutableBoundingBox bb, Color color) { BlockPos minBlockPos = new BlockPos(bb.minX, bb.minY, bb.minZ); BlockPos maxBlockPos = new BlockPos(bb.maxX, bb.maxY, bb.maxZ); return new BoundingBoxStructure(minBlockPos, maxBlockPos, color); diff --git a/java/com/irtimaled/bbor/common/models/BoundingBoxVillage.java b/java/com/irtimaled/bbor/common/models/BoundingBoxVillage.java index 427aa45d..44bfcfbc 100644 --- a/java/com/irtimaled/bbor/common/models/BoundingBoxVillage.java +++ b/java/com/irtimaled/bbor/common/models/BoundingBoxVillage.java @@ -6,8 +6,9 @@ import net.minecraft.village.VillageDoorInfo; import java.awt.*; -import java.util.*; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class BoundingBoxVillage extends BoundingBox { private final BlockPos center; diff --git a/java/com/irtimaled/bbor/config/ConfigManager.java b/java/com/irtimaled/bbor/config/ConfigManager.java index 37227f9b..a280d1d7 100644 --- a/java/com/irtimaled/bbor/config/ConfigManager.java +++ b/java/com/irtimaled/bbor/config/ConfigManager.java @@ -26,9 +26,14 @@ public class ConfigManager { public static Setting drawLazySpawnChunks; public static Setting drawEndCities; public static Setting drawMansions; + public static Setting drawShipwrecks; + public static Setting drawOceanRuins; + public static Setting drawBuriedTreasure; + public static Setting drawIgloos; public static void loadConfig(File mcConfigDir) { configDir = mcConfigDir; + configDir.mkdirs(); Configuration config = new Configuration(new File(configDir, "BBOutlineReloaded.cfg")); config.load(); @@ -53,6 +58,10 @@ public static void loadConfig(File mcConfigDir) { drawLazySpawnChunks = SetupBooleanProperty(config, "features", "drawLazySpawnChunks", false, "If set to true the lazy spawn chunks bounding boxes will be drawn. (default: false)"); drawEndCities = SetupBooleanProperty(config, "features", "drawEndCities", true, "If set to true end city bounding boxes will be drawn. (default: true)"); drawMansions = SetupBooleanProperty(config, "features", "drawMansions", true, "If set to true woodland mansions will be drawn. (default: true)"); + drawShipwrecks = SetupBooleanProperty(config, "features", "drawShipwrecks", false, "If set to true shipwrecks will be drawn. (default: false)"); + drawOceanRuins = SetupBooleanProperty(config, "features", "drawOceanRuins", false, "If set to true ocean ruins will be drawn. (default: false)"); + drawBuriedTreasure = SetupBooleanProperty(config, "features", "drawBuriedTreasures", false, "If set to true buried treasure will be drawn. (default: false)"); + drawIgloos = SetupBooleanProperty(config, "features", "drawIgloos", false, "If set to true igloos will be drawn. (default: false)"); config.save(); } diff --git a/java/com/irtimaled/bbor/forge/ForgeClientProxy.java b/java/com/irtimaled/bbor/forge/ForgeClientProxy.java deleted file mode 100644 index 0ec1a8b5..00000000 --- a/java/com/irtimaled/bbor/forge/ForgeClientProxy.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.irtimaled.bbor.forge; - -import com.irtimaled.bbor.client.ClientProxy; -import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.client.event.RenderWorldLastEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.InputEvent; -import net.minecraftforge.fml.common.network.FMLNetworkEvent; - -public class ForgeClientProxy extends ForgeCommonProxy { - private ClientProxy proxy; - - @Override - public ClientProxy getProxy() { - if (proxy == null) { - proxy = new ClientProxy(); - } - return proxy; - } - - @SubscribeEvent - public void onKeyInputEvent(InputEvent.KeyInputEvent evt) { - getProxy().keyPressed(); - } - - @Override - protected void onRegisteredPlayerCountChanged(int registeredPlayerCount) { - getProxy().setRemoteUserCount(registeredPlayerCount-1); - } - - @Override - protected boolean isRemotePlayer(EntityPlayer player) { - if (Minecraft.getMinecraft().isSingleplayer()) { - EntityPlayer singlePlayer = Minecraft.getMinecraft().player; - return singlePlayer != null && player.getGameProfile() != singlePlayer.getGameProfile(); - } - return true; - } - - @SubscribeEvent - public void renderWorldLastEvent(RenderWorldLastEvent event) { - getProxy().render(event.getPartialTicks()); - } - - @SubscribeEvent - public void clientConnectionToServerEvent(FMLNetworkEvent.ClientConnectedToServerEvent evt) { - if (!evt.isLocal()) { - getProxy().playerConnectedToServer(evt.getManager()); - } - } - - @SubscribeEvent - public void clientDisconnectionFromServerEvent(FMLNetworkEvent.ClientDisconnectionFromServerEvent evt) { - getProxy().playerDisconnectedFromServer(); - } -} diff --git a/java/com/irtimaled/bbor/forge/ForgeCommonProxy.java b/java/com/irtimaled/bbor/forge/ForgeCommonProxy.java deleted file mode 100644 index 956275f0..00000000 --- a/java/com/irtimaled/bbor/forge/ForgeCommonProxy.java +++ /dev/null @@ -1,206 +0,0 @@ -package com.irtimaled.bbor.forge; - -import com.irtimaled.bbor.Logger; -import com.irtimaled.bbor.common.BoundingBoxCache; -import com.irtimaled.bbor.common.CommonProxy; -import com.irtimaled.bbor.common.DimensionCache; -import com.irtimaled.bbor.common.IVillageEventHandler; -import com.irtimaled.bbor.common.models.BoundingBox; -import com.irtimaled.bbor.forge.messages.*; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.network.NetHandlerPlayServer; -import net.minecraft.server.MinecraftServer; -import net.minecraft.world.DimensionType; -import net.minecraft.world.World; -import net.minecraftforge.event.world.ChunkEvent; -import net.minecraftforge.event.world.WorldEvent; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.PlayerEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; -import net.minecraftforge.fml.common.network.FMLNetworkEvent; -import net.minecraftforge.fml.common.network.NetworkRegistry; -import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; -import net.minecraftforge.fml.relauncher.Side; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -public class ForgeCommonProxy implements IVillageEventHandler { - private Map playerDimensions = new ConcurrentHashMap<>(); - private Map> playerBoundingBoxesCache = new HashMap<>(); - private HashSet registeredPlayers = new HashSet<>(); - - protected CommonProxy getProxy() { - if (commonProxy == null) - commonProxy = new CommonProxy(); - return commonProxy; - } - - @SubscribeEvent - public void packetRegistrationEvent(FMLNetworkEvent.CustomPacketRegistrationEvent event) { - if (event.getOperation().equals("REGISTER") && - event.getRegistrations().contains("bbor") && - event.getHandler() instanceof NetHandlerPlayServer) { - registeredPlayers.add(((NetHandlerPlayServer) event.getHandler()).player); - onRegisteredPlayerCountChanged(registeredPlayers.size()); - } - } - - protected SimpleNetworkWrapper network; - private CommonProxy commonProxy; - - void init() { - CommonProxy proxy = getProxy(); - proxy.setEventHandler(this); - proxy.init(); - network = NetworkRegistry.INSTANCE.newSimpleChannel("bbor"); - network.registerMessage(AddBoundingBoxMessageHandler.class, AddBoundingBoxMessage.class, 0, Side.CLIENT); - network.registerMessage(RemoveBoundingBoxMessageHandler.class, RemoveBoundingBoxMessage.class, 1, Side.CLIENT); - network.registerMessage(InitializeClientMessageHandler.class, InitializeClientMessage.class, 2, Side.CLIENT); - } - - @SubscribeEvent - public void worldEvent(WorldEvent.Load event) { - World world = event.getWorld(); - getProxy().worldLoaded(world); - } - - @SubscribeEvent - public void chunkEvent(ChunkEvent.Load event) { - getProxy().chunkLoaded(event.getChunk()); - } - - @SubscribeEvent - public void playerChangedDimensionEvent(PlayerEvent.PlayerChangedDimensionEvent evt) { - if (playerDimensions.containsKey(evt.player)) { - EntityPlayerMP player = (EntityPlayerMP) evt.player; - sendBoundingBoxes(player); - } - } - - @SubscribeEvent - public void playerLoggedInEvent(PlayerEvent.PlayerLoggedInEvent evt) { - if (evt.player instanceof EntityPlayerMP && - isRemotePlayer(evt.player)) { - EntityPlayerMP player = (EntityPlayerMP) evt.player; - initializeClient(player); - sendBoundingBoxes(player); - } - } - - private void sendBoundingBoxes(EntityPlayerMP player) { - DimensionType dimensionType = DimensionType.getById(player.dimension); - playerDimensions.put(player, dimensionType); - sendToPlayer(player, getDimensionCache().getBoundingBoxes(dimensionType)); - } - - protected boolean isRemotePlayer(EntityPlayer player) { - return registeredPlayers.contains(player); - } - - private void initializeClient(EntityPlayerMP player) { - network.sendTo(InitializeClientMessage.from(getDimensionCache().getWorldData()), player); - } - - @SubscribeEvent - public void playerLoggedOutEvent(PlayerEvent.PlayerLoggedOutEvent evt) { - if (isRemotePlayer(evt.player)) { - playerDimensions.remove(evt.player); - playerBoundingBoxesCache.remove(evt.player); - registeredPlayers.remove(evt.player); - onRegisteredPlayerCountChanged(registeredPlayers.size()); - } - } - - protected void onRegisteredPlayerCountChanged(int registeredPlayerCount) { - } - - @SubscribeEvent - public void tickEvent(TickEvent event) { - for (EntityPlayerMP player : playerDimensions.keySet()) { - MinecraftServer mc = FMLCommonHandler.instance().getMinecraftServerInstance(); - if (!mc.getPlayerList().getPlayers().contains(player)) { - playerDimensions.remove(player); - } else { - DimensionType dimensionType = playerDimensions.get(player); - sendToPlayer(player, getDimensionCache().getBoundingBoxes(dimensionType)); - } - } - getProxy().tick(); - } - - private void sendToPlayer(EntityPlayerMP player, BoundingBoxCache boundingBoxCache) { - if (boundingBoxCache == null) - return; - Map> cacheSubset = getBoundingBoxMap(player, boundingBoxCache.getBoundingBoxes()); - - DimensionType dimensionType = DimensionType.getById(player.dimension); - if (cacheSubset.keySet().size() > 0) { - Logger.info("send %d entries to %s (%s)", cacheSubset.keySet().size(), player.getDisplayNameString(), dimensionType); - } - - for (BoundingBox key : cacheSubset.keySet()) { - Set boundingBoxes = cacheSubset.get(key); - network.sendTo(AddBoundingBoxMessage.from(dimensionType, key, boundingBoxes), player); - - if (!playerBoundingBoxesCache.containsKey(player)) { - playerBoundingBoxesCache.put(player, new HashSet<>()); - } - playerBoundingBoxesCache.get(player).add(key); - } - } - - private Map> getBoundingBoxMap(EntityPlayerMP player, Map> boundingBoxMap) { - Map> cacheSubset = new HashMap<>(); - for (BoundingBox key : boundingBoxMap.keySet()) { - if (!playerBoundingBoxesCache.containsKey(player) || !playerBoundingBoxesCache.get(player).contains(key)) { - cacheSubset.put(key, boundingBoxMap.get(key)); - } - } - return cacheSubset; - } - - public void villageRemoved(DimensionType dimensionType, BoundingBox bb) { - RemoveBoundingBoxMessage message = RemoveBoundingBoxMessage.from(dimensionType, bb); - for (EntityPlayerMP player : playerDimensions.keySet()) { - if (DimensionType.getById(player.dimension) == dimensionType) { - Logger.info("remove 1 entry from %s (%s)", player.getDisplayNameString(), dimensionType); - network.sendTo(message, player); - - if (playerBoundingBoxesCache.containsKey(player) && - playerBoundingBoxesCache.get(player).contains(bb)) { - playerBoundingBoxesCache.get(player).remove(bb); - } - } - } - } - - public void setWorldData(long seed, int spawnX, int spawnZ) { - getDimensionCache().setWorldData(seed, spawnX, spawnZ); - } - - public void addBoundingBox(DimensionType dimensionType, BoundingBox key, Set boundingBoxes) { - DimensionCache dimensionCache = getDimensionCache(); - BoundingBoxCache cache = dimensionCache.getBoundingBoxes(dimensionType); - if (cache == null) { - dimensionCache.put(dimensionType, cache = new BoundingBoxCache()); - } - cache.addBoundingBoxes(key, boundingBoxes); - } - - public void removeBoundingBox(DimensionType dimensionType, BoundingBox key) { - BoundingBoxCache cache = getDimensionCache().getBoundingBoxes(dimensionType); - if (cache != null) { - cache.removeBoundingBox(key); - } - } - - private DimensionCache getDimensionCache() { - return getProxy().getDimensionCache(); - } -} diff --git a/java/com/irtimaled/bbor/forge/ForgeMod.java b/java/com/irtimaled/bbor/forge/ForgeMod.java deleted file mode 100644 index 3311a068..00000000 --- a/java/com/irtimaled/bbor/forge/ForgeMod.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.irtimaled.bbor.forge; - -import com.irtimaled.bbor.config.ConfigManager; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.SidedProxy; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; - -@Mod(modid = ForgeMod.MODID, name = ForgeMod.NAME, version = ForgeMod.VERSION, acceptedMinecraftVersions = ForgeMod.MCVERSION, acceptableRemoteVersions = "*") -public class ForgeMod { - static final String MODID = "bbor"; - static final String NAME = "BoundingBoxOutlineReloaded"; - static final String VERSION = "1.0.3"; - static final String MCVERSION = "1.12.2"; - - public SimpleNetworkWrapper network; - - @Mod.Instance() - public static ForgeMod instance; - - @SidedProxy(clientSide = "com.irtimaled.bbor.forge.ForgeClientProxy", serverSide = "com.irtimaled.bbor.forge.ForgeCommonProxy") - public static ForgeCommonProxy proxy; - - @Mod.EventHandler - public void preInit(FMLPreInitializationEvent evt) { - ConfigManager.loadConfig(evt.getModConfigurationDirectory()); - } - - @Mod.EventHandler - public void load(FMLInitializationEvent evt) { - MinecraftForge.EVENT_BUS.register(proxy); - proxy.init(); - } -} diff --git a/java/com/irtimaled/bbor/forge/messages/AddBoundingBoxMessage.java b/java/com/irtimaled/bbor/forge/messages/AddBoundingBoxMessage.java deleted file mode 100644 index 26f5cb4d..00000000 --- a/java/com/irtimaled/bbor/forge/messages/AddBoundingBoxMessage.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.irtimaled.bbor.forge.messages; - -import com.irtimaled.bbor.common.models.BoundingBox; -import io.netty.buffer.ByteBuf; -import net.minecraft.world.DimensionType; -import net.minecraftforge.fml.common.network.ByteBufUtils; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; - -import java.util.HashSet; -import java.util.Set; - -public class AddBoundingBoxMessage implements IMessage { - private DimensionType dimensionType; - private BoundingBox key; - private Set boundingBoxes; - - public static AddBoundingBoxMessage from(DimensionType dimensionType, BoundingBox key, Set boundingBoxes) { - AddBoundingBoxMessage message = new AddBoundingBoxMessage(); - message.dimensionType = dimensionType; - message.key = key; - message.boundingBoxes = boundingBoxes; - return message; - } - - @Override - public void fromBytes(ByteBuf buf) { - dimensionType = DimensionType.getById(ByteBufUtils.readVarInt(buf, 5)); - key = BoundingBoxDeserializer.deserialize(buf); - boundingBoxes = new HashSet<>(); - while (buf.isReadable()) { - BoundingBox boundingBox = BoundingBoxDeserializer.deserialize(buf); - boundingBoxes.add(boundingBox); - } - if (boundingBoxes.size() == 0) - boundingBoxes.add(key); - } - - @Override - public void toBytes(ByteBuf buf) { - ByteBufUtils.writeVarInt(buf, dimensionType.getId(), 5); - BoundingBoxSerializer.serialize(key, buf); - if (boundingBoxes != null && - boundingBoxes.size() > 1) { - for (BoundingBox boundingBox : boundingBoxes) { - BoundingBoxSerializer.serialize(boundingBox, buf); - } - } - } - - public DimensionType getDimensionType() { - return dimensionType; - } - - BoundingBox getKey() { - return key; - } - - Set getBoundingBoxes() { - return boundingBoxes; - } -} diff --git a/java/com/irtimaled/bbor/forge/messages/AddBoundingBoxMessageHandler.java b/java/com/irtimaled/bbor/forge/messages/AddBoundingBoxMessageHandler.java deleted file mode 100644 index 37e60278..00000000 --- a/java/com/irtimaled/bbor/forge/messages/AddBoundingBoxMessageHandler.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.irtimaled.bbor.forge.messages; - -import com.irtimaled.bbor.forge.ForgeMod; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -public class AddBoundingBoxMessageHandler implements IMessageHandler { - @Override - public IMessage onMessage(AddBoundingBoxMessage message, MessageContext ctx) { - ForgeMod.proxy.addBoundingBox(message.getDimensionType(), message.getKey(), message.getBoundingBoxes()); - return null; - } -} diff --git a/java/com/irtimaled/bbor/forge/messages/BoundingBoxDeserializer.java b/java/com/irtimaled/bbor/forge/messages/BoundingBoxDeserializer.java deleted file mode 100644 index d0441520..00000000 --- a/java/com/irtimaled/bbor/forge/messages/BoundingBoxDeserializer.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.irtimaled.bbor.forge.messages; - -import com.irtimaled.bbor.common.models.BoundingBox; -import com.irtimaled.bbor.common.models.BoundingBoxStructure; -import com.irtimaled.bbor.common.models.BoundingBoxVillage; -import io.netty.buffer.ByteBuf; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.common.network.ByteBufUtils; - -import java.awt.*; -import java.util.HashSet; -import java.util.Set; - -class BoundingBoxDeserializer { - static BoundingBox deserialize(ByteBuf buf) { - char type = (char) ByteBufUtils.readVarShort(buf); - switch (type) { - case 'V': - return deserializeVillage(buf); - case 'S': - return deserializeStructure(buf); - } - return null; - } - - private static BoundingBox deserializeStructure(ByteBuf buf) { - BlockPos minBlockPos = deserializeBlockPos(buf); - BlockPos maxBlockPos = deserializeBlockPos(buf); - Color color = new Color(ByteBufUtils.readVarInt(buf, 5)); - return BoundingBoxStructure.from(minBlockPos, maxBlockPos, color); - } - - private static BoundingBox deserializeVillage(ByteBuf buf) { - BlockPos center = deserializeBlockPos(buf); - int radius = ByteBufUtils.readVarInt(buf, 5); - boolean spawnsIronGolems = ByteBufUtils.readVarShort(buf) == 1; - Color color = new Color(ByteBufUtils.readVarInt(buf, 5)); - Set doors = new HashSet<>(); - while (buf.isReadable()) { - BlockPos door = deserializeBlockPos(buf); - doors.add(door); - } - return BoundingBoxVillage.from(center, radius, color, spawnsIronGolems, doors); - } - - private static BlockPos deserializeBlockPos(ByteBuf buf) { - int x = ByteBufUtils.readVarInt(buf, 5); - int y = ByteBufUtils.readVarInt(buf, 5); - int z = ByteBufUtils.readVarInt(buf, 5); - return new BlockPos(x, y, z); - } -} diff --git a/java/com/irtimaled/bbor/forge/messages/BoundingBoxSerializer.java b/java/com/irtimaled/bbor/forge/messages/BoundingBoxSerializer.java deleted file mode 100644 index f0392f6e..00000000 --- a/java/com/irtimaled/bbor/forge/messages/BoundingBoxSerializer.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.irtimaled.bbor.forge.messages; - -import com.irtimaled.bbor.common.models.BoundingBox; -import com.irtimaled.bbor.common.models.BoundingBoxStructure; -import com.irtimaled.bbor.common.models.BoundingBoxVillage; -import io.netty.buffer.ByteBuf; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.common.network.ByteBufUtils; - -import java.awt.*; - -class BoundingBoxSerializer { - static void serialize(BoundingBox boundingBox, ByteBuf buf) { - if (boundingBox instanceof BoundingBoxVillage) { - serializeVillage((BoundingBoxVillage) boundingBox, buf); - } - if (boundingBox instanceof BoundingBoxStructure) { - serializeStructure((BoundingBoxStructure) boundingBox, buf); - } - } - - private static void serializeVillage(BoundingBoxVillage boundingBox, ByteBuf buf) { - ByteBufUtils.writeVarShort(buf, 'V'); - serializeBlockPos(boundingBox.getCenter(), buf); - ByteBufUtils.writeVarInt(buf, boundingBox.getRadius(), 5); - ByteBufUtils.writeVarShort(buf, boundingBox.getSpawnsIronGolems() ? 1 : 0); - serializeColor(boundingBox.getColor(), buf); - for (BlockPos door : boundingBox.getDoors()) { - serializeBlockPos(door, buf); - } - } - - private static void serializeStructure(BoundingBoxStructure boundingBox, ByteBuf buf) { - ByteBufUtils.writeVarShort(buf, 'S'); - serializeCuboid(boundingBox, buf); - serializeColor(boundingBox.getColor(), buf); - } - - private static void serializeColor(Color color, ByteBuf buf) { - ByteBufUtils.writeVarInt(buf, color.getRGB(), 5); - } - - private static void serializeCuboid(BoundingBox boundingBox, ByteBuf buf) { - serializeBlockPos(boundingBox.getMinBlockPos(), buf); - serializeBlockPos(boundingBox.getMaxBlockPos(), buf); - } - - private static void serializeBlockPos(BlockPos blockPos, ByteBuf buf) { - ByteBufUtils.writeVarInt(buf, blockPos.getX(), 5); - ByteBufUtils.writeVarInt(buf, blockPos.getY(), 5); - ByteBufUtils.writeVarInt(buf, blockPos.getZ(), 5); - } -} diff --git a/java/com/irtimaled/bbor/forge/messages/InitializeClientMessage.java b/java/com/irtimaled/bbor/forge/messages/InitializeClientMessage.java deleted file mode 100644 index 684736ac..00000000 --- a/java/com/irtimaled/bbor/forge/messages/InitializeClientMessage.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.irtimaled.bbor.forge.messages; - -import com.irtimaled.bbor.common.models.WorldData; -import io.netty.buffer.ByteBuf; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; - -public class InitializeClientMessage implements IMessage { - private WorldData worldData; - - public static InitializeClientMessage from(WorldData worldData) { - InitializeClientMessage message = new InitializeClientMessage(); - message.worldData = new WorldData(worldData.getSeed(), worldData.getSpawnX(), worldData.getSpawnZ()); - return message; - } - - @Override - public void fromBytes(ByteBuf buf) { - long seed = buf.readLong(); - int spawnX = buf.readInt(); - int spawnZ = buf.readInt(); - worldData = new WorldData(seed, spawnX, spawnZ); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeLong(worldData.getSeed()); - buf.writeInt(worldData.getSpawnX()); - buf.writeInt(worldData.getSpawnZ()); - } - - WorldData getWorldData() { - return worldData; - } -} diff --git a/java/com/irtimaled/bbor/forge/messages/InitializeClientMessageHandler.java b/java/com/irtimaled/bbor/forge/messages/InitializeClientMessageHandler.java deleted file mode 100644 index 176231a3..00000000 --- a/java/com/irtimaled/bbor/forge/messages/InitializeClientMessageHandler.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.irtimaled.bbor.forge.messages; - -import com.irtimaled.bbor.common.models.WorldData; -import com.irtimaled.bbor.forge.ForgeMod; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -public class InitializeClientMessageHandler implements IMessageHandler { - @Override - public IMessage onMessage(InitializeClientMessage message, MessageContext ctx) { - WorldData worldData = message.getWorldData(); - ForgeMod.proxy.setWorldData(worldData.getSeed(), worldData.getSpawnX(), worldData.getSpawnZ()); - return null; - } -} diff --git a/java/com/irtimaled/bbor/forge/messages/RemoveBoundingBoxMessage.java b/java/com/irtimaled/bbor/forge/messages/RemoveBoundingBoxMessage.java deleted file mode 100644 index 283dbe1a..00000000 --- a/java/com/irtimaled/bbor/forge/messages/RemoveBoundingBoxMessage.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.irtimaled.bbor.forge.messages; - -import com.irtimaled.bbor.common.models.BoundingBox; -import io.netty.buffer.ByteBuf; -import net.minecraft.world.DimensionType; -import net.minecraftforge.fml.common.network.ByteBufUtils; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; - -public class RemoveBoundingBoxMessage implements IMessage { - private DimensionType dimensionType; - private BoundingBox key; - - public static RemoveBoundingBoxMessage from(DimensionType dimensionType, BoundingBox key) { - RemoveBoundingBoxMessage message = new RemoveBoundingBoxMessage(); - message.dimensionType = dimensionType; - message.key = key; - return message; - } - - @Override - public void fromBytes(ByteBuf buf) { - dimensionType = DimensionType.getById(ByteBufUtils.readVarInt(buf, 5)); - key = BoundingBoxDeserializer.deserialize(buf); - } - - @Override - public void toBytes(ByteBuf buf) { - ByteBufUtils.writeVarInt(buf, dimensionType.getId(), 5); - BoundingBoxSerializer.serialize(key, buf); - } - - public DimensionType getDimensionType() { - return dimensionType; - } - - BoundingBox getKey() { - return key; - } -} diff --git a/java/com/irtimaled/bbor/forge/messages/RemoveBoundingBoxMessageHandler.java b/java/com/irtimaled/bbor/forge/messages/RemoveBoundingBoxMessageHandler.java deleted file mode 100644 index 58c972c0..00000000 --- a/java/com/irtimaled/bbor/forge/messages/RemoveBoundingBoxMessageHandler.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.irtimaled.bbor.forge.messages; - -import com.irtimaled.bbor.forge.ForgeMod; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -public class RemoveBoundingBoxMessageHandler implements IMessageHandler { - @Override - public IMessage onMessage(RemoveBoundingBoxMessage message, MessageContext ctx) { - ForgeMod.proxy.removeBoundingBox(message.getDimensionType(), message.getKey()); - return null; - } -} diff --git a/java/com/irtimaled/bbor/install/Main.java b/java/com/irtimaled/bbor/install/Main.java new file mode 100644 index 00000000..32cb8f9a --- /dev/null +++ b/java/com/irtimaled/bbor/install/Main.java @@ -0,0 +1,100 @@ +package com.irtimaled.bbor.install; + +import javax.swing.*; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.text.SimpleDateFormat; +import java.util.*; + +public class Main { + public static void main(String... args) throws Throwable { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (Throwable t) { + t.printStackTrace(); + } + + try { + String osName = getOsName(); + File minecraftFolder = getMinecraftFolder(osName); + File versionFolder = new File(minecraftFolder, "versions/@MC_VERSION@-BBOR-@VERSION@/"); + versionFolder.mkdirs(); + + File versionJson = new File(versionFolder, "@MC_VERSION@-BBOR-@VERSION@.json"); + Files.copy(Main.class.getResourceAsStream("/profile.json"), versionJson.toPath(), StandardCopyOption.REPLACE_EXISTING); + + try { + File profilesJson = new File(minecraftFolder, "launcher_profiles.json"); + if (profilesJson.exists()) { // TODO: use gson instead + String identifier = "\"bbor-@MC_VERSION@\""; + String contents = new String(Files.readAllBytes(profilesJson.toPath())); + if (contents.contains(identifier)) { + contents = contents.replaceAll(",\n *"+identifier+": \\{[^}]*},", ","); + contents = contents.replaceAll(",?\n *"+identifier+": \\{[^}]*},?", ""); + } + + String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); + + contents = contents.replace("\n \"profiles\": {", "\n \"profiles\": {\n" + + " "+identifier+": {\n" + + " \"name\": \"Bounding Box Outline Reloaded\",\n" + + " \"type\": \"custom\",\n" + + " \"created\": \""+date+"T00:00:00.000Z\",\n" + + " \"lastUsed\": \"2100-01-01T00:00:00.000Z\",\n" + + " \"lastVersionId\": \"@MC_VERSION@-BBOR-@VERSION@\"\n" + + " },"); + + Files.write(profilesJson.toPath(), contents.getBytes()); + } + } catch (Throwable t) { + t.printStackTrace(); + } + + // Copy rift jar to libraries + try { + String source = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath(); + if (source.startsWith("/") && osName.contains("win")) { + source = source.substring(1); + } + File riftJar = new File(minecraftFolder, "libraries/com/irtimaled/bbor/@VERSION@/bbor-@VERSION@.jar"); + riftJar.getParentFile().mkdirs(); + Files.copy(Paths.get(source), riftJar.toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (Throwable t) { + t.printStackTrace(); + } + + JOptionPane.showMessageDialog(null, + "Bounding Box Outline Reloaded @VERSION@ for\n Minecraft @MC_VERSION@ has been successfully installed!\n" + + "\n" + + "Re-open the Minecraft Launcher to see it in the dropdown.", + "Bounding Box Outline Reloaded Installer", JOptionPane.INFORMATION_MESSAGE); + } catch (Throwable t) { + StringWriter w = new StringWriter(); + t.printStackTrace(new PrintWriter(w)); + JOptionPane.showMessageDialog(null, + "An error occured while installing Bounding Box Outline Reloaded, please report this to the issue\n" + + "tracker (https://github.com/irtimaled/BoundingBoxOutlineReloaded/issues):\n" + + "\n" + + w.toString().replace("\t", " "), "Bounding Box Outline Reloaded Installer", JOptionPane.ERROR_MESSAGE); + } + } + + private static File getMinecraftFolder(String osName) { + File minecraftFolder; + if (osName.contains("win")) { + minecraftFolder = new File(System.getenv("APPDATA") + "/.minecraft"); + } else if (osName.contains("mac")) { + minecraftFolder = new File(System.getProperty("user.home") + "/Library/Application Support/minecraft"); + } else { + minecraftFolder = new File(System.getProperty("user.home") + "/.minecraft"); + } + return minecraftFolder; + } + + private static String getOsName() { + return System.getProperty("os.name").toLowerCase(Locale.ROOT); + } + +} diff --git a/java/com/irtimaled/bbor/launch/ClientTweaker.java b/java/com/irtimaled/bbor/launch/ClientTweaker.java new file mode 100644 index 00000000..77eb7e0f --- /dev/null +++ b/java/com/irtimaled/bbor/launch/ClientTweaker.java @@ -0,0 +1,21 @@ +package com.irtimaled.bbor.launch; + +import java.io.File; +import java.util.List; + +public class ClientTweaker extends Tweaker { + @Override + protected void addOptions(List args, File gameDir, File assetsDir, String profile){ + addArg("--assetsDir", assetsDir.getPath()); + } + + @Override + public String getLaunchTarget() { + return "net.minecraft.client.main.Main"; + } + + @Override + protected boolean isClient() { + return true; + } +} diff --git a/java/com/irtimaled/bbor/launch/ServerTweaker.java b/java/com/irtimaled/bbor/launch/ServerTweaker.java new file mode 100644 index 00000000..f214d0d1 --- /dev/null +++ b/java/com/irtimaled/bbor/launch/ServerTweaker.java @@ -0,0 +1,13 @@ +package com.irtimaled.bbor.launch; + +public class ServerTweaker extends Tweaker { + @Override + protected boolean isClient() { + return false; + } + + @Override + public String getLaunchTarget() { + return "net.minecraft.server.MinecraftServer"; + } +} diff --git a/java/com/irtimaled/bbor/launch/Tweaker.java b/java/com/irtimaled/bbor/launch/Tweaker.java new file mode 100644 index 00000000..2b8e67a6 --- /dev/null +++ b/java/com/irtimaled/bbor/launch/Tweaker.java @@ -0,0 +1,56 @@ +package com.irtimaled.bbor.launch; + +import net.minecraft.launchwrapper.ITweaker; +import net.minecraft.launchwrapper.LaunchClassLoader; +import org.spongepowered.asm.launch.MixinBootstrap; +import org.spongepowered.asm.mixin.MixinEnvironment; +import org.spongepowered.asm.mixin.Mixins; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +public abstract class Tweaker implements ITweaker { + public List args; + + @Override + public void acceptOptions(List args, File gameDir, File assetsDir, String profile) { + this.args = new ArrayList<>(args); + addArg("--version", profile); + addOptions(args, gameDir, assetsDir, profile); + } + + protected void addArg(String name, String value) { + args.add(name); + if (value != null) { + args.add(value); + } + } + + protected void addOptions(List args, File gameDir, File assetsDir, String profile) { + } + + @Override + public void injectIntoClassLoader(LaunchClassLoader classLoader) { + // Use the Launch classLoader to load the RiftLoader class. Otherwise identical + // classes may not be equal, and 'instanceof' may return false when it should be true. + /*try { + Class clazz = Launch.classLoader.findClass("org.dimdev.riftloader.RiftLoader"); + clazz.getMethod("load", boolean.class).invoke(clazz.getField("instance").get(null), isClient()); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } +*/ + MixinBootstrap.init(); + Mixins.addConfiguration("mixins.bbor.json"); + MixinEnvironment.getDefaultEnvironment().setSide(isClient() ? MixinEnvironment.Side.CLIENT : MixinEnvironment.Side.SERVER); + + } + + protected abstract boolean isClient(); + + @Override + public String[] getLaunchArguments() { + return args.toArray(new String[0]); + } +} diff --git a/java/com/irtimaled/bbor/litemod/LiteMod.java b/java/com/irtimaled/bbor/litemod/LiteMod.java deleted file mode 100755 index bdd1f861..00000000 --- a/java/com/irtimaled/bbor/litemod/LiteMod.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.irtimaled.bbor.litemod; - -import com.irtimaled.bbor.client.BoundingBoxOutlineReloaded; -import com.mumfrey.liteloader.Tickable; -import net.minecraft.client.Minecraft; - -import java.io.File; - -public class LiteMod implements Tickable { - public LiteMod() { - } - - @Override - public String getName() { - return "BoundingBoxOutlineReloaded"; - } - - @Override - public String getVersion() { - return "1.0.1"; - } - - @Override - public void init(File configPath) { - BoundingBoxOutlineReloaded.init(); - } - - @Override - public void upgradeSettings(String version, File configPath, File oldConfigPath) { - } - - @Override - public void onTick(Minecraft minecraft, float partialTicks, boolean inGame, boolean clock) { - BoundingBoxOutlineReloaded.keyPressed(); - } -} diff --git a/java/com/irtimaled/bbor/litemod/mixins/MixinEntityRenderer.java b/java/com/irtimaled/bbor/litemod/mixins/MixinEntityRenderer.java deleted file mode 100644 index 9833c425..00000000 --- a/java/com/irtimaled/bbor/litemod/mixins/MixinEntityRenderer.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.irtimaled.bbor.litemod.mixins; - -import com.irtimaled.bbor.client.BoundingBoxOutlineReloaded; -import com.mumfrey.liteloader.client.overlays.IEntityRenderer; -import net.minecraft.client.renderer.EntityRenderer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(EntityRenderer.class) -public abstract class MixinEntityRenderer implements IEntityRenderer { - @Inject(method = "renderWorldPass", - at = @At(shift = At.Shift.BEFORE, - value = "INVOKE_STRING", - target = "Lnet/minecraft/profiler/Profiler;endStartSection(Ljava/lang/String;)V", - args = "ldc=hand")) - private void onRenderHand(int pass, float partialTicks, long timeSlice, CallbackInfo ci) { - BoundingBoxOutlineReloaded.render(partialTicks); - } -} \ No newline at end of file diff --git a/java/com/irtimaled/bbor/litemod/mixins/MixinIntegratedServer.java b/java/com/irtimaled/bbor/litemod/mixins/MixinIntegratedServer.java deleted file mode 100755 index e23c038f..00000000 --- a/java/com/irtimaled/bbor/litemod/mixins/MixinIntegratedServer.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.irtimaled.bbor.litemod.mixins; - -import com.irtimaled.bbor.client.BoundingBoxOutlineReloaded; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.integrated.IntegratedServer; -import net.minecraft.world.World; -import net.minecraft.world.WorldType; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(IntegratedServer.class) -public abstract class MixinIntegratedServer extends MinecraftServer { - public MixinIntegratedServer() { - super(null, null, null, null, null, null, null); - } - - @Inject(method = "loadAllWorlds", - at = @At("RETURN"), - remap = false) - private void onLoadAllWorlds(String saveName, String worldNameIn, long seed, WorldType type, String generatorOptions, CallbackInfo ci) { - for (World world : this.worlds) { - BoundingBoxOutlineReloaded.worldLoaded(world); - } - } -} \ No newline at end of file diff --git a/java/com/irtimaled/bbor/litemod/mixins/MixinKeyBinding.java b/java/com/irtimaled/bbor/litemod/mixins/MixinKeyBinding.java deleted file mode 100644 index b7bd818e..00000000 --- a/java/com/irtimaled/bbor/litemod/mixins/MixinKeyBinding.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.irtimaled.bbor.litemod.mixins; - -import net.minecraft.client.resources.I18n; -import net.minecraft.client.settings.KeyBinding; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Map; - -@Mixin(KeyBinding.class) -public abstract class MixinKeyBinding implements Comparable { - @Shadow - private static Map CATEGORY_ORDER; - - @Shadow - private String keyDescription; - - @Shadow - private String keyCategory; - - @Overwrite() - public int compareTo(KeyBinding p_compareTo_1_) { - return this.keyCategory.equals(p_compareTo_1_.getKeyCategory()) ? I18n.format(this.keyDescription).compareTo(I18n.format(p_compareTo_1_.getKeyDescription())) : ((Integer) CATEGORY_ORDER.getOrDefault(this.keyCategory, 0)).compareTo(CATEGORY_ORDER.getOrDefault(p_compareTo_1_.getKeyCategory(), 0)); - } -} diff --git a/java/com/irtimaled/bbor/litemod/mixins/MixinNetworkManager.java b/java/com/irtimaled/bbor/litemod/mixins/MixinNetworkManager.java deleted file mode 100644 index e108bc2f..00000000 --- a/java/com/irtimaled/bbor/litemod/mixins/MixinNetworkManager.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.irtimaled.bbor.litemod.mixins; - -import com.irtimaled.bbor.client.BoundingBoxOutlineReloaded; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.Packet; -import net.minecraft.network.login.client.CPacketLoginStart; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(NetworkManager.class) -public abstract class MixinNetworkManager { - @Inject(method = "sendPacket(Lnet/minecraft/network/Packet;)V", - at = @At("RETURN")) - private void onLoaded(Packet packetIn, CallbackInfo ci) { - if (packetIn instanceof CPacketLoginStart) { - BoundingBoxOutlineReloaded.playerConnectedToServer((NetworkManager)(Object)this); - } - } -} \ No newline at end of file diff --git a/java/com/irtimaled/bbor/mixin/client/MixinMinecraft.java b/java/com/irtimaled/bbor/mixin/client/MixinMinecraft.java new file mode 100644 index 00000000..38152b81 --- /dev/null +++ b/java/com/irtimaled/bbor/mixin/client/MixinMinecraft.java @@ -0,0 +1,21 @@ +package com.irtimaled.bbor.mixin.client; + +import com.irtimaled.bbor.client.BoundingBoxOutlineReloaded; +import net.minecraft.client.Minecraft; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Minecraft.class) +public class MixinMinecraft { + @Inject(method = "init", at = @At("RETURN")) + private void init(CallbackInfo ci) { + BoundingBoxOutlineReloaded.init(); + } + + @Inject(method = "processKeyBinds", at = @At("HEAD")) + public void processKeyBinds(CallbackInfo ci) { + BoundingBoxOutlineReloaded.keyPressed(); + } +} \ No newline at end of file diff --git a/java/com/irtimaled/bbor/litemod/mixins/MixinWorldClient.java b/java/com/irtimaled/bbor/mixin/client/multiplayer/MixinWorldClient.java similarity index 55% rename from java/com/irtimaled/bbor/litemod/mixins/MixinWorldClient.java rename to java/com/irtimaled/bbor/mixin/client/multiplayer/MixinWorldClient.java index e03412c8..f52ad19c 100644 --- a/java/com/irtimaled/bbor/litemod/mixins/MixinWorldClient.java +++ b/java/com/irtimaled/bbor/mixin/client/multiplayer/MixinWorldClient.java @@ -1,22 +1,17 @@ -package com.irtimaled.bbor.litemod.mixins; +package com.irtimaled.bbor.mixin.client.multiplayer; import com.irtimaled.bbor.client.BoundingBoxOutlineReloaded; import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(WorldClient.class) -public abstract class MixinWorldClient extends World { - public MixinWorldClient() { - super(null, null, null, null, true); - } - - @Inject(method = "sendQuittingDisconnectingPacket", - at = @At("RETURN")) - private void onDisconnecting(CallbackInfo ci) { +public class MixinWorldClient { + @Inject(method="sendQuittingDisconnectingPacket", at=@At("RETURN")) + private void sendQuittingDisconnectingPacket(CallbackInfo ci) + { BoundingBoxOutlineReloaded.playerDisconnectedFromServer(); } } diff --git a/java/com/irtimaled/bbor/mixin/client/renderer/MixinEntityRenderer.java b/java/com/irtimaled/bbor/mixin/client/renderer/MixinEntityRenderer.java new file mode 100644 index 00000000..44e52229 --- /dev/null +++ b/java/com/irtimaled/bbor/mixin/client/renderer/MixinEntityRenderer.java @@ -0,0 +1,16 @@ +package com.irtimaled.bbor.mixin.client.renderer; + +import com.irtimaled.bbor.client.BoundingBoxOutlineReloaded; +import net.minecraft.client.renderer.EntityRenderer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(EntityRenderer.class) +public class MixinEntityRenderer { + @Inject(method = "updateCameraAndRender(FJ)V", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/profiler/Profiler;endStartSection(Ljava/lang/String;)V", args = "ldc=hand", shift = At.Shift.BEFORE)) + private void render(float partialTicks, long ignored, CallbackInfo ci) { + BoundingBoxOutlineReloaded.render(partialTicks); + } +} diff --git a/java/com/irtimaled/bbor/mixin/client/settings/MixinKeyBinding.java b/java/com/irtimaled/bbor/mixin/client/settings/MixinKeyBinding.java new file mode 100644 index 00000000..f9a47243 --- /dev/null +++ b/java/com/irtimaled/bbor/mixin/client/settings/MixinKeyBinding.java @@ -0,0 +1,18 @@ +package com.irtimaled.bbor.mixin.client.settings; + +import net.minecraft.client.settings.KeyBinding; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Map; + + +@Mixin(KeyBinding.class) +public class MixinKeyBinding { + @Shadow + private static Map CATEGORY_ORDER; + + static { + CATEGORY_ORDER.put("Bounding Box Outline Reloaded", 0); + } +} \ No newline at end of file diff --git a/java/com/irtimaled/bbor/mixin/network/MixinNetworkManager.java b/java/com/irtimaled/bbor/mixin/network/MixinNetworkManager.java new file mode 100644 index 00000000..1dae2034 --- /dev/null +++ b/java/com/irtimaled/bbor/mixin/network/MixinNetworkManager.java @@ -0,0 +1,20 @@ +package com.irtimaled.bbor.mixin.network; + +import io.netty.util.concurrent.GenericFutureListener; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(NetworkManager.class) +public class MixinNetworkManager { + @Inject(method = "sendPacket(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", at= @At("RETURN")) + public void sendPacket(Packet packetIn, GenericFutureListener listener, CallbackInfo ci) { + if (packetIn instanceof net.minecraft.network.login.client.CPacketLoginStart) { + com.irtimaled.bbor.client.BoundingBoxOutlineReloaded.playerConnectedToServer((NetworkManager) (Object) this); + } + } + +} diff --git a/java/com/irtimaled/bbor/mixin/server/MixinMinecraftServer.java b/java/com/irtimaled/bbor/mixin/server/MixinMinecraftServer.java new file mode 100644 index 00000000..045396f1 --- /dev/null +++ b/java/com/irtimaled/bbor/mixin/server/MixinMinecraftServer.java @@ -0,0 +1,25 @@ +package com.irtimaled.bbor.mixin.server; + +import com.irtimaled.bbor.client.BoundingBoxOutlineReloaded; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(MinecraftServer.class) +public class MixinMinecraftServer { + + @Shadow public WorldServer[] worlds; + + @Inject(method = "initialWorldChunkLoad", at = @At("HEAD")) + private void initialWorldChunkLoad(CallbackInfo ci) + { + for(World world : worlds) { + BoundingBoxOutlineReloaded.worldLoaded(world); + } + } +} diff --git a/java/com/irtimaled/bbor/litemod/mixins/MixinChunk.java b/java/com/irtimaled/bbor/mixin/world/chunk/MixinChunk.java similarity index 57% rename from java/com/irtimaled/bbor/litemod/mixins/MixinChunk.java rename to java/com/irtimaled/bbor/mixin/world/chunk/MixinChunk.java index eadba899..82c0770c 100644 --- a/java/com/irtimaled/bbor/litemod/mixins/MixinChunk.java +++ b/java/com/irtimaled/bbor/mixin/world/chunk/MixinChunk.java @@ -1,4 +1,4 @@ -package com.irtimaled.bbor.litemod.mixins; +package com.irtimaled.bbor.mixin.world.chunk; import com.irtimaled.bbor.client.BoundingBoxOutlineReloaded; import net.minecraft.world.chunk.Chunk; @@ -8,10 +8,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(Chunk.class) -public abstract class MixinChunk { - @Inject(method = "onLoad", - at = @At("RETURN")) - private void onLoaded(CallbackInfo ci) { - BoundingBoxOutlineReloaded.chunkLoaded((Chunk)(Object)this); +public class MixinChunk { + @Inject(method = "onLoad", at = @At("RETURN")) + private void onLoad(CallbackInfo ci) { + BoundingBoxOutlineReloaded.chunkLoaded((Chunk) (Object) this); } } \ No newline at end of file diff --git a/patches/net.minecraft.client.Minecraft.java.patch b/patches/net.minecraft.client.Minecraft.java.patch deleted file mode 100644 index c87d6ab2..00000000 --- a/patches/net.minecraft.client.Minecraft.java.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff -r -u a/net/minecraft/client/Minecraft.java b/net/minecraft/client/Minecraft.java ---- a/net/minecraft/client/Minecraft.java 2017-09-27 12:01:40.000000000 -0700 -+++ b/net/minecraft/client/Minecraft.java 2017-09-27 11:30:01.000000000 -0700 -@@ -643,6 +643,8 @@ - } - - this.renderGlobal.makeEntityOutlineShader(); -+ -+ com.irtimaled.bbor.BoundingBoxOutlineReloaded.init(); - } - - /** -@@ -2276,6 +2278,8 @@ - this.gameSettings.smoothCamera = !this.gameSettings.smoothCamera; - } - -+ com.irtimaled.bbor.BoundingBoxOutlineReloaded.keyPressed(); -+ - for (int i = 0; i < 9; ++i) - { - boolean flag = this.gameSettings.keyBindSaveToolbar.isKeyDown(); diff --git a/patches/net.minecraft.client.multiplayer.WorldClient.java.patch b/patches/net.minecraft.client.multiplayer.WorldClient.java.patch deleted file mode 100644 index 4cf1fa36..00000000 --- a/patches/net.minecraft.client.multiplayer.WorldClient.java.patch +++ /dev/null @@ -1,11 +0,0 @@ -diff -r -u a/net/minecraft/client/multiplayer/WorldClient.java b/net/minecraft/client/multiplayer/WorldClient.java ---- a/net/minecraft/client/multiplayer/WorldClient.java 2017-09-27 12:01:40.000000000 -0700 -+++ b/net/minecraft/client/multiplayer/WorldClient.java 2017-09-27 11:53:37.000000000 -0700 -@@ -320,6 +320,7 @@ - public void sendQuittingDisconnectingPacket() - { - this.connection.getNetworkManager().closeChannel(new TextComponentString("Quitting")); -+ com.irtimaled.bbor.BoundingBoxOutlineReloaded.playerDisconnectedFromServer(); - } - - /** diff --git a/patches/net.minecraft.client.renderer.EntityRenderer.java.patch b/patches/net.minecraft.client.renderer.EntityRenderer.java.patch deleted file mode 100644 index 64061ffe..00000000 --- a/patches/net.minecraft.client.renderer.EntityRenderer.java.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff -r -u a/net/minecraft/client/renderer/EntityRenderer.java b/net/minecraft/client/renderer/EntityRenderer.java ---- a/net/minecraft/client/renderer/EntityRenderer.java 2017-09-27 12:01:40.000000000 -0700 -+++ b/net/minecraft/client/renderer/EntityRenderer.java 2017-09-27 11:53:37.000000000 -0700 -@@ -1483,6 +1483,8 @@ - this.renderCloudsCheck(renderglobal, partialTicks, pass, d0, d1, d2); - } - -+ com.irtimaled.bbor.BoundingBoxOutlineReloaded.render(partialTicks); -+ - this.mc.mcProfiler.endStartSection("hand"); - - if (this.renderHand) diff --git a/patches/net.minecraft.client.settings.KeyBinding.java.patch b/patches/net.minecraft.client.settings.KeyBinding.java.patch deleted file mode 100644 index 61d3792f..00000000 --- a/patches/net.minecraft.client.settings.KeyBinding.java.patch +++ /dev/null @@ -1,10 +0,0 @@ -diff -r -u a/net/minecraft/client/settings/KeyBinding.java b/net/minecraft/client/settings/KeyBinding.java ---- a/net/minecraft/client/settings/KeyBinding.java 2017-09-27 12:01:40.000000000 -0700 -+++ b/net/minecraft/client/settings/KeyBinding.java 2017-09-27 11:52:47.000000000 -0700 -@@ -184,5 +184,6 @@ - CATEGORY_ORDER.put("key.categories.multiplayer", Integer.valueOf(5)); - CATEGORY_ORDER.put("key.categories.ui", Integer.valueOf(6)); - CATEGORY_ORDER.put("key.categories.misc", Integer.valueOf(7)); -+ CATEGORY_ORDER.put("Bounding Box Outline Reloaded", Integer.valueOf(0)); - } - } diff --git a/patches/net.minecraft.network.NetworkManager.java.patch b/patches/net.minecraft.network.NetworkManager.java.patch deleted file mode 100644 index bf165f8d..00000000 --- a/patches/net.minecraft.network.NetworkManager.java.patch +++ /dev/null @@ -1,22 +0,0 @@ -diff -r -u a/net/minecraft/network/NetworkManager.java b/net/minecraft/network/NetworkManager.java ---- a/net/minecraft/network/NetworkManager.java 2017-09-27 12:01:41.000000000 -0700 -+++ b/net/minecraft/network/NetworkManager.java 2017-09-27 11:53:38.000000000 -0700 -@@ -32,6 +32,7 @@ - import java.util.concurrent.locks.ReentrantReadWriteLock; - import javax.annotation.Nullable; - import javax.crypto.SecretKey; -+import net.minecraft.network.login.client.CPacketLoginStart; - import net.minecraft.util.CryptManager; - import net.minecraft.util.ITickable; - import net.minecraft.util.LazyLoadBase; -@@ -188,6 +189,10 @@ - this.readWriteLock.writeLock().unlock(); - } - } -+ -+ if (packetIn instanceof CPacketLoginStart) { -+ com.irtimaled.bbor.BoundingBoxOutlineReloaded.playerConnectedToServer(this); -+ } - } - - public void sendPacket(Packet packetIn, GenericFutureListener > listener, GenericFutureListener > ... listeners) diff --git a/patches/net.minecraft.server.integrated.IntegratedServer.java.patch b/patches/net.minecraft.server.integrated.IntegratedServer.java.patch deleted file mode 100644 index 1f36b77e..00000000 --- a/patches/net.minecraft.server.integrated.IntegratedServer.java.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff -r -u a/net/minecraft/server/integrated/IntegratedServer.java b/net/minecraft/server/integrated/IntegratedServer.java ---- a/net/minecraft/server/integrated/IntegratedServer.java 2017-09-27 12:01:41.000000000 -0700 -+++ b/net/minecraft/server/integrated/IntegratedServer.java 2017-09-27 11:37:50.000000000 -0700 -@@ -114,6 +114,8 @@ - this.worlds[i] = (WorldServer)(new WorldServerMulti(this, isavehandler, j, this.worlds[0], this.profiler)).init(); - } - -+ com.irtimaled.bbor.BoundingBoxOutlineReloaded.worldLoaded(this.worlds[i]); -+ - this.worlds[i].addEventListener(new ServerWorldEventHandler(this, this.worlds[i])); - } - diff --git a/patches/net.minecraft.world.chunk.Chunk.java.patch b/patches/net.minecraft.world.chunk.Chunk.java.patch deleted file mode 100644 index 52d41baf..00000000 --- a/patches/net.minecraft.world.chunk.Chunk.java.patch +++ /dev/null @@ -1,11 +0,0 @@ -diff -r -u a/net/minecraft/world/chunk/Chunk.java b/net/minecraft/world/chunk/Chunk.java ---- a/net/minecraft/world/chunk/Chunk.java 2017-09-27 12:01:41.000000000 -0700 -+++ b/net/minecraft/world/chunk/Chunk.java 2017-09-27 11:34:42.000000000 -0700 -@@ -935,6 +935,7 @@ - { - this.world.loadEntities(classinheritancemultimap); - } -+ com.irtimaled.bbor.BoundingBoxOutlineReloaded.chunkLoaded(this); - } - - /** diff --git a/resources/litemod.json b/resources/litemod.json deleted file mode 100755 index ad93565c..00000000 --- a/resources/litemod.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "bbor", - "displayName": "BoundingBoxOutlineReloaded", - "description": "Shows the bounding boxes of structures and features.", - "version": "1.0.1", - "author": "irtimaled", - "mcversion": "1.12.1", - "mixinConfigs": [ - "mixins.bbor.json" - ] -} diff --git a/resources/mcmod.info b/resources/mcmod.info deleted file mode 100644 index 39c60459..00000000 --- a/resources/mcmod.info +++ /dev/null @@ -1,17 +0,0 @@ -[ -{ - "modid": "bbor", - "name": "Bounding Box Outline Reloaded", - "description": "Shows the bounding boxes of structures and features.", - "version": "${version}", - "mcversion": "${mcversion}", - "url": "http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2345401", - "updateUrl": "", - "authorList": ["irtimaled"], - "credits": "Thanks to 4poc & KaboPC.", - "logoFile": "", - "screenshots": [], - "dependencies": [] -} -] - diff --git a/resources/mixins.bbor.json b/resources/mixins.bbor.json index 8c7a41bc..198e740a 100644 --- a/resources/mixins.bbor.json +++ b/resources/mixins.bbor.json @@ -1,19 +1,19 @@ { "required": true, - "minVersion": "0.7.3", + "minVersion": "0.7.11", "compatibilityLevel": "JAVA_8", "target": "@env(DEFAULT)", - "package": "com.irtimaled.bbor.litemod.mixins", + "package": "com.irtimaled.bbor.mixin", "refmap": "mixins.bbor.refmap.json", "mixins": [ - "MixinIntegratedServer", - "MixinEntityRenderer", - "MixinChunk", - "MixinNetworkManager", - "MixinWorldClient", - "MixinKeyBinding" + "world.chunk.MixinChunk", + "network.MixinNetworkManager", + "server.MixinMinecraftServer" ], - "injectors": { - "defaultRequire": 1 - } + "client": [ + "client.MixinMinecraft", + "client.renderer.MixinEntityRenderer", + "client.multiplayer.MixinWorldClient", + "client.settings.MixinKeyBinding" + ] } diff --git a/resources/mixins.bbor.refmap.json b/resources/mixins.bbor.refmap.json deleted file mode 100644 index 56feab29..00000000 --- a/resources/mixins.bbor.refmap.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "mappings": { - "com/irtimaled/bbor/litemod/mixins/MixinIntegratedServer": { - "loadAllWorlds": "Lchd;a(Ljava/lang/String;Ljava/lang/String;JLamz;Ljava/lang/String;)V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinNetworkManager": { - "sendPacket(Lnet/minecraft/network/Packet;)V": "Lgw;a(Lht;)V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinEntityRenderer": { - "Lnet/minecraft/profiler/Profiler;endStartSection(Ljava/lang/String;)V": "Lrl;c(Ljava/lang/String;)V", - "renderWorldPass": "Lbuq;a(IFJ)V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinWorldClient": { - "sendQuittingDisconnectingPacket": "Lbsb;O()V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinChunk": { - "onLoad": "Laxw;c()V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinKeyBinding": { - "compareTo": "Lbhy;a(Lbhy;)I" - } - }, - "data": { - "notch": { - "com/irtimaled/bbor/litemod/mixins/MixinIntegratedServer": { - "loadAllWorlds": "Lchd;a(Ljava/lang/String;Ljava/lang/String;JLamz;Ljava/lang/String;)V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinNetworkManager": { - "sendPacket(Lnet/minecraft/network/Packet;)V": "Lgw;a(Lht;)V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinEntityRenderer": { - "Lnet/minecraft/profiler/Profiler;endStartSection(Ljava/lang/String;)V": "Lrl;c(Ljava/lang/String;)V", - "renderWorldPass": "Lbuq;a(IFJ)V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinWorldClient": { - "sendQuittingDisconnectingPacket": "Lbsb;O()V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinChunk": { - "onLoad": "Laxw;c()V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinKeyBinding": { - "compareTo": "Lbhy;a(Lbhy;)I" - } - }, - "searge": { - "com/irtimaled/bbor/litemod/mixins/MixinIntegratedServer": { - "loadAllWorlds": "Lnet/minecraft/server/integrated/IntegratedServer;func_71247_a(Ljava/lang/String;Ljava/lang/String;JLnet/minecraft/world/WorldType;Ljava/lang/String;)V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinNetworkManager": { - "sendPacket(Lnet/minecraft/network/Packet;)V": "Lnet/minecraft/network/NetworkManager;func_179290_a(Lnet/minecraft/network/Packet;)V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinEntityRenderer": { - "Lnet/minecraft/profiler/Profiler;endStartSection(Ljava/lang/String;)V": "Lnet/minecraft/profiler/Profiler;func_76318_c(Ljava/lang/String;)V", - "renderWorldPass": "Lnet/minecraft/client/renderer/EntityRenderer;func_175068_a(IFJ)V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinWorldClient": { - "sendQuittingDisconnectingPacket": "Lnet/minecraft/client/multiplayer/WorldClient;func_72882_A()V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinChunk": { - "onLoad": "Lnet/minecraft/world/chunk/Chunk;func_76631_c()V" - }, - "com/irtimaled/bbor/litemod/mixins/MixinKeyBinding": { - "compareTo": "Lnet/minecraft/client/settings/KeyBinding;compareTo(Lnet/minecraft/client/settings/KeyBinding;)I" - } - } - } -} diff --git a/resources/pack.mcmeta b/resources/pack.mcmeta deleted file mode 100644 index c00c6426..00000000 --- a/resources/pack.mcmeta +++ /dev/null @@ -1,7 +0,0 @@ -{ - "pack": { - "description": "bbor resources", - "pack_format": 3, - "_comment": "A pack_format of 3 should be used starting with Minecraft 1.11. All resources, including language files, should be lowercase (eg: en_us.lang). A pack_format of 2 will load your mod resources with LegacyV2Adapter, which requires language files to have uppercase letters (eg: en_US.lang)." - } -} diff --git a/resources/profile.json b/resources/profile.json new file mode 100644 index 00000000..22460e49 --- /dev/null +++ b/resources/profile.json @@ -0,0 +1,30 @@ +{ + "inheritsFrom": "${mcVersion}", + "id": "${mcVersion}-BBOR-${version}", + "jar": "${mcVersion}", + "time": "${formattedTime}", + "type": "release", + "arguments": { + "game": [ + "--tweakClass", + "${tweakClass}" + ] + }, + "mainClass": "net.minecraft.launchwrapper.Launch", + "libraries": [ + { + "name": "com.irtimaled:bbor:${version}" + }, + { + "name": "org.ow2.asm:asm:6.2", + "url": "http://repo1.maven.org/maven2/" + }, + { + "name": "org.ow2.asm:asm-commons:6.2", + "url": "http://repo1.maven.org/maven2/" + }, + { + "name": "net.minecraft:launchwrapper:1.12" + } + ] +} \ No newline at end of file