Search in sources :

Example 1 with Waypoint

use of journeymap.client.api.display.Waypoint in project Geolosys by oitsjustjose.

the class ForgeEventListener method registerEvent.

@SubscribeEvent
public void registerEvent(RightClickBlock event) {
    try {
        IBlockState state = event.getWorld().getBlockState(event.getPos());
        if (state.getBlock() == Geolosys.getInstance().ORE_SAMPLE || state.getBlock() == Geolosys.getInstance().ORE_SAMPLE_VANILLA) {
            if (event.getEntityPlayer().isSneaking() && event.getWorld().isRemote) {
                if (jmAPI.playerAccepts(Lib.MODID, DisplayType.Waypoint)) {
                    String name = new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state)).getDisplayName();
                    String id = Lib.MODID + " - " + name + " - " + event.getWorld().getChunkFromBlockCoords(event.getPos()).getPos();
                    try {
                        jmAPI.show(new Waypoint(Lib.MODID, id, name, event.getWorld().provider.getDimension(), event.getPos()));
                    } catch (Throwable t) {
                        Geolosys.getInstance().LOGGER.info(t.getMessage());
                    }
                }
            }
        }
    } catch (NullPointerException ignored) {
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Waypoint(journeymap.client.api.display.Waypoint) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with Waypoint

use of journeymap.client.api.display.Waypoint in project minecolonies by Minecolonies.

the class ColonyDeathpoints method updateGraves.

/**
 * Synchronise the list of currently-existing graves in the colony.
 * (Can be called when there is no change.)
 *
 * @param jmap The JourneyMap API
 * @param colony The colony.
 * @param graves The list of grave positions.
 */
public static void updateGraves(@NotNull final Journeymap jmap, @NotNull final IColonyView colony, @NotNull final Set<BlockPos> graves) {
    final Map<BlockPos, Waypoint> waypoints = overlays.computeIfAbsent(colony.getDimension(), k -> new HashMap<>()).computeIfAbsent(colony.getID(), k -> new HashMap<>());
    final boolean permitted = colony.getPermissions().hasPermission(Minecraft.getInstance().player, Action.MAP_DEATHS) && JourneymapOptions.getDeathpoints(jmap.getOptions());
    final Iterator<Map.Entry<BlockPos, Waypoint>> iterator = waypoints.entrySet().iterator();
    while (iterator.hasNext()) {
        final Map.Entry<BlockPos, Waypoint> waypointEntry = iterator.next();
        if (!permitted || !graves.contains(waypointEntry.getKey())) {
            if (waypointEntry.getValue() != null) {
                jmap.getApi().remove(waypointEntry.getValue());
            }
            iterator.remove();
        }
    }
    if (permitted) {
        for (final BlockPos grave : graves) {
            waypoints.computeIfAbsent(grave, k -> tryCreatingWaypoint(jmap, colony, k));
        }
    }
}
Also used : DisplayType(journeymap.client.api.display.DisplayType) java.util(java.util) LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) Action(com.minecolonies.api.colony.permissions.Action) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) AbstractTileEntityGrave(com.minecolonies.api.tileentities.AbstractTileEntityGrave) RegistryKey(net.minecraft.util.RegistryKey) IGraveData(com.minecolonies.api.colony.IGraveData) Minecraft(net.minecraft.client.Minecraft) COM_MINECOLONIES_JMAP_PREFIX(com.minecolonies.api.util.constant.TranslationConstants.COM_MINECOLONIES_JMAP_PREFIX) MOD_ID(com.minecolonies.api.util.constant.Constants.MOD_ID) Lazy(net.minecraftforge.common.util.Lazy) IColonyView(com.minecolonies.api.colony.IColonyView) World(net.minecraft.world.World) IColonyManager(com.minecolonies.api.colony.IColonyManager) Waypoint(journeymap.client.api.display.Waypoint) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) Nullable(org.jetbrains.annotations.Nullable) ResourceLocation(net.minecraft.util.ResourceLocation) ChunkStatus(net.minecraft.world.chunk.ChunkStatus) IChunk(net.minecraft.world.chunk.IChunk) MapImage(journeymap.client.api.model.MapImage) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) BlockPos(net.minecraft.util.math.BlockPos) Waypoint(journeymap.client.api.display.Waypoint)

Example 3 with Waypoint

use of journeymap.client.api.display.Waypoint in project minecolonies by Minecolonies.

the class ColonyDeathpoints method tryCreatingWaypoint.

@Nullable
private static Waypoint tryCreatingWaypoint(@NotNull final Journeymap jmap, @NotNull final IColonyView colony, @NotNull final IChunk chunk, @NotNull final BlockPos pos) {
    if (!jmap.getApi().playerAccepts(MOD_ID, DisplayType.Waypoint))
        return null;
    final TileEntity blockEntity = chunk.getBlockEntity(pos);
    if (blockEntity instanceof AbstractTileEntityGrave) {
        final IGraveData grave = ((AbstractTileEntityGrave) blockEntity).getGraveData();
        if (grave != null) {
            final String text = grave.getCitizenJobName() == null ? LanguageHandler.format(COM_MINECOLONIES_JMAP_PREFIX + "deathpoint_name", grave.getCitizenName()) : LanguageHandler.format(COM_MINECOLONIES_JMAP_PREFIX + "deathpoint_namejob", grave.getCitizenName(), grave.getCitizenJobName());
            final Waypoint waypoint = new Waypoint(MOD_ID, text, colony.getDimension(), pos);
            waypoint.setEditable(true).setPersistent(false).setIcon(deathIcon.get()).setColor(0x888888);
            jmap.show(waypoint);
            return waypoint;
        }
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AbstractTileEntityGrave(com.minecolonies.api.tileentities.AbstractTileEntityGrave) Waypoint(journeymap.client.api.display.Waypoint) IGraveData(com.minecolonies.api.colony.IGraveData) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with Waypoint

use of journeymap.client.api.display.Waypoint in project minecolonies by ldtteam.

the class ColonyDeathpoints method tryCreatingWaypoint.

@Nullable
private static Waypoint tryCreatingWaypoint(@NotNull final Journeymap jmap, @NotNull final IColonyView colony, @NotNull final IChunk chunk, @NotNull final BlockPos pos) {
    if (!jmap.getApi().playerAccepts(MOD_ID, DisplayType.Waypoint))
        return null;
    final TileEntity blockEntity = chunk.getBlockEntity(pos);
    if (blockEntity instanceof AbstractTileEntityGrave) {
        final IGraveData grave = ((AbstractTileEntityGrave) blockEntity).getGraveData();
        if (grave != null) {
            final String text = grave.getCitizenJobName() == null ? LanguageHandler.format(COM_MINECOLONIES_JMAP_PREFIX + "deathpoint_name", grave.getCitizenName()) : LanguageHandler.format(COM_MINECOLONIES_JMAP_PREFIX + "deathpoint_namejob", grave.getCitizenName(), grave.getCitizenJobName());
            final Waypoint waypoint = new Waypoint(MOD_ID, text, colony.getDimension(), pos);
            waypoint.setEditable(true).setPersistent(false).setIcon(deathIcon.get()).setColor(0x888888);
            jmap.show(waypoint);
            return waypoint;
        }
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AbstractTileEntityGrave(com.minecolonies.api.tileentities.AbstractTileEntityGrave) Waypoint(journeymap.client.api.display.Waypoint) IGraveData(com.minecolonies.api.colony.IGraveData) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with Waypoint

use of journeymap.client.api.display.Waypoint in project minecolonies by ldtteam.

the class ColonyDeathpoints method updateGraves.

/**
 * Synchronise the list of currently-existing graves in the colony.
 * (Can be called when there is no change.)
 *
 * @param jmap The JourneyMap API
 * @param colony The colony.
 * @param graves The list of grave positions.
 */
public static void updateGraves(@NotNull final Journeymap jmap, @NotNull final IColonyView colony, @NotNull final Set<BlockPos> graves) {
    final Map<BlockPos, Waypoint> waypoints = overlays.computeIfAbsent(colony.getDimension(), k -> new HashMap<>()).computeIfAbsent(colony.getID(), k -> new HashMap<>());
    final boolean permitted = colony.getPermissions().hasPermission(Minecraft.getInstance().player, Action.MAP_DEATHS) && JourneymapOptions.getDeathpoints(jmap.getOptions());
    final Iterator<Map.Entry<BlockPos, Waypoint>> iterator = waypoints.entrySet().iterator();
    while (iterator.hasNext()) {
        final Map.Entry<BlockPos, Waypoint> waypointEntry = iterator.next();
        if (!permitted || !graves.contains(waypointEntry.getKey())) {
            if (waypointEntry.getValue() != null) {
                jmap.getApi().remove(waypointEntry.getValue());
            }
            iterator.remove();
        }
    }
    if (permitted) {
        for (final BlockPos grave : graves) {
            waypoints.computeIfAbsent(grave, k -> tryCreatingWaypoint(jmap, colony, k));
        }
    }
}
Also used : DisplayType(journeymap.client.api.display.DisplayType) java.util(java.util) LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) Action(com.minecolonies.api.colony.permissions.Action) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) AbstractTileEntityGrave(com.minecolonies.api.tileentities.AbstractTileEntityGrave) RegistryKey(net.minecraft.util.RegistryKey) IGraveData(com.minecolonies.api.colony.IGraveData) Minecraft(net.minecraft.client.Minecraft) COM_MINECOLONIES_JMAP_PREFIX(com.minecolonies.api.util.constant.TranslationConstants.COM_MINECOLONIES_JMAP_PREFIX) MOD_ID(com.minecolonies.api.util.constant.Constants.MOD_ID) Lazy(net.minecraftforge.common.util.Lazy) IColonyView(com.minecolonies.api.colony.IColonyView) World(net.minecraft.world.World) IColonyManager(com.minecolonies.api.colony.IColonyManager) Waypoint(journeymap.client.api.display.Waypoint) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) Nullable(org.jetbrains.annotations.Nullable) ResourceLocation(net.minecraft.util.ResourceLocation) ChunkStatus(net.minecraft.world.chunk.ChunkStatus) IChunk(net.minecraft.world.chunk.IChunk) MapImage(journeymap.client.api.model.MapImage) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) BlockPos(net.minecraft.util.math.BlockPos) Waypoint(journeymap.client.api.display.Waypoint)

Aggregations

Waypoint (journeymap.client.api.display.Waypoint)5 IGraveData (com.minecolonies.api.colony.IGraveData)4 AbstractTileEntityGrave (com.minecolonies.api.tileentities.AbstractTileEntityGrave)4 TileEntity (net.minecraft.tileentity.TileEntity)4 Nullable (org.jetbrains.annotations.Nullable)4 LanguageHandler (com.ldtteam.structurize.util.LanguageHandler)2 MinecoloniesAPIProxy (com.minecolonies.api.MinecoloniesAPIProxy)2 IColonyManager (com.minecolonies.api.colony.IColonyManager)2 IColonyView (com.minecolonies.api.colony.IColonyView)2 Action (com.minecolonies.api.colony.permissions.Action)2 MOD_ID (com.minecolonies.api.util.constant.Constants.MOD_ID)2 COM_MINECOLONIES_JMAP_PREFIX (com.minecolonies.api.util.constant.TranslationConstants.COM_MINECOLONIES_JMAP_PREFIX)2 java.util (java.util)2 DisplayType (journeymap.client.api.display.DisplayType)2 MapImage (journeymap.client.api.model.MapImage)2 Minecraft (net.minecraft.client.Minecraft)2 RegistryKey (net.minecraft.util.RegistryKey)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 BlockPos (net.minecraft.util.math.BlockPos)2 ChunkPos (net.minecraft.util.math.ChunkPos)2