From 0a5527f3d4ea9948d7c22bfbb97994e5fc79bec8 Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Thu, 19 Mar 2020 15:35:09 +0000 Subject: [PATCH] Add backwards compatibility to convert old-format atlas markers to new ones --- .../WizardryAntiqueAtlasIntegration.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/electroblob/wizardry/integration/antiqueatlas/WizardryAntiqueAtlasIntegration.java b/src/main/java/electroblob/wizardry/integration/antiqueatlas/WizardryAntiqueAtlasIntegration.java index 69e25efe..1d35f9f0 100644 --- a/src/main/java/electroblob/wizardry/integration/antiqueatlas/WizardryAntiqueAtlasIntegration.java +++ b/src/main/java/electroblob/wizardry/integration/antiqueatlas/WizardryAntiqueAtlasIntegration.java @@ -1,11 +1,17 @@ package electroblob.wizardry.integration.antiqueatlas; import electroblob.wizardry.Wizardry; +import hunternif.mc.atlas.AntiqueAtlasMod; import hunternif.mc.atlas.api.AtlasAPI; +import hunternif.mc.atlas.marker.GlobalMarkersData; +import hunternif.mc.atlas.marker.Marker; import hunternif.mc.atlas.registry.MarkerType; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; /** * This class handles all of wizardry's integration with the Antique Atlas mod. This class contains only the code @@ -15,6 +21,7 @@ import net.minecraftforge.fml.common.Loader; * @since Wizardry 4.2 * @author Electroblob */ +@Mod.EventBusSubscriber public class WizardryAntiqueAtlasIntegration { public static final String ANTIQUE_ATLAS_MOD_ID = "antiqueatlas"; @@ -68,4 +75,18 @@ public class WizardryAntiqueAtlasIntegration { AtlasAPI.getMarkerAPI().registerMarker(new MarkerType(OBELISK_MARKER, new ResourceLocation(Wizardry.MODID, "textures/integration/antiqueatlas/obelisk.png"))); } + @SubscribeEvent + public static void onWorldLoadEvent(WorldEvent.Load event){ + // Backwards compatibility for existing markers using the old translation key format (with colons) + GlobalMarkersData data = AntiqueAtlasMod.globalMarkersData.getData(); + for(Marker marker : data.getMarkersInDimension(event.getWorld().provider.getDimension())){ + if(marker.getLabel().contains(":")){ + // Remove old-format markers and replace them with new ones + data.removeMarker(marker.getId()); + AtlasAPI.getMarkerAPI().putGlobalMarker(event.getWorld(), marker.isVisibleAhead(), marker.getType(), + marker.getLabel().replace(':', '.'), marker.getX(), marker.getZ()); + } + } + } + }