use of com.minecolonies.api.colony.IColonyView in project minecolonies by Minecolonies.
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 Minecolonies.
the class DebugRendererChunkBorder method renderWorldLastEvent.
public static void renderWorldLastEvent(@NotNull final RenderWorldLastEvent event) {
final PlayerEntity player = Minecraft.getInstance().player;
if (player.getItemInHand(Hand.MAIN_HAND).getItem() != ModItems.buildTool.get()) {
return;
}
final World world = Minecraft.getInstance().level;
final IColonyView nearestColonyView = IColonyManager.getInstance().getClosestColonyView(world, player.blockPosition());
if (nearestColonyView == null) {
return;
}
final ChunkPos playerChunkPos = new ChunkPos(player.blockPosition());
final int playerRenderDist = Math.max(Minecraft.getInstance().options.renderDistance - RENDER_DIST_THRESHOLD, 2);
if (lastColonyView != nearestColonyView || !lastPlayerChunk.equals(playerChunkPos)) {
lastColonyView = nearestColonyView;
lastPlayerChunk = playerChunkPos;
final Map<ChunkPos, Integer> coloniesMap = new HashMap<>();
final Map<ChunkPos, Integer> chunkticketsMap = new HashMap<>();
final int range = Math.max(Minecraft.getInstance().options.renderDistance, MineColonies.getConfig().getServer().maxColonySize.get());
for (int chunkX = -range; chunkX <= range; chunkX++) {
for (int chunkZ = -range; chunkZ <= range; chunkZ++) {
final Chunk chunk = world.getChunk(playerChunkPos.x + chunkX, playerChunkPos.z + chunkZ);
chunk.getCapability(CLOSE_COLONY_CAP, null).ifPresent(cap -> coloniesMap.put(chunk.getPos(), cap.getOwningColony()));
if (nearestColonyView.getTicketedChunks().contains(chunk.getPos().toLong())) {
chunkticketsMap.put(chunk.getPos(), nearestColonyView.getID());
} else {
chunkticketsMap.put(chunk.getPos(), 0);
}
}
}
final BufferBuilder bufferbuilder = Tessellator.getInstance().getBuilder();
colonies = draw(bufferbuilder, coloniesMap, nearestColonyView.getID(), playerChunkPos, playerRenderDist);
chunktickets = draw(bufferbuilder, chunkticketsMap, nearestColonyView.getID(), playerChunkPos, playerRenderDist);
}
final Vector3d currView = Minecraft.getInstance().getEntityRenderDispatcher().camera.getPosition();
final MatrixStack stack = event.getMatrixStack();
final Pair<DrawState, ByteBuffer> buffer = InputMappings.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_LEFT_CONTROL) ? chunktickets : colonies;
stack.pushPose();
stack.translate(-currView.x, -currView.y, -currView.z);
RenderSystem.enableDepthTest();
RenderSystem.shadeModel(7425);
RenderSystem.enableAlphaTest();
RenderSystem.defaultAlphaFunc();
RenderSystem.disableTexture();
RenderSystem.disableBlend();
RenderSystem.lineWidth(1.0F);
RenderSystem.pushMatrix();
RenderSystem.loadIdentity();
RenderSystem.multMatrix(stack.last().pose());
WorldVertexBufferUploader._end(buffer.getSecond(), buffer.getFirst().mode(), buffer.getFirst().format(), buffer.getFirst().vertexCount());
RenderSystem.popMatrix();
RenderSystem.lineWidth(1.0F);
RenderSystem.enableBlend();
RenderSystem.enableTexture();
RenderSystem.shadeModel(7424);
stack.popPose();
}
use of com.minecolonies.api.colony.IColonyView in project minecolonies by Minecolonies.
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 Minecolonies.
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 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