Search in sources :

Example 1 with BuildingResourcesModuleView

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));
    }
}
Also used : MarkBuildingDirtyMessage(com.minecolonies.coremod.network.messages.server.colony.building.MarkBuildingDirtyMessage) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) WindowBuilderResModule(com.minecolonies.coremod.client.gui.modules.WindowBuilderResModule) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) ImmutableCollection(com.google.common.collect.ImmutableCollection) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) BuildingBuilder(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBuilder) ScrollingList(com.ldtteam.blockout.views.ScrollingList) ItemIcon(com.ldtteam.blockout.controls.ItemIcon) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ImmutableList(com.google.common.collect.ImmutableList) Minecraft(net.minecraft.client.Minecraft) Map(java.util.Map) RessourceAvailability(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource.RessourceAvailability) Delivery(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery) Network(com.minecolonies.coremod.Network) Constants(com.minecolonies.api.util.constant.Constants) PlayerInventory(net.minecraft.entity.player.PlayerInventory) IColonyView(com.minecolonies.api.colony.IColonyView) BuildingResourcesModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.BuildingResourcesModuleView) Collection(java.util.Collection) IColonyManager(com.minecolonies.api.colony.IColonyManager) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) BlockPos(net.minecraft.util.math.BlockPos) Pane(com.ldtteam.blockout.Pane) Text(com.ldtteam.blockout.controls.Text) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Image(com.ldtteam.blockout.controls.Image) WindowConstants(com.minecolonies.api.util.constant.WindowConstants) InventoryUtils(com.minecolonies.api.util.InventoryUtils) NotNull(org.jetbrains.annotations.NotNull) ArrayList(java.util.ArrayList) Text(com.ldtteam.blockout.controls.Text) PlayerInventory(net.minecraft.entity.player.PlayerInventory) IColonyView(com.minecolonies.api.colony.IColonyView) BuildingResourcesModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.BuildingResourcesModuleView) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) BuildingResourcesModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.BuildingResourcesModuleView) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ImmutableCollection(com.google.common.collect.ImmutableCollection) Collection(java.util.Collection) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Delivery(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) Map(java.util.Map)

Example 2 with BuildingResourcesModuleView

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());
}
Also used : TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Text(com.ldtteam.blockout.controls.Text) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane) BuildingResourcesModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.BuildingResourcesModuleView) MarkBuildingDirtyMessage(com.minecolonies.coremod.network.messages.server.colony.building.MarkBuildingDirtyMessage)

Example 3 with BuildingResourcesModuleView

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));
    }
}
Also used : MarkBuildingDirtyMessage(com.minecolonies.coremod.network.messages.server.colony.building.MarkBuildingDirtyMessage) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) WindowBuilderResModule(com.minecolonies.coremod.client.gui.modules.WindowBuilderResModule) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) ImmutableCollection(com.google.common.collect.ImmutableCollection) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) BuildingBuilder(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBuilder) ScrollingList(com.ldtteam.blockout.views.ScrollingList) ItemIcon(com.ldtteam.blockout.controls.ItemIcon) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ImmutableList(com.google.common.collect.ImmutableList) Minecraft(net.minecraft.client.Minecraft) Map(java.util.Map) RessourceAvailability(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource.RessourceAvailability) Delivery(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery) Network(com.minecolonies.coremod.Network) Constants(com.minecolonies.api.util.constant.Constants) PlayerInventory(net.minecraft.entity.player.PlayerInventory) IColonyView(com.minecolonies.api.colony.IColonyView) BuildingResourcesModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.BuildingResourcesModuleView) Collection(java.util.Collection) IColonyManager(com.minecolonies.api.colony.IColonyManager) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) BlockPos(net.minecraft.util.math.BlockPos) Pane(com.ldtteam.blockout.Pane) Text(com.ldtteam.blockout.controls.Text) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Image(com.ldtteam.blockout.controls.Image) WindowConstants(com.minecolonies.api.util.constant.WindowConstants) InventoryUtils(com.minecolonies.api.util.InventoryUtils) NotNull(org.jetbrains.annotations.NotNull) ArrayList(java.util.ArrayList) Text(com.ldtteam.blockout.controls.Text) PlayerInventory(net.minecraft.entity.player.PlayerInventory) IColonyView(com.minecolonies.api.colony.IColonyView) BuildingResourcesModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.BuildingResourcesModuleView) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) BuildingResourcesModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.BuildingResourcesModuleView) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ImmutableCollection(com.google.common.collect.ImmutableCollection) Collection(java.util.Collection) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Delivery(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) Map(java.util.Map)

Example 4 with BuildingResourcesModuleView

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());
}
Also used : TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Text(com.ldtteam.blockout.controls.Text) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane) BuildingResourcesModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.BuildingResourcesModuleView) MarkBuildingDirtyMessage(com.minecolonies.coremod.network.messages.server.colony.building.MarkBuildingDirtyMessage)

Aggregations

Pane (com.ldtteam.blockout.Pane)4 Text (com.ldtteam.blockout.controls.Text)4 ScrollingList (com.ldtteam.blockout.views.ScrollingList)4 BuildingResourcesModuleView (com.minecolonies.coremod.colony.buildings.moduleviews.BuildingResourcesModuleView)4 MarkBuildingDirtyMessage (com.minecolonies.coremod.network.messages.server.colony.building.MarkBuildingDirtyMessage)4 ClientPlayerEntity (net.minecraft.client.entity.player.ClientPlayerEntity)4 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)4 ImmutableCollection (com.google.common.collect.ImmutableCollection)2 ImmutableList (com.google.common.collect.ImmutableList)2 Image (com.ldtteam.blockout.controls.Image)2 ItemIcon (com.ldtteam.blockout.controls.ItemIcon)2 IColonyManager (com.minecolonies.api.colony.IColonyManager)2 IColonyView (com.minecolonies.api.colony.IColonyView)2 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)2 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)2 Delivery (com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery)2 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)2 InventoryUtils (com.minecolonies.api.util.InventoryUtils)2 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)2 Constants (com.minecolonies.api.util.constant.Constants)2