use of com.minecolonies.api.colony.IColonyView in project minecolonies by ldtteam.
the class WindowRequestDetail method onOpened.
/**
* Called when the GUI has been opened. Will fill the fields and lists.
*/
@Override
public void onOpened() {
final Box box = findPaneOfTypeByID(BOX_ID_REQUEST, Box.class);
final Text description = PaneBuilders.textBuilder().style(TextFormatting.getByCode('r')).style(TextFormatting.getByCode('0')).append(request.getLongDisplayString()).build();
description.setPosition(1, 1);
description.setSize(box.getWidth() - 2, AbstractTextElement.SIZE_FOR_UNLIMITED_ELEMENTS);
box.addChild(description);
box.setSize(box.getWidth(), description.getRenderedTextHeight() + 2);
description.setSize(box.getWidth() - 2, box.getHeight());
final Image logo = findPaneOfTypeByID(DELIVERY_IMAGE, Image.class);
final ItemIcon exampleStackDisplay = findPaneOfTypeByID(LIST_ELEMENT_ID_REQUEST_STACK, ItemIcon.class);
final List<ItemStack> displayStacks = request.getDisplayStacks();
final IColonyView colony = IColonyManager.getInstance().getColonyView(colonyId, Minecraft.getInstance().level.dimension());
if (!displayStacks.isEmpty()) {
exampleStackDisplay.setItem(displayStacks.get((lifeCount / LIFE_COUNT_DIVIDER) % displayStacks.size()));
} else if (!request.getDisplayIcon().equals(MISSING)) {
logo.setVisible(true);
logo.setImage(request.getDisplayIcon());
PaneBuilders.tooltipBuilder().hoverPane(logo).build().setText(request.getResolverToolTip(colony));
}
findPaneOfTypeByID(REQUESTER, Text.class).setText(request.getRequester().getRequesterDisplayName(colony.getRequestManager(), request));
findPaneOfTypeByID(LIST_ELEMENT_ID_REQUEST_LOCATION, Text.class).setText(request.getRequester().getLocation().toString());
if (colony == null) {
Log.getLogger().warn("---Colony Null in WindowRequestDetail---");
return;
}
try {
final IRequestResolver<?> resolver = colony.getRequestManager().getResolverForRequest(request.getId());
if (resolver == null) {
Log.getLogger().warn("---IRequestResolver Null in WindowRequestDetail---");
return;
}
findPaneOfTypeByID(RESOLVER, Text.class).setText("Resolver: " + resolver.getRequesterDisplayName(colony.getRequestManager(), request).getString());
} catch (@SuppressWarnings(EXCEPTION_HANDLERS_SHOULD_PRESERVE_THE_ORIGINAL_EXCEPTIONS) final IllegalArgumentException e) {
/*
* Do nothing we just need to know if it has a resolver or not.
*/
Log.getLogger().warn("---IRequestResolver Null in WindowRequestDetail---", e);
}
// Checks if fulfill button should be displayed
Pane fulfillButton = this.window.getChildren().stream().filter(pane -> pane.getID().equals(REQUEST_FULLFIL)).findFirst().get();
if ((this.prevWindow instanceof RequestWindowCitizen && !((RequestWindowCitizen) prevWindow).fulfillable(request)) || this.prevWindow instanceof WindowClipBoard) {
fulfillButton.hide();
}
// Checks if cancel button should be displayed
Pane cancelButton = this.window.getChildren().stream().filter(pane -> pane.getID().equals(REQUEST_CANCEL)).findFirst().get();
if (this.prevWindow instanceof RequestWindowCitizen && !((RequestWindowCitizen) prevWindow).cancellable(request)) {
cancelButton.hide();
}
}
use of com.minecolonies.api.colony.IColonyView in project minecolonies by ldtteam.
the class ClientEventHandler method handleRenderScepterGuard.
/**
* Renders the guard scepter objects into the world.
*
* @param event The caught event
* @param world The world in which to render
* @param player The player for which to render
*/
private static void handleRenderScepterGuard(@NotNull final RenderWorldLastEvent event, final ClientWorld world, final PlayerEntity player) {
final PlacementSettings settings = new PlacementSettings(Settings.instance.getMirror(), BlockPosUtil.getRotationFromRotations(Settings.instance.getRotation()));
final ItemStack stack = player.getMainHandItem();
if (!stack.hasTag()) {
return;
}
final CompoundNBT compound = stack.getTag();
final IColonyView colony = IColonyManager.getInstance().getColonyView(compound.getInt(TAG_ID), player.level.dimension());
if (colony == null) {
return;
}
final BlockPos guardTower = BlockPosUtil.read(compound, TAG_POS);
final IBuildingView hut = colony.getBuilding(guardTower);
if (hut == null) {
return;
}
if (partolPointTemplate == null) {
partolPointTemplate = new LoadOnlyStructureHandler(world, hut.getPosition(), "schematics/infrastructure/patrolpoint", settings, true).getBluePrint();
}
if (hut instanceof AbstractBuildingGuards.View) {
StructureClientHandler.renderStructureAtPosList(partolPointTemplate, event.getPartialTicks(), ((AbstractBuildingGuards.View) hut).getPatrolTargets().stream().map(BlockPos::above).collect(Collectors.toList()), event.getMatrixStack());
}
}
use of com.minecolonies.api.colony.IColonyView in project minecolonies by ldtteam.
the class ClientEventHandler method handleRenderBuildTool.
/**
* Renders building bounding boxes into the client
*
* @param event The caught event
* @param world The world in which to render
* @param player The player for which to render
*/
private static void handleRenderBuildTool(@NotNull final RenderWorldLastEvent event, final ClientWorld world, final PlayerEntity player) {
if (Settings.instance.getActiveStructure() == null) {
return;
}
final IColonyView colony = IColonyManager.getInstance().getClosestColonyView(world, new BlockPos(player.position()));
if (colony == null) {
return;
}
final BlockPos activePosition = Settings.instance.getPosition();
final Map<BlockPos, Triple<Blueprint, BlockPos, BlockPos>> newCache = new HashMap<>();
for (final IBuildingView buildingView : colony.getBuildings()) {
if (MinecoloniesAPIProxy.getInstance().getConfig().getClient().neighborbuildingrendering.get()) {
if (buildingView.getBuildingType() == ModBuildings.postBox || buildingView.getBuildingType() == ModBuildings.stash) {
continue;
}
final BlockPos currentPosition = buildingView.getPosition();
if (activePosition.closerThan(currentPosition, PREVIEW_RANGE)) {
if (blueprintCache.containsKey(currentPosition)) {
newCache.put(currentPosition, blueprintCache.get(currentPosition));
continue;
}
final TileEntity tile = world.getBlockEntity(buildingView.getID());
String schematicName = buildingView.getSchematicName();
if (tile instanceof IBlueprintDataProvider) {
if (!((IBlueprintDataProvider) tile).getSchematicName().isEmpty()) {
schematicName = ((IBlueprintDataProvider) tile).getSchematicName().replaceAll("\\d$", "");
}
}
final StructureName sn = new StructureName(Structures.SCHEMATICS_PREFIX, buildingView.getStyle(), schematicName + buildingView.getBuildingMaxLevel());
final String structureName = sn.toString();
final String md5 = Structures.getMD5(structureName);
final IStructureHandler wrapper = new LoadOnlyStructureHandler(world, buildingView.getID(), structureName, new PlacementSettings(), true);
if (!wrapper.hasBluePrint() || !wrapper.isCorrectMD5(md5)) {
if (alreadyRequestedStructures.contains(structureName)) {
continue;
}
alreadyRequestedStructures.add(structureName);
Log.getLogger().error("Couldn't find schematic: " + structureName + " requesting to server if possible.");
if (ServerLifecycleHooks.getCurrentServer() == null) {
Network.getNetwork().sendToServer(new SchematicRequestMessage(structureName));
}
continue;
}
final Blueprint blueprint = wrapper.getBluePrint();
final Mirror mirror = buildingView.isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE;
blueprint.rotateWithMirror(BlockPosUtil.getRotationFromRotations(buildingView.getRotation()), mirror, world);
final BlockPos primaryOffset = blueprint.getPrimaryBlockOffset();
final BlockPos boxStartPos = currentPosition.subtract(primaryOffset);
final BlockPos size = new BlockPos(blueprint.getSizeX(), blueprint.getSizeY(), blueprint.getSizeZ());
final BlockPos boxEndPos = boxStartPos.offset(size).subtract(new BlockPos(1, 1, 1));
blueprint.setRenderSource(buildingView.getID());
if (buildingView.getBuildingLevel() < buildingView.getBuildingMaxLevel()) {
newCache.put(currentPosition, new Triple(blueprint, boxStartPos, boxEndPos));
} else {
newCache.put(currentPosition, new Triple<>(null, boxStartPos, boxEndPos));
}
}
}
}
blueprintCache = newCache;
for (final Map.Entry<BlockPos, Triple<Blueprint, BlockPos, BlockPos>> nearbyBuilding : blueprintCache.entrySet()) {
final Triple<Blueprint, BlockPos, BlockPos> buildingData = nearbyBuilding.getValue();
final BlockPos position = nearbyBuilding.getKey();
if (buildingData.a != null) {
StructureClientHandler.renderStructureAtPos(buildingData.a, event.getPartialTicks(), position, event.getMatrixStack());
}
RenderUtils.renderBox(buildingData.b, buildingData.c, 0, 0, 1, 1.0F, 0.002D, event.getMatrixStack(), linesWithCullAndDepth.get());
}
}
use of com.minecolonies.api.colony.IColonyView in project minecolonies by ldtteam.
the class TileEntityColonyFlag method getPatternList.
/**
* Retrieves the patterns for the renderer
* @return the list of pattern-color pairs
*/
@OnlyIn(Dist.CLIENT)
public List<Pair<BannerPattern, DyeColor>> getPatternList() {
// Structurize will cause the second condition to be false
if (level != null && level.dimension() != null) {
IColonyView colony = IColonyManager.getInstance().getColonyView(this.colonyId, level.dimension());
if (colony != null && this.flag != colony.getColonyFlag()) {
this.flag = colony.getColonyFlag();
setChanged();
}
}
return BannerTileEntity.createPatterns(DyeColor.WHITE, this.flag.size() > 1 ? this.flag : this.patterns);
}
use of com.minecolonies.api.colony.IColonyView 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));
}
}
}
Aggregations