|
| 1 | +package dev.frydae.emcutils.journey; |
| 2 | + |
| 3 | +import dev.frydae.emcutils.containers.EmpireResidence; |
| 4 | +import dev.frydae.emcutils.utils.Util; |
| 5 | +import journeymap.client.api.IClientAPI; |
| 6 | +import journeymap.client.api.IClientPlugin; |
| 7 | +import journeymap.client.api.display.Context; |
| 8 | +import journeymap.client.api.display.ModPopupMenu; |
| 9 | +import journeymap.client.api.event.ClientEvent; |
| 10 | +import journeymap.client.api.event.fabric.FabricEvents; |
| 11 | +import net.minecraft.client.MinecraftClient; |
| 12 | +import net.minecraft.util.math.BlockPos; |
| 13 | +import net.minecraft.util.math.Vec3d; |
| 14 | +import org.jetbrains.annotations.NotNull; |
| 15 | + |
| 16 | +import java.util.EnumSet; |
| 17 | + |
| 18 | +import static dev.frydae.emcutils.utils.Util.MODID; |
| 19 | +import static journeymap.client.api.event.ClientEvent.Type.MAPPING_STARTED; |
| 20 | + |
| 21 | +public class EmpireMinecraftUtilitiesJourney implements IClientPlugin { |
| 22 | + private IClientAPI api; |
| 23 | + @Override |
| 24 | + public void initialize(@NotNull final IClientAPI api) { |
| 25 | + this.api = api; |
| 26 | + |
| 27 | + api.subscribe(getModId(), EnumSet.of(MAPPING_STARTED)); |
| 28 | + |
| 29 | + // Turn off radars on EMC |
| 30 | + FabricEvents.ENTITY_RADAR_UPDATE_EVENT.register(event -> { if (Util.isOnEMC) event.setCanceled(true); }); |
| 31 | + |
| 32 | + // Add residence TP button |
| 33 | + FabricEvents.FULLSCREEN_POPUP_MENU_EVENT.register(event -> |
| 34 | + event.getPopupMenu().addMenuItem("Teleport to Residence", new TeleportToResidenceAction())); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public String getModId() { |
| 39 | + return MODID; |
| 40 | + } |
| 41 | + |
| 42 | + @SuppressWarnings("deprecation") |
| 43 | + @Override |
| 44 | + public void onEvent(@NotNull final ClientEvent event) { |
| 45 | + if (event.type.equals(MAPPING_STARTED) && Util.isOnEMC) { |
| 46 | + // Disable cave maps on EMC |
| 47 | + api.toggleDisplay(null, Context.MapType.Underground, Context.UI.Any, false); |
| 48 | + |
| 49 | + // Set world names on EMC |
| 50 | + api.setWorldId(Util.getCurrentServer().getName().toLowerCase()); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + private static class TeleportToResidenceAction implements ModPopupMenu.Action { |
| 55 | + @Override |
| 56 | + public void doAction(final @NotNull BlockPos pos) { |
| 57 | + if (Util.isOnEMC) { |
| 58 | + EmpireResidence res = Util.getCurrentServer().getResidenceByLoc(new Vec3d(pos.getX(), pos.getY(), pos.getZ())); |
| 59 | + if (res != null) { |
| 60 | + MinecraftClient.getInstance().player.sendChatMessage(res.getVisitCommand()); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments