Search in sources :

Example 16 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by ldtteam.

the class WindowMineGuardModule method pullGuardsFromHut.

/**
 * Retrieve guards from the building to display in GUI.
 */
private void pullGuardsFromHut() {
    if (buildingView.getColony().getBuilding(buildingView.getID()) != null) {
        guardsInfo.clear();
        assignedGuards = 0;
        final List<IBuildingView> buildings = buildingView.getColony().getBuildings().stream().filter(entry -> entry instanceof AbstractBuildingGuards.View && entry.getModuleView(SettingsModuleView.class).getSetting(AbstractBuildingGuards.GUARD_TASK).getValue().equals(GuardTaskSetting.PATROL_MINE)).collect(Collectors.toList());
        for (final IBuildingView building : buildings) {
            final AbstractBuildingGuards.View guardbuilding = (AbstractBuildingGuards.View) building;
            if (guardbuilding.getMinePos() != null && guardbuilding.getMinePos().equals(buildingView.getPosition())) {
                assignedGuards++;
            }
            for (final Integer citizenId : guardbuilding.getGuards()) {
                guardsInfo.add(buildingView.getColony().getCitizen(citizenId));
            }
        }
        if (guardsInfo.isEmpty()) {
            findPaneOfTypeByID("noguardwarning", Text.class).setVisible(true);
        } else {
            findPaneOfTypeByID("noguardwarning", Text.class).setVisible(false);
        }
    }
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) GuardTaskSetting(com.minecolonies.coremod.colony.buildings.modules.settings.GuardTaskSetting) Pane(com.ldtteam.blockout.Pane) Collectors(java.util.stream.Collectors) Text(com.ldtteam.blockout.controls.Text) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ArrayList(java.util.ArrayList) List(java.util.List) Button(com.ldtteam.blockout.controls.Button) AbstractModuleWindow(com.minecolonies.coremod.client.gui.AbstractModuleWindow) SettingsModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.SettingsModuleView) GuardSetMinePosMessage(com.minecolonies.coremod.network.messages.server.colony.building.guard.GuardSetMinePosMessage) Network(com.minecolonies.coremod.Network) Constants(com.minecolonies.api.util.constant.Constants) AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) Text(com.ldtteam.blockout.controls.Text) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) SettingsModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.SettingsModuleView)

Example 17 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by ldtteam.

the class WindowWorkOrderPage method fillWorkOrderList.

/**
 * Fills the workOrder list inside the townhall GUI.
 */
private void fillWorkOrderList() {
    final ScrollingList workOrderList = findPaneOfTypeByID(LIST_WORKORDER, ScrollingList.class);
    workOrderList.enable();
    workOrderList.show();
    // Creates a dataProvider for the unemployed citizenList.
    workOrderList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return workOrders.size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final WorkOrderView workOrder = workOrders.get(index);
            String claimingCitizen = "";
            final int numElements = getElementCount();
            if (index == 0) {
                if (numElements == 1) {
                    rowPane.findPaneOfTypeByID(BUTTON_DOWN, Button.class).hide();
                } else {
                    rowPane.findPaneOfTypeByID(BUTTON_DOWN, Button.class).show();
                }
                rowPane.findPaneOfTypeByID(BUTTON_UP, Button.class).hide();
            } else if (index == numElements - 1) {
                rowPane.findPaneOfTypeByID(BUTTON_DOWN, Button.class).hide();
            }
            // Searches citizen of id x
            for (@NotNull final IBuildingView buildingView : building.getColony().getBuildings()) {
                if (buildingView.getPosition().equals(workOrder.getClaimedBy()) && buildingView instanceof AbstractBuildingBuilderView) {
                    claimingCitizen = ((AbstractBuildingBuilderView) buildingView).getWorkerName();
                    break;
                }
            }
            rowPane.findPaneOfTypeByID(WORK_LABEL, Text.class).setText(workOrder.getDisplayName());
            rowPane.findPaneOfTypeByID(ASSIGNEE_LABEL, Text.class).setText(claimingCitizen);
            rowPane.findPaneOfTypeByID(HIDDEN_WORKORDER_ID, Text.class).setText(Integer.toString(workOrder.getId()));
        }
    });
}
Also used : WorkOrderView(com.minecolonies.api.colony.workorders.WorkOrderView) AbstractBuildingBuilderView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingBuilderView) Button(com.ldtteam.blockout.controls.Button) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane)

Example 18 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by Minecolonies.

the class BuildingEntry method produceBuildingView.

public IBuildingView produceBuildingView(final BlockPos position, final IColonyView colony) {
    final IBuildingView buildingView = buildingViewProducer.get().apply(colony, position);
    for (final Supplier<Supplier<IBuildingModuleView>> module : buildingModuleViewProducers) {
        buildingView.registerModule(module.get().get());
    }
    buildingView.setBuildingType(this);
    return buildingView;
}
Also used : IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) Supplier(java.util.function.Supplier)

Example 19 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by Minecolonies.

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 20 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by Minecolonies.

the class ColonyView method handleColonyBuildingViewMessage.

/**
 * Update a ColonyView's buildings given a network data ColonyView update packet. This uses a full-replacement - buildings do not get updated and are instead overwritten.
 *
 * @param buildingId location of the building.
 * @param buf        buffer containing ColonyBuilding information.
 * @return null == no response.
 */
@Override
@Nullable
public IMessage handleColonyBuildingViewMessage(final BlockPos buildingId, @NotNull final PacketBuffer buf) {
    if (buildings.containsKey(buildingId)) {
        // Read the string first to set up the buffer.
        buf.readUtf(32767);
        buildings.get(buildingId).deserialize(buf);
    } else {
        @Nullable final IBuildingView building = IBuildingDataManager.getInstance().createViewFrom(this, buildingId, buf);
        if (building != null) {
            buildings.put(building.getID(), building);
            if (building instanceof BuildingTownHall.View) {
                townHall = (ITownHallView) building;
            }
        }
    }
    return null;
}
Also used : IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ITownHallView(com.minecolonies.api.colony.buildings.workerbuildings.ITownHallView) WorkOrderView(com.minecolonies.api.colony.workorders.WorkOrderView) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) PermissionsView(com.minecolonies.coremod.colony.permissions.PermissionsView) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)30 Pane (com.ldtteam.blockout.Pane)14 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)14 ScrollingList (com.ldtteam.blockout.views.ScrollingList)12 Text (com.ldtteam.blockout.controls.Text)10 IColonyView (com.minecolonies.api.colony.IColonyView)10 BlockPos (net.minecraft.util.math.BlockPos)10 Button (com.ldtteam.blockout.controls.Button)8 Nullable (org.jetbrains.annotations.Nullable)8 NotNull (org.jetbrains.annotations.NotNull)7 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)6 ICitizenDataView (com.minecolonies.api.colony.ICitizenDataView)6 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)6 Constants (com.minecolonies.api.util.constant.Constants)6 Network (com.minecolonies.coremod.Network)6 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)6 AbstractBuildingView (com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView)6 List (java.util.List)6 ItemStack (net.minecraft.item.ItemStack)6 Image (com.ldtteam.blockout.controls.Image)4