use of com.minecolonies.coremod.colony.buildings.moduleviews.BuildingResourcesModuleView in project minecolonies by Minecolonies.
the class WindowResourceList method pullResourcesFromHut.
/**
* Retrieve resources from the building to display in GUI.
*/
private void pullResourcesFromHut() {
final IBuildingView newView = builder.getColony().getBuilding(builder.getID());
if (newView instanceof BuildingBuilder.View) {
final BuildingResourcesModuleView moduleView = newView.getModuleView(BuildingResourcesModuleView.class);
final PlayerInventory inventory = this.mc.player.inventory;
final boolean isCreative = this.mc.player.isCreative();
final List<Delivery> deliveries = new ArrayList<>();
for (Map.Entry<Integer, Collection<IToken<?>>> entry : builder.getOpenRequestsByCitizen().entrySet()) {
addDeliveryRequestsToList(deliveries, ImmutableList.copyOf(entry.getValue()));
}
resources.clear();
resources.addAll(moduleView.getResources().values());
double supplied = 0;
double total = 0;
for (final BuildingBuilderResource resource : resources) {
final int amountToSet;
if (isCreative) {
amountToSet = resource.getAmount();
} else {
amountToSet = InventoryUtils.getItemCountInItemHandler(new InvWrapper(inventory), stack -> !ItemStackUtils.isEmpty(stack) && ItemStackUtils.compareItemStacksIgnoreStackSize(stack, resource.getItemStack()));
}
resource.setPlayerAmount(amountToSet);
resource.setAmountInDelivery(0);
for (final Delivery delivery : deliveries) {
if (ItemStackUtils.compareItemStacksIgnoreStackSize(resource.getItemStack(), delivery.getStack(), false, false)) {
resource.setAmountInDelivery(resource.getAmountInDelivery() + delivery.getStack().getCount());
}
}
supplied += Math.min(resource.getAvailable(), resource.getAmount());
total += resource.getAmount();
}
if (total > 0) {
findPaneOfTypeByID(LABEL_PROGRESS, Text.class).setText(new TranslationTextComponent("com.minecolonies.coremod.gui.progress.res", (int) ((supplied / total) * 100) + "%", moduleView.getProgress() + "%"));
}
resources.sort(new BuildingBuilderResource.ResourceComparator(NOT_NEEDED, HAVE_ENOUGH, IN_DELIVERY, NEED_MORE, DONT_HAVE));
}
}
use of com.minecolonies.coremod.colony.buildings.moduleviews.BuildingResourcesModuleView in project minecolonies by ldtteam.
the class WindowResourceList method onOpened.
@Override
public void onOpened() {
final ClientPlayerEntity player = Minecraft.getInstance().player;
if (this.builder == null) {
player.sendMessage(new TranslationTextComponent("com.minecolonies.coremod.resourcescroll.nobuilder"), player.getUUID());
close();
return;
}
super.onOpened();
pullResourcesFromHut();
final ScrollingList resourceList = findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class);
if (resourceList == null) {
player.sendMessage(new TranslationTextComponent("com.minecolonies.coremod.resourcescroll.null"), player.getUUID());
close();
return;
}
resourceList.setDataProvider(new ScrollingList.DataProvider() {
@Override
public int getElementCount() {
return resources.size();
}
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
updateResourcePane(index, rowPane);
}
});
final BuildingResourcesModuleView moduleView = builder.getModuleView(BuildingResourcesModuleView.class);
// Make sure we have a fresh view
Network.getNetwork().sendToServer(new MarkBuildingDirtyMessage(builder));
findPaneOfTypeByID(LABEL_WORKERNAME, Text.class).setText(builder.getWorkerName());
findPaneOfTypeByID(LABEL_CONSTRUCTION_NAME, Text.class).setText(moduleView.getConstructionName());
}
use of com.minecolonies.coremod.colony.buildings.moduleviews.BuildingResourcesModuleView in project minecolonies by ldtteam.
the class WindowResourceList method pullResourcesFromHut.
/**
* Retrieve resources from the building to display in GUI.
*/
private void pullResourcesFromHut() {
final IBuildingView newView = builder.getColony().getBuilding(builder.getID());
if (newView instanceof BuildingBuilder.View) {
final BuildingResourcesModuleView moduleView = newView.getModuleView(BuildingResourcesModuleView.class);
final PlayerInventory inventory = this.mc.player.inventory;
final boolean isCreative = this.mc.player.isCreative();
final List<Delivery> deliveries = new ArrayList<>();
for (Map.Entry<Integer, Collection<IToken<?>>> entry : builder.getOpenRequestsByCitizen().entrySet()) {
addDeliveryRequestsToList(deliveries, ImmutableList.copyOf(entry.getValue()));
}
resources.clear();
resources.addAll(moduleView.getResources().values());
double supplied = 0;
double total = 0;
for (final BuildingBuilderResource resource : resources) {
final int amountToSet;
if (isCreative) {
amountToSet = resource.getAmount();
} else {
amountToSet = InventoryUtils.getItemCountInItemHandler(new InvWrapper(inventory), stack -> !ItemStackUtils.isEmpty(stack) && ItemStackUtils.compareItemStacksIgnoreStackSize(stack, resource.getItemStack()));
}
resource.setPlayerAmount(amountToSet);
resource.setAmountInDelivery(0);
for (final Delivery delivery : deliveries) {
if (ItemStackUtils.compareItemStacksIgnoreStackSize(resource.getItemStack(), delivery.getStack(), false, false)) {
resource.setAmountInDelivery(resource.getAmountInDelivery() + delivery.getStack().getCount());
}
}
supplied += Math.min(resource.getAvailable(), resource.getAmount());
total += resource.getAmount();
}
if (total > 0) {
findPaneOfTypeByID(LABEL_PROGRESS, Text.class).setText(new TranslationTextComponent("com.minecolonies.coremod.gui.progress.res", (int) ((supplied / total) * 100) + "%", moduleView.getProgress() + "%"));
}
resources.sort(new BuildingBuilderResource.ResourceComparator(NOT_NEEDED, HAVE_ENOUGH, IN_DELIVERY, NEED_MORE, DONT_HAVE));
}
}
use of com.minecolonies.coremod.colony.buildings.moduleviews.BuildingResourcesModuleView in project minecolonies by Minecolonies.
the class WindowResourceList method onOpened.
@Override
public void onOpened() {
final ClientPlayerEntity player = Minecraft.getInstance().player;
if (this.builder == null) {
player.sendMessage(new TranslationTextComponent("com.minecolonies.coremod.resourcescroll.nobuilder"), player.getUUID());
close();
return;
}
super.onOpened();
pullResourcesFromHut();
final ScrollingList resourceList = findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class);
if (resourceList == null) {
player.sendMessage(new TranslationTextComponent("com.minecolonies.coremod.resourcescroll.null"), player.getUUID());
close();
return;
}
resourceList.setDataProvider(new ScrollingList.DataProvider() {
@Override
public int getElementCount() {
return resources.size();
}
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
updateResourcePane(index, rowPane);
}
});
final BuildingResourcesModuleView moduleView = builder.getModuleView(BuildingResourcesModuleView.class);
// Make sure we have a fresh view
Network.getNetwork().sendToServer(new MarkBuildingDirtyMessage(builder));
findPaneOfTypeByID(LABEL_WORKERNAME, Text.class).setText(builder.getWorkerName());
findPaneOfTypeByID(LABEL_CONSTRUCTION_NAME, Text.class).setText(moduleView.getConstructionName());
}
Aggregations