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