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()));
}
}
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));
}
}
}
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);
}
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);
}
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));
}
}
}
Aggregations