Search in sources :

Example 21 with IColonyView

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();
    }
}
Also used : Box(com.ldtteam.blockout.views.Box) ItemStack(net.minecraft.item.ItemStack) IColonyView(com.minecolonies.api.colony.IColonyView) Pane(com.ldtteam.blockout.Pane) RequestWindowCitizen(com.minecolonies.coremod.client.gui.citizen.RequestWindowCitizen)

Example 22 with IColonyView

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());
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) ItemStack(net.minecraft.item.ItemStack) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) IColonyView(com.minecolonies.api.colony.IColonyView) IColonyView(com.minecolonies.api.colony.IColonyView) EmptyView(com.minecolonies.coremod.colony.buildings.views.EmptyView) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView)

Example 23 with IColonyView

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());
    }
}
Also used : IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) StructureName(com.ldtteam.structurize.management.StructureName) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Triple(org.antlr.v4.runtime.misc.Triple) TileEntity(net.minecraft.tileentity.TileEntity) SchematicRequestMessage(com.ldtteam.structurize.network.messages.SchematicRequestMessage) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) BlockPos(net.minecraft.util.math.BlockPos) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) IColonyView(com.minecolonies.api.colony.IColonyView) Mirror(net.minecraft.util.Mirror) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 24 with IColonyView

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);
}
Also used : IColonyView(com.minecolonies.api.colony.IColonyView) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 25 with IColonyView

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

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