Search in sources :

Example 1 with IColonyView

use of com.minecolonies.api.colony.IColonyView in project minecolonies by Minecolonies.

the class ColonyBorderMapping method updateChunk.

/**
 * Flags the colony border overlay for update, if needed for a single just-loaded chunk.
 *
 * @param jmap The JourneyMap API
 * @param dimension The dimension of the world.  Nothing happens unless this is the client world.
 * @param chunk The chunk that was just loaded.
 */
public static void updateChunk(@NotNull final Journeymap jmap, @NotNull final RegistryKey<World> dimension, @NotNull final Chunk chunk) {
    final World world = Minecraft.getInstance().level;
    if (world == null || !dimension.equals(world.dimension()))
        return;
    final Map<Integer, ColonyBorderOverlay> dimensionOverlays = overlays.get(dimension);
    // not ready yet
    if (dimensionOverlays == null)
        return;
    boolean changed = false;
    final int id = getOwningColonyForChunk(chunk);
    if (id == 0) {
        for (final Map<Integer, ColonyBorderOverlay> overlayMap : overlays.values()) {
            for (final ColonyBorderOverlay overlay : overlayMap.values()) {
                changed |= overlay.updateChunks(Collections.emptySet(), Collections.singleton(chunk.getPos()));
            }
        }
    } else {
        final IColonyManager colonyManager = MinecoloniesAPIProxy.getInstance().getColonyManager();
        final IColonyView colony = colonyManager.getColonyView(id, dimension);
        final ColonyBorderOverlay overlay = dimensionOverlays.computeIfAbsent(id, k -> new ColonyBorderOverlay(dimension, id));
        changed |= overlay.updateChunks(Collections.singleton(chunk.getPos()), Collections.emptySet());
        changed |= overlay.updateInfo(colony, JourneymapOptions.getShowColonyName(jmap.getOptions()));
    }
}
Also used : IColonyManager(com.minecolonies.api.colony.IColonyManager) World(net.minecraft.world.World) IColonyView(com.minecolonies.api.colony.IColonyView)

Example 2 with IColonyView

use of com.minecolonies.api.colony.IColonyView 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 IColonyView

use of com.minecolonies.api.colony.IColonyView in project minecolonies by Minecolonies.

the class EventListener method onColonyViewUpdated.

@SubscribeEvent
public void onColonyViewUpdated(@NotNull final ColonyViewUpdatedEvent event) {
    final IColonyView colony = event.getColony();
    final Set<BlockPos> graves = colony.getGraveManager().getGraves().keySet();
    ColonyDeathpoints.updateGraves(this.jmap, colony, graves);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) IColonyView(com.minecolonies.api.colony.IColonyView) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 4 with IColonyView

use of com.minecolonies.api.colony.IColonyView in project minecolonies by Minecolonies.

the class ItemScepterPermission method useOn.

/**
 * Used when clicking on block in world.
 *
 * @return the result
 */
@Override
@NotNull
public ActionResultType useOn(final ItemUseContext ctx) {
    if (!ctx.getLevel().isClientSide) {
        return ActionResultType.SUCCESS;
    }
    final ItemStack scepter = ctx.getPlayer().getItemInHand(ctx.getHand());
    if (!scepter.hasTag()) {
        scepter.setTag(new CompoundNBT());
    }
    final IColonyView iColonyView = IColonyManager.getInstance().getClosestColonyView(ctx.getLevel(), ctx.getClickedPos());
    if (iColonyView == null) {
        return ActionResultType.FAIL;
    }
    final CompoundNBT compound = scepter.getTag();
    return handleItemAction(compound, ctx.getPlayer(), ctx.getLevel(), ctx.getClickedPos(), iColonyView);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ItemStack(net.minecraft.item.ItemStack) IColonyView(com.minecolonies.api.colony.IColonyView) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with IColonyView

use of com.minecolonies.api.colony.IColonyView in project minecolonies by Minecolonies.

the class ItemResourceScroll method appendHoverText.

@Override
@OnlyIn(Dist.CLIENT)
public void appendHoverText(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
    super.appendHoverText(stack, worldIn, tooltip, flagIn);
    if (worldIn == null)
        return;
    final CompoundNBT compound = checkForCompound(stack);
    final int colonyId = compound.getInt(TAG_COLONY_ID);
    final BlockPos builderPos = BlockPosUtil.read(compound, TAG_BUILDER);
    final IColonyView colonyView = IColonyManager.getInstance().getColonyView(colonyId, worldIn.dimension());
    if (colonyView != null) {
        final IBuildingView buildingView = colonyView.getBuilding(builderPos);
        if (buildingView instanceof BuildingBuilder.View) {
            String name = ((BuildingBuilder.View) buildingView).getWorkerName();
            tooltip.add(name != null && !name.trim().isEmpty() ? new StringTextComponent(TextFormatting.DARK_PURPLE + name) : new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_SCROLL_NO_BUILDER));
        }
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) StringTextComponent(net.minecraft.util.text.StringTextComponent) IColonyView(com.minecolonies.api.colony.IColonyView) IColonyView(com.minecolonies.api.colony.IColonyView) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Aggregations

IColonyView (com.minecolonies.api.colony.IColonyView)26 BlockPos (net.minecraft.util.math.BlockPos)14 IColonyManager (com.minecolonies.api.colony.IColonyManager)8 ItemStack (net.minecraft.item.ItemStack)8 CompoundNBT (net.minecraft.nbt.CompoundNBT)8 World (net.minecraft.world.World)8 NotNull (org.jetbrains.annotations.NotNull)8 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)6 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)6 java.util (java.util)6 Minecraft (net.minecraft.client.Minecraft)6 Nullable (org.jetbrains.annotations.Nullable)6 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)5 Pane (com.ldtteam.blockout.Pane)4 StructureName (com.ldtteam.structurize.management.StructureName)4 SchematicRequestMessage (com.ldtteam.structurize.network.messages.SchematicRequestMessage)4 LanguageHandler (com.ldtteam.structurize.util.LanguageHandler)4 MinecoloniesAPIProxy (com.minecolonies.api.MinecoloniesAPIProxy)4 Constants (com.minecolonies.api.util.constant.Constants)3 MutableChunkPos (com.minecolonies.coremod.util.MutableChunkPos)3