Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix journeymap #10143

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
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
*/
@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;
Expand All @@ -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
Expand All @@ -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());
}
}
}
}