diff --git a/gradle.properties b/gradle.properties index 5f4d5460c8a..8fa73bd10a8 100755 --- a/gradle.properties +++ b/gradle.properties @@ -32,8 +32,7 @@ multiPistonVersion=1.21-1.2.47-BETA jei_mcversion=1.21.1 jei_version=19.8.4.116 jmapApiVersion=2.0.0-1.21-SNAPSHOT -jmapMcVersion=1.21.1 -jmapVersion=0 +jmapVersion=1.21-6.0.0-beta.19 tinkersConstructVersion=0 mantleVersion=0 # some mods include the MC version as part of their "real" version number, others diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 26173388d29..7f42f5e4cff 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -48,7 +48,7 @@ dependencies { compileOnly "info.journeymap:journeymap-api-neoforge:${project.jmapApiVersion}" if (project.hasProperty("runWithJourneymap") && project.runWithJourneymap.toBoolean()) { - runtimeOnly "flat:journeymap:${project.jmapMcVersion}-${project.jmapVersion}-neoforge" + runtimeOnly "flat:journeymap-neoforge:${project.jmapVersion}" } // replace "compileOnly" with "implementation" when you want to include it for testing // compileOnly "slimeknights.tconstruct:TConstruct:${project.exactMinecraftVersion}-${project.tinkersConstructVersion}") diff --git a/src/main/java/com/minecolonies/core/compatibility/journeymap/EventListener.java b/src/main/java/com/minecolonies/core/compatibility/journeymap/EventListener.java index 02ee7d0c509..1df2d72ec6c 100644 --- a/src/main/java/com/minecolonies/core/compatibility/journeymap/EventListener.java +++ b/src/main/java/com/minecolonies/core/compatibility/journeymap/EventListener.java @@ -3,25 +3,9 @@ import com.minecolonies.api.colony.IColonyView; import com.minecolonies.api.colony.event.ClientChunkUpdatedEvent; import com.minecolonies.api.colony.event.ColonyViewUpdatedEvent; -import com.minecolonies.api.colony.jobs.IJob; -import com.minecolonies.api.colony.jobs.registry.IJobRegistry; -import com.minecolonies.api.colony.jobs.registry.JobEntry; -import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; -import com.minecolonies.api.entity.mobs.AbstractEntityRaiderMob; -import com.minecolonies.core.colony.jobs.AbstractJobGuard; -import com.minecolonies.core.entity.visitor.VisitorCitizen; -import journeymap.api.v2.client.display.Context; -import journeymap.api.v2.client.entity.WrappedEntity; -import journeymap.api.v2.client.event.EntityRadarUpdateEvent; -import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.network.chat.Style; import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; import net.neoforged.bus.api.EventPriority; import net.neoforged.bus.api.SubscribeEvent; @@ -31,17 +15,12 @@ import net.neoforged.neoforge.event.level.ChunkEvent; import org.jetbrains.annotations.NotNull; -import java.util.Arrays; import java.util.Set; -import static com.minecolonies.api.entity.citizen.AbstractEntityCitizen.DATA_JOB; import static com.minecolonies.api.util.constant.Constants.MOD_ID; -import static com.minecolonies.api.util.constant.TranslationConstants.PARTIAL_JOURNEY_MAP_INFO; public class EventListener { - private static final Style JOB_TOOLTIP = Style.EMPTY.withColor(ChatFormatting.YELLOW).withItalic(true); - @NotNull private final Journeymap jmap; @@ -89,84 +68,6 @@ public void onColonyViewUpdated(@NotNull final ColonyViewUpdatedEvent event) ColonyDeathpoints.updateGraves(this.jmap, colony, graves); } - @SubscribeEvent - public void onUpdateEntityRadar(@NotNull final EntityRadarUpdateEvent event) - { - final WrappedEntity wrapper = event.getWrappedEntity(); - final Entity entity = wrapper.getEntityRef().get(); - - if (entity instanceof AbstractEntityCitizen) - { - final boolean isVisitor = entity instanceof VisitorCitizen; - MutableComponent jobName; - - if (isVisitor) - { - if (!JourneymapOptions.getShowVisitors(this.jmap.getOptions())) - { - wrapper.setDisable(true); - return; - } - - jobName = Component.translatableEscape(PARTIAL_JOURNEY_MAP_INFO + "visitor"); - } - else - { - final String jobId = entity.getEntityData().get(DATA_JOB); - final JobEntry jobEntry = IJobRegistry.getInstance().get(ResourceLocation.parse(jobId)); - final IJob job = jobEntry == null ? null : jobEntry.produceJob(null); - - if (job instanceof AbstractJobGuard - ? !JourneymapOptions.getShowGuards(this.jmap.getOptions()) - : !JourneymapOptions.getShowCitizens(this.jmap.getOptions())) - { - wrapper.setDisable(true); - return; - } - - jobName = Component.translatableEscape(jobEntry == null - ? PARTIAL_JOURNEY_MAP_INFO + "unemployed" - : jobEntry.getTranslationKey()); - } - - if (JourneymapOptions.getShowColonistTooltip(this.jmap.getOptions())) - { - Component name = entity.getCustomName(); - if (name != null) - { - wrapper.setEntityToolTips(Arrays.asList(name, jobName.setStyle(JOB_TOOLTIP))); - } - } - - final boolean showName = event.getActiveUiState().ui.equals(Context.UI.Minimap) - ? JourneymapOptions.getShowColonistNameMinimap(this.jmap.getOptions()) - : JourneymapOptions.getShowColonistNameFullscreen(this.jmap.getOptions()); - - if (!showName) - { - wrapper.setCustomName(""); - } - - if (!isVisitor && JourneymapOptions.getShowColonistTeamColour(this.jmap.getOptions())) - { - wrapper.setColor(entity.getTeamColor()); - } - } - else if (entity instanceof AbstractEntityRaiderMob) - { - final JourneymapOptions.RaiderColor color = JourneymapOptions.getRaiderColor(this.jmap.getOptions()); - - if (JourneymapOptions.RaiderColor.NONE.equals(color)) - { - wrapper.setDisable(true); - } - else if (!JourneymapOptions.RaiderColor.HOSTILE.equals(color)) - { - wrapper.setColor(color.getColor().getValue()); - } - } - } - @SubscribeEvent(priority = EventPriority.LOW) public void onClientTick(@NotNull final ClientTickEvent.Pre event) { diff --git a/src/main/java/com/minecolonies/core/compatibility/journeymap/JourneymapPlugin.java b/src/main/java/com/minecolonies/core/compatibility/journeymap/JourneymapPlugin.java index 4a32b9d1927..a6cf8f1a3de 100644 --- a/src/main/java/com/minecolonies/core/compatibility/journeymap/JourneymapPlugin.java +++ b/src/main/java/com/minecolonies/core/compatibility/journeymap/JourneymapPlugin.java @@ -1,14 +1,34 @@ package com.minecolonies.core.compatibility.journeymap; +import com.minecolonies.api.colony.jobs.IJob; +import com.minecolonies.api.colony.jobs.registry.IJobRegistry; +import com.minecolonies.api.colony.jobs.registry.JobEntry; +import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; +import com.minecolonies.api.entity.mobs.AbstractEntityRaiderMob; +import com.minecolonies.core.colony.jobs.AbstractJobGuard; +import com.minecolonies.core.entity.visitor.VisitorCitizen; import journeymap.api.v2.client.IClientAPI; import journeymap.api.v2.client.IClientPlugin; import journeymap.api.v2.client.JourneyMapPlugin; +import journeymap.api.v2.client.display.Context; +import journeymap.api.v2.client.entity.WrappedEntity; +import journeymap.api.v2.client.event.EntityRadarUpdateEvent; import journeymap.api.v2.client.event.MappingEvent; import journeymap.api.v2.client.event.RegistryEvent; import journeymap.api.v2.common.event.ClientEventRegistry; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; import org.jetbrains.annotations.NotNull; +import java.util.Arrays; + +import static com.minecolonies.api.entity.citizen.AbstractEntityCitizen.DATA_JOB; import static com.minecolonies.api.util.constant.Constants.MOD_ID; +import static com.minecolonies.api.util.constant.TranslationConstants.PARTIAL_JOURNEY_MAP_INFO; /** * Plugin entrypoint for JourneyMap @@ -16,6 +36,8 @@ @JourneyMapPlugin(apiVersion = IClientAPI.API_VERSION) public class JourneymapPlugin implements IClientPlugin { + private static final Style JOB_TOOLTIP = Style.EMPTY.withColor(ChatFormatting.YELLOW).withItalic(true); + private Journeymap jmap; @SuppressWarnings("unused") private EventListener listener; @@ -27,8 +49,9 @@ public void initialize(@NotNull final IClientAPI api) this.listener = new EventListener(this.jmap); ClientEventRegistry.MAPPING_EVENT.subscribe(MOD_ID, this::onMappingEvent); - ClientEventRegistry.INFO_SLOT_REGISTRY_EVENT_EVENT.subscribe(MOD_ID, this::onRegistryEvent); - + ClientEventRegistry.OPTIONS_REGISTRY_EVENT_EVENT.subscribe(MOD_ID, this::onOptionsRegistryEvent); + ClientEventRegistry.INFO_SLOT_REGISTRY_EVENT_EVENT.subscribe(MOD_ID, this::onInfoRegistryEvent); + ClientEventRegistry.ENTITY_RADAR_UPDATE_EVENT.subscribe(MOD_ID, this::onEntityRadarUpdateEvent); } @Override @@ -52,16 +75,90 @@ private void onMappingEvent(final MappingEvent event) } } - private void onRegistryEvent(final RegistryEvent event) + private void onOptionsRegistryEvent(final RegistryEvent.OptionsRegistryEvent event) + { + this.jmap.setOptions(new JourneymapOptions()); + } + + private void onInfoRegistryEvent(final RegistryEvent.InfoSlotRegistryEvent event) { - if (RegistryEvent.RegistryType.OPTIONS.equals(event.getRegistryType())) + event.register(MOD_ID, "com.minecolonies.coremod.journeymap.currentcolony", 2500, ColonyBorderMapping::getCurrentColony); + } + + private void onEntityRadarUpdateEvent(final EntityRadarUpdateEvent event) + { + final WrappedEntity wrapper = event.getWrappedEntity(); + final Entity entity = wrapper.getEntityRef().get(); + + if (entity instanceof AbstractEntityCitizen) { - this.jmap.setOptions(new JourneymapOptions()); + final boolean isVisitor = entity instanceof VisitorCitizen; + MutableComponent jobName; + + if (isVisitor) + { + if (!JourneymapOptions.getShowVisitors(this.jmap.getOptions())) + { + wrapper.setDisable(true); + return; + } + + jobName = Component.translatableEscape(PARTIAL_JOURNEY_MAP_INFO + "visitor"); + } + else + { + final String jobId = entity.getEntityData().get(DATA_JOB); + final JobEntry jobEntry = IJobRegistry.getInstance().get(ResourceLocation.parse(jobId)); + final IJob job = jobEntry == null ? null : jobEntry.produceJob(null); + + if (job instanceof AbstractJobGuard + ? !JourneymapOptions.getShowGuards(this.jmap.getOptions()) + : !JourneymapOptions.getShowCitizens(this.jmap.getOptions())) + { + wrapper.setDisable(true); + return; + } + + jobName = Component.translatableEscape(jobEntry == null + ? PARTIAL_JOURNEY_MAP_INFO + "unemployed" + : jobEntry.getTranslationKey()); + } + + if (JourneymapOptions.getShowColonistTooltip(this.jmap.getOptions())) + { + Component name = entity.getCustomName(); + if (name != null) + { + wrapper.setEntityToolTips(Arrays.asList(name, jobName.setStyle(JOB_TOOLTIP))); + } + } + + final boolean showName = event.getActiveUiState().ui.equals(Context.UI.Minimap) + ? JourneymapOptions.getShowColonistNameMinimap(this.jmap.getOptions()) + : JourneymapOptions.getShowColonistNameFullscreen(this.jmap.getOptions()); + + if (!showName) + { + wrapper.setCustomName(""); + } + + if (!isVisitor && JourneymapOptions.getShowColonistTeamColour(this.jmap.getOptions())) + { + wrapper.setColor(entity.getTeamColor()); + } } - else if (RegistryEvent.RegistryType.INFO_SLOT.equals(event.getRegistryType())) + else if (entity instanceof AbstractEntityRaiderMob) { - final RegistryEvent.InfoSlotRegistryEvent infoSlotRegistry = (RegistryEvent.InfoSlotRegistryEvent) event; - infoSlotRegistry.register(MOD_ID, "com.minecolonies.coremod.journeymap.currentcolony", 2500, ColonyBorderMapping::getCurrentColony); + final JourneymapOptions.RaiderColor color = JourneymapOptions.getRaiderColor(this.jmap.getOptions()); + + if (JourneymapOptions.RaiderColor.NONE.equals(color)) + { + wrapper.setDisable(true); + } + else if (!JourneymapOptions.RaiderColor.HOSTILE.equals(color)) + { + wrapper.setColor(color.getColor().getValue()); + } } } }