Search in sources :

Example 1 with TryResearchMessage

use of com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage in project minecolonies by ldtteam.

the class WindowResearchTree method drawResearchItem.

/**
 * Draw the entirety of an individual research item on a tree, including icons and tooltips.
 *
 * @param view      the view to append it to.
 * @param offsetX   the horizontal offset of the left side of the research block.
 * @param offsetY   the vertical offset of the top side of the research block.
 * @param research  the global research characteristics to draw.
 * @param abandoned the abandoned status of the parent of the research, if one is present.
 * @return abandoned status, true if the research is blocked in the local colony the completion of a sibling research, or an ancestor's sibling's research.
 */
private boolean drawResearchItem(final ZoomDragView view, final int offsetX, final int offsetY, final IGlobalResearch research, boolean abandoned) {
    final ILocalResearchTree tree = building.getColony().getResearchManager().getResearchTree();
    final boolean parentResearched = tree.hasCompletedResearch(research.getParent());
    final IGlobalResearch parentResearch = IGlobalResearchTree.getInstance().getResearch(branch, research.getParent());
    final ResearchState state = tree.getResearch(branch, research.getId()) == null ? ResearchState.NOT_STARTED : tree.getResearch(branch, research.getId()).getState();
    final int progress = tree.getResearch(branch, research.getId()) == null ? 0 : tree.getResearch(branch, research.getId()).getProgress();
    if (mc.player.isCreative() && state == ResearchState.IN_PROGRESS && MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchCreativeCompletion.get() && progress < IGlobalResearchTree.getInstance().getBranchData(branch).getBaseTime(research.getDepth())) {
        Network.getNetwork().sendToServer(new TryResearchMessage(building, research.getId(), research.getBranch(), false));
    }
    if (research.getDepth() != 1 && (state != ResearchState.FINISHED && state != ResearchState.IN_PROGRESS) && parentResearch.hasOnlyChild() && parentResearch.hasResearchedChild(tree)) {
        abandoned = true;
    }
    final ResearchButtonState researchState = getResearchButtonState(abandoned, parentResearched, research, state);
    drawResearchBoxes(view, offsetX, offsetY, research, researchState, progress);
    drawResearchReqsAndCosts(view, offsetX, offsetY, research, researchState);
    drawResearchIcons(view, offsetX, offsetY, research, researchState);
    drawResearchTexts(view, offsetX, offsetY, research, researchState, progress);
    return abandoned;
}
Also used : TryResearchMessage(com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage) ResearchState(com.minecolonies.api.research.util.ResearchState)

Example 2 with TryResearchMessage

use of com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage in project minecolonies by Minecolonies.

the class WindowResearchTree method drawResearchItem.

/**
 * Draw the entirety of an individual research item on a tree, including icons and tooltips.
 *
 * @param view      the view to append it to.
 * @param offsetX   the horizontal offset of the left side of the research block.
 * @param offsetY   the vertical offset of the top side of the research block.
 * @param research  the global research characteristics to draw.
 * @param abandoned the abandoned status of the parent of the research, if one is present.
 * @return abandoned status, true if the research is blocked in the local colony the completion of a sibling research, or an ancestor's sibling's research.
 */
private boolean drawResearchItem(final ZoomDragView view, final int offsetX, final int offsetY, final IGlobalResearch research, boolean abandoned) {
    final ILocalResearchTree tree = building.getColony().getResearchManager().getResearchTree();
    final boolean parentResearched = tree.hasCompletedResearch(research.getParent());
    final IGlobalResearch parentResearch = IGlobalResearchTree.getInstance().getResearch(branch, research.getParent());
    final ResearchState state = tree.getResearch(branch, research.getId()) == null ? ResearchState.NOT_STARTED : tree.getResearch(branch, research.getId()).getState();
    final int progress = tree.getResearch(branch, research.getId()) == null ? 0 : tree.getResearch(branch, research.getId()).getProgress();
    if (mc.player.isCreative() && state == ResearchState.IN_PROGRESS && MinecoloniesAPIProxy.getInstance().getConfig().getServer().researchCreativeCompletion.get() && progress < IGlobalResearchTree.getInstance().getBranchData(branch).getBaseTime(research.getDepth())) {
        Network.getNetwork().sendToServer(new TryResearchMessage(building, research.getId(), research.getBranch(), false));
    }
    if (research.getDepth() != 1 && (state != ResearchState.FINISHED && state != ResearchState.IN_PROGRESS) && parentResearch.hasOnlyChild() && parentResearch.hasResearchedChild(tree)) {
        abandoned = true;
    }
    final ResearchButtonState researchState = getResearchButtonState(abandoned, parentResearched, research, state);
    drawResearchBoxes(view, offsetX, offsetY, research, researchState, progress);
    drawResearchReqsAndCosts(view, offsetX, offsetY, research, researchState);
    drawResearchIcons(view, offsetX, offsetY, research, researchState);
    drawResearchTexts(view, offsetX, offsetY, research, researchState, progress);
    return abandoned;
}
Also used : TryResearchMessage(com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage) ResearchState(com.minecolonies.api.research.util.ResearchState)

Example 3 with TryResearchMessage

use of com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage in project minecolonies by Minecolonies.

the class WindowResearchTree method onButtonClicked.

@Override
public void onButtonClicked(@NotNull final Button button) {
    super.onButtonClicked(button);
    // closing and reopening the WindowResearchTree.
    if (button.getParent().getChildren().contains(undoButton)) {
        button.getParent().removeChild(undoButton);
    }
    for (ItemIcon icon : undoCostIcons) {
        if (button.getParent().getChildren().contains(icon)) {
            button.getParent().removeChild(icon);
        }
    }
    if (button.getParent().getChildren().contains(undoText)) {
        button.getParent().removeChild(undoText);
    }
    // May eventually want a sound handler here, but SoundUtils.playErrorSound is a bit much.
    if (button.getID().isEmpty()) {
    // intentionally empty.
    } else // Undo just the selected research.
    if (button.getID().contains("undo:")) {
        final String undoName = button.getID().substring(button.getID().indexOf(':') + 1);
        if (!ResourceLocation.isValidResourceLocation(undoName)) {
            return;
        }
        final ResourceLocation undoID = new ResourceLocation(undoName);
        final ILocalResearch cancelResearch = building.getColony().getResearchManager().getResearchTree().getResearch(branch, undoID);
        if (cancelResearch != null) {
            // Instead, offset the UniversityWindow's count by -1 before the packet could be sent.
            if (cancelResearch.getState() == ResearchState.IN_PROGRESS) {
                last.updateResearchCount(-1);
            }
            // Canceled research will eventually be removed from the local tree on synchronization from server,
            // But this can be long enough (~5 seconds) to cause confusion if the player reopens the WindowResearchTree.
            // Completely removing the research to null will allow players to unintentionally restart it.
            // While the server-side logic prevents this from taking items, it would be confusing.
            // Setting to NOT_STARTED means that it can't be sent, as only null research states
            // are eligible to send TryResearchMessages, and only IN_PROGRESS, or FINISHED
            // are eligible to drawUndo buttons.
            cancelResearch.setState(ResearchState.NOT_STARTED);
            Network.getNetwork().sendToServer(new TryResearchMessage(building, cancelResearch.getId(), cancelResearch.getBranch(), true));
            close();
        }
    } else if (ResourceLocation.isValidResourceLocation(button.getID()) && IGlobalResearchTree.getInstance().getResearch(branch, new ResourceLocation(button.getID())) != null && (building.getBuildingLevel() >= IGlobalResearchTree.getInstance().getResearch(branch, new ResourceLocation(button.getID())).getDepth() || building.getBuildingLevel() == building.getBuildingMaxLevel())) {
        final IGlobalResearch research = IGlobalResearchTree.getInstance().getResearch(branch, new ResourceLocation(button.getID()));
        final ILocalResearch localResearch = building.getColony().getResearchManager().getResearchTree().getResearch(branch, research.getId());
        if (localResearch == null && building.getBuildingLevel() > building.getColony().getResearchManager().getResearchTree().getResearchInProgress().size() && (research.hasEnoughResources(new InvWrapper(Minecraft.getInstance().player.inventory)) || (mc.player.isCreative()))) {
            // This side won't actually start research; it'll be overridden the next colony update from the server.
            // It will, however, update for the next WindowResearchTree if the colony update is slow to come back.
            // Again, the server will prevent someone from paying items twice, but this avoids some confusion.
            research.startResearch(building.getColony().getResearchManager().getResearchTree());
            // don't need to offset count here, as the startResearch will pad it until the new Colony data comes in.
            last.updateResearchCount(0);
            if (research.getDepth() > building.getBuildingMaxLevel()) {
                hasMax = true;
            }
            Network.getNetwork().sendToServer(new TryResearchMessage(building, research.getId(), research.getBranch(), false));
            close();
        } else if (localResearch != null) {
            // This still costs items, so mostly only beneficial to free up a researcher slot.
            if (localResearch.getState() == ResearchState.IN_PROGRESS) {
                drawUndoProgressButton(button);
            }
            if (localResearch.getState() == ResearchState.FINISHED) {
                // Autostart research should not allow undo of completed research as well, as it will attempt to restart it on colony reload.
                if (research.isImmutable() || research.isAutostart()) {
                    return;
                }
                // don't allow research with completed or in-progress children to be reset.  They must be reset individually.
                for (ResourceLocation childId : research.getChildren()) {
                    if (building.getColony().getResearchManager().getResearchTree().getResearch(branch, childId) != null && building.getColony().getResearchManager().getResearchTree().getResearch(branch, childId).getState() != ResearchState.NOT_STARTED) {
                        return;
                    }
                }
                // Probably not vital most of the time, but even some beneficial effects may not be desirable in all circumstances.
                if (branchType == ResearchBranchType.UNLOCKABLES) {
                    drawUndoCompleteButton(button);
                }
                // above-max-level research prohibits other options, and should be resetable.
                if (hasMax && research.getDepth() > building.getBuildingMaxLevel() && building.getBuildingLevel() == building.getBuildingMaxLevel()) {
                    drawUndoCompleteButton(button);
                    return;
                }
                // researches with an ancestor with OnlyChild status should be undoable, no children are complete or in-progress.
                ResourceLocation parentId = IGlobalResearchTree.getInstance().getResearch(branch, research.getId()).getParent();
                while (!parentId.getPath().isEmpty()) {
                    if (IGlobalResearchTree.getInstance().getResearch(branch, parentId) != null && IGlobalResearchTree.getInstance().getResearch(branch, parentId).hasOnlyChild()) {
                        drawUndoCompleteButton(button);
                        break;
                    }
                    parentId = IGlobalResearchTree.getInstance().getResearch(branch, parentId).getParent();
                }
            }
        }
    } else // Cancel the entire WindowResearchTree
    if (button.getID().equals("cancel")) {
        this.close();
        last.open();
    }
}
Also used : TryResearchMessage(com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage) ResourceLocation(net.minecraft.util.ResourceLocation) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper)

Example 4 with TryResearchMessage

use of com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage in project minecolonies by Minecolonies.

the class NetworkChannel method registerCommonMessages.

/**
 * Registers all common messages.
 */
public void registerCommonMessages() {
    setupInternalMessages();
    int idx = 0;
    registerMessage(++idx, ServerUUIDMessage.class, ServerUUIDMessage::new);
    // ColonyView messages
    registerMessage(++idx, ColonyViewMessage.class, ColonyViewMessage::new);
    registerMessage(++idx, ColonyViewCitizenViewMessage.class, ColonyViewCitizenViewMessage::new);
    registerMessage(++idx, ColonyViewRemoveCitizenMessage.class, ColonyViewRemoveCitizenMessage::new);
    registerMessage(++idx, ColonyViewBuildingViewMessage.class, ColonyViewBuildingViewMessage::new);
    registerMessage(++idx, ColonyViewRemoveBuildingMessage.class, ColonyViewRemoveBuildingMessage::new);
    registerMessage(++idx, PermissionsMessage.View.class, PermissionsMessage.View::new);
    registerMessage(++idx, ColonyStylesMessage.class, ColonyStylesMessage::new);
    registerMessage(++idx, ColonyViewWorkOrderMessage.class, ColonyViewWorkOrderMessage::new);
    registerMessage(++idx, ColonyViewRemoveWorkOrderMessage.class, ColonyViewRemoveWorkOrderMessage::new);
    registerMessage(++idx, UpdateChunkCapabilityMessage.class, UpdateChunkCapabilityMessage::new);
    // Permission Request messages
    registerMessage(++idx, PermissionsMessage.Permission.class, PermissionsMessage.Permission::new);
    registerMessage(++idx, PermissionsMessage.AddPlayer.class, PermissionsMessage.AddPlayer::new);
    registerMessage(++idx, PermissionsMessage.RemovePlayer.class, PermissionsMessage.RemovePlayer::new);
    registerMessage(++idx, PermissionsMessage.ChangePlayerRank.class, PermissionsMessage.ChangePlayerRank::new);
    registerMessage(++idx, PermissionsMessage.AddPlayerOrFakePlayer.class, PermissionsMessage.AddPlayerOrFakePlayer::new);
    registerMessage(++idx, PermissionsMessage.AddRank.class, PermissionsMessage.AddRank::new);
    registerMessage(++idx, PermissionsMessage.RemoveRank.class, PermissionsMessage.RemoveRank::new);
    registerMessage(++idx, PermissionsMessage.EditRankType.class, PermissionsMessage.EditRankType::new);
    registerMessage(++idx, PermissionsMessage.SetSubscriber.class, PermissionsMessage.SetSubscriber::new);
    // Colony Request messages
    registerMessage(++idx, BuildRequestMessage.class, BuildRequestMessage::new);
    registerMessage(++idx, OpenInventoryMessage.class, OpenInventoryMessage::new);
    registerMessage(++idx, TownHallRenameMessage.class, TownHallRenameMessage::new);
    registerMessage(++idx, MinerSetLevelMessage.class, MinerSetLevelMessage::new);
    registerMessage(++idx, RecallCitizenMessage.class, RecallCitizenMessage::new);
    registerMessage(++idx, BuildToolPlaceMessage.class, BuildToolPlaceMessage::new);
    registerMessage(++idx, ToggleJobMessage.class, ToggleJobMessage::new);
    registerMessage(++idx, HireFireMessage.class, HireFireMessage::new);
    registerMessage(++idx, WorkOrderChangeMessage.class, WorkOrderChangeMessage::new);
    registerMessage(++idx, AssignFieldMessage.class, AssignFieldMessage::new);
    registerMessage(++idx, AssignmentModeMessage.class, AssignmentModeMessage::new);
    registerMessage(++idx, GuardSetMinePosMessage.class, GuardSetMinePosMessage::new);
    registerMessage(++idx, RecallCitizenHutMessage.class, RecallCitizenHutMessage::new);
    registerMessage(++idx, TransferItemsRequestMessage.class, TransferItemsRequestMessage::new);
    registerMessage(++idx, MarkBuildingDirtyMessage.class, MarkBuildingDirtyMessage::new);
    registerMessage(++idx, ChangeFreeToInteractBlockMessage.class, ChangeFreeToInteractBlockMessage::new);
    registerMessage(++idx, CreateColonyMessage.class, CreateColonyMessage::new);
    registerMessage(++idx, ColonyDeleteOwnMessage.class, ColonyDeleteOwnMessage::new);
    registerMessage(++idx, ColonyViewRemoveMessage.class, ColonyViewRemoveMessage::new);
    registerMessage(++idx, GiveToolMessage.class, GiveToolMessage::new);
    registerMessage(++idx, ToggleHousingMessage.class, ToggleHousingMessage::new);
    registerMessage(++idx, ToggleMoveInMessage.class, ToggleMoveInMessage::new);
    registerMessage(++idx, AssignUnassignMessage.class, AssignUnassignMessage::new);
    registerMessage(++idx, OpenCraftingGUIMessage.class, OpenCraftingGUIMessage::new);
    registerMessage(++idx, AddRemoveRecipeMessage.class, AddRemoveRecipeMessage::new);
    registerMessage(++idx, ChangeRecipePriorityMessage.class, ChangeRecipePriorityMessage::new);
    registerMessage(++idx, ChangeDeliveryPriorityMessage.class, ChangeDeliveryPriorityMessage::new);
    registerMessage(++idx, ForcePickupMessage.class, ForcePickupMessage::new);
    registerMessage(++idx, UpgradeWarehouseMessage.class, UpgradeWarehouseMessage::new);
    registerMessage(++idx, BuildToolPasteMessage.class, BuildToolPasteMessage::new);
    registerMessage(++idx, TransferItemsToCitizenRequestMessage.class, TransferItemsToCitizenRequestMessage::new);
    registerMessage(++idx, UpdateRequestStateMessage.class, UpdateRequestStateMessage::new);
    registerMessage(++idx, BuildingSetStyleMessage.class, BuildingSetStyleMessage::new);
    registerMessage(++idx, RecallSingleCitizenMessage.class, RecallSingleCitizenMessage::new);
    registerMessage(++idx, AssignFilterableItemMessage.class, AssignFilterableItemMessage::new);
    registerMessage(++idx, TeamColonyColorChangeMessage.class, TeamColonyColorChangeMessage::new);
    registerMessage(++idx, ColonyFlagChangeMessage.class, ColonyFlagChangeMessage::new);
    registerMessage(++idx, ToggleHelpMessage.class, ToggleHelpMessage::new);
    registerMessage(++idx, PauseCitizenMessage.class, PauseCitizenMessage::new);
    registerMessage(++idx, RestartCitizenMessage.class, RestartCitizenMessage::new);
    registerMessage(++idx, SortWarehouseMessage.class, SortWarehouseMessage::new);
    registerMessage(++idx, PostBoxRequestMessage.class, PostBoxRequestMessage::new);
    registerMessage(++idx, HireMercenaryMessage.class, HireMercenaryMessage::new);
    registerMessage(++idx, HutRenameMessage.class, HutRenameMessage::new);
    registerMessage(++idx, BuildingHiringModeMessage.class, BuildingHiringModeMessage::new);
    registerMessage(++idx, DecorationBuildRequestMessage.class, DecorationBuildRequestMessage::new);
    registerMessage(++idx, DecorationControllerUpdateMessage.class, DecorationControllerUpdateMessage::new);
    registerMessage(++idx, DirectPlaceMessage.class, DirectPlaceMessage::new);
    registerMessage(++idx, TeleportToColonyMessage.class, TeleportToColonyMessage::new);
    registerMessage(++idx, EnchanterWorkerSetMessage.class, EnchanterWorkerSetMessage::new);
    registerMessage(++idx, InteractionResponse.class, InteractionResponse::new);
    registerMessage(++idx, TryResearchMessage.class, TryResearchMessage::new);
    registerMessage(++idx, HireSpiesMessage.class, HireSpiesMessage::new);
    registerMessage(++idx, AddMinimumStockToBuildingModuleMessage.class, AddMinimumStockToBuildingModuleMessage::new);
    registerMessage(++idx, RemoveMinimumStockFromBuildingModuleMessage.class, RemoveMinimumStockFromBuildingModuleMessage::new);
    registerMessage(++idx, FieldPlotResizeMessage.class, FieldPlotResizeMessage::new);
    registerMessage(++idx, AdjustSkillCitizenMessage.class, AdjustSkillCitizenMessage::new);
    registerMessage(++idx, BuilderSelectWorkOrderMessage.class, BuilderSelectWorkOrderMessage::new);
    registerMessage(++idx, TriggerSettingMessage.class, TriggerSettingMessage::new);
    registerMessage(++idx, AssignFilterableEntityMessage.class, AssignFilterableEntityMessage::new);
    registerMessage(++idx, BuildPickUpMessage.class, BuildPickUpMessage::new);
    registerMessage(++idx, SwitchBuildingWithToolMessage.class, SwitchBuildingWithToolMessage::new);
    registerMessage(++idx, ColonyTextureStyleMessage.class, ColonyTextureStyleMessage::new);
    registerMessage(++idx, MinerRepairLevelMessage.class, MinerRepairLevelMessage::new);
    registerMessage(++idx, ResetFilterableItemMessage.class, ResetFilterableItemMessage::new);
    registerMessage(++idx, CourierHiringModeMessage.class, CourierHiringModeMessage::new);
    registerMessage(++idx, QuarryHiringModeMessage.class, QuarryHiringModeMessage::new);
    registerMessage(++idx, ToggleRecipeMessage.class, ToggleRecipeMessage::new);
    // Client side only
    registerMessage(++idx, BlockParticleEffectMessage.class, BlockParticleEffectMessage::new);
    registerMessage(++idx, CompostParticleMessage.class, CompostParticleMessage::new);
    registerMessage(++idx, ItemParticleEffectMessage.class, ItemParticleEffectMessage::new);
    registerMessage(++idx, LocalizedParticleEffectMessage.class, LocalizedParticleEffectMessage::new);
    registerMessage(++idx, UpdateChunkRangeCapabilityMessage.class, UpdateChunkRangeCapabilityMessage::new);
    registerMessage(++idx, OpenSuggestionWindowMessage.class, OpenSuggestionWindowMessage::new);
    registerMessage(++idx, UpdateClientWithRecipesMessage.class, UpdateClientWithRecipesMessage::new);
    registerMessage(++idx, CircleParticleEffectMessage.class, CircleParticleEffectMessage::new);
    registerMessage(++idx, StreamParticleEffectMessage.class, StreamParticleEffectMessage::new);
    registerMessage(++idx, SleepingParticleMessage.class, SleepingParticleMessage::new);
    registerMessage(++idx, VanillaParticleMessage.class, VanillaParticleMessage::new);
    registerMessage(++idx, StopMusicMessage.class, StopMusicMessage::new);
    registerMessage(++idx, PlayAudioMessage.class, PlayAudioMessage::new);
    registerMessage(++idx, PlayMusicAtPosMessage.class, PlayMusicAtPosMessage::new);
    registerMessage(++idx, ColonyVisitorViewDataMessage.class, ColonyVisitorViewDataMessage::new);
    registerMessage(++idx, SyncPathMessage.class, SyncPathMessage::new);
    registerMessage(++idx, SyncPathReachedMessage.class, SyncPathReachedMessage::new);
    // JEI Messages
    registerMessage(++idx, TransferRecipeCraftingTeachingMessage.class, TransferRecipeCraftingTeachingMessage::new);
    // Advancement Messages
    registerMessage(++idx, OpenGuiWindowTriggerMessage.class, OpenGuiWindowTriggerMessage::new);
    registerMessage(++idx, ClickGuiButtonTriggerMessage.class, ClickGuiButtonTriggerMessage::new);
    // Colony-Independent items
    registerMessage(++idx, RemoveFromRallyingListMessage.class, RemoveFromRallyingListMessage::new);
    registerMessage(++idx, ToggleBannerRallyGuardsMessage.class, ToggleBannerRallyGuardsMessage::new);
    // Research-related messages.
    registerMessage(++idx, GlobalResearchTreeMessage.class, GlobalResearchTreeMessage::new);
    // Crafter Recipe-related messages
    registerMessage(++idx, CustomRecipeManagerMessage.class, CustomRecipeManagerMessage::new);
    // Resource scroll NBT share message
    registerMessage(++idx, ResourceScrollSaveWarehouseSnapshotMessage.class, ResourceScrollSaveWarehouseSnapshotMessage::new);
}
Also used : UpgradeWarehouseMessage(com.minecolonies.coremod.network.messages.server.colony.building.warehouse.UpgradeWarehouseMessage) EnchanterWorkerSetMessage(com.minecolonies.coremod.network.messages.server.colony.building.enchanter.EnchanterWorkerSetMessage) MinerSetLevelMessage(com.minecolonies.coremod.network.messages.server.colony.building.miner.MinerSetLevelMessage) BuilderSelectWorkOrderMessage(com.minecolonies.coremod.network.messages.server.colony.building.builder.BuilderSelectWorkOrderMessage) GlobalResearchTreeMessage(com.minecolonies.coremod.research.GlobalResearchTreeMessage) AssignmentModeMessage(com.minecolonies.coremod.network.messages.server.colony.building.farmer.AssignmentModeMessage) PostBoxRequestMessage(com.minecolonies.coremod.network.messages.server.colony.building.postbox.PostBoxRequestMessage) TryResearchMessage(com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage) SortWarehouseMessage(com.minecolonies.coremod.network.messages.server.colony.building.warehouse.SortWarehouseMessage) AssignUnassignMessage(com.minecolonies.coremod.network.messages.server.colony.building.home.AssignUnassignMessage) MinerRepairLevelMessage(com.minecolonies.coremod.network.messages.server.colony.building.miner.MinerRepairLevelMessage) AssignFieldMessage(com.minecolonies.coremod.network.messages.server.colony.building.farmer.AssignFieldMessage) GuardSetMinePosMessage(com.minecolonies.coremod.network.messages.server.colony.building.guard.GuardSetMinePosMessage) CustomRecipeManagerMessage(com.minecolonies.coremod.colony.crafting.CustomRecipeManagerMessage) TargetPoint(net.minecraftforge.fml.network.PacketDistributor.TargetPoint) PermissionsMessage(com.minecolonies.coremod.network.messages.PermissionsMessage)

Example 5 with TryResearchMessage

use of com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage in project minecolonies by ldtteam.

the class WindowResearchTree method onButtonClicked.

@Override
public void onButtonClicked(@NotNull final Button button) {
    super.onButtonClicked(button);
    // closing and reopening the WindowResearchTree.
    if (button.getParent().getChildren().contains(undoButton)) {
        button.getParent().removeChild(undoButton);
    }
    for (ItemIcon icon : undoCostIcons) {
        if (button.getParent().getChildren().contains(icon)) {
            button.getParent().removeChild(icon);
        }
    }
    if (button.getParent().getChildren().contains(undoText)) {
        button.getParent().removeChild(undoText);
    }
    // May eventually want a sound handler here, but SoundUtils.playErrorSound is a bit much.
    if (button.getID().isEmpty()) {
    // intentionally empty.
    } else // Undo just the selected research.
    if (button.getID().contains("undo:")) {
        final String undoName = button.getID().substring(button.getID().indexOf(':') + 1);
        if (!ResourceLocation.isValidResourceLocation(undoName)) {
            return;
        }
        final ResourceLocation undoID = new ResourceLocation(undoName);
        final ILocalResearch cancelResearch = building.getColony().getResearchManager().getResearchTree().getResearch(branch, undoID);
        if (cancelResearch != null) {
            // Instead, offset the UniversityWindow's count by -1 before the packet could be sent.
            if (cancelResearch.getState() == ResearchState.IN_PROGRESS) {
                last.updateResearchCount(-1);
            }
            // Canceled research will eventually be removed from the local tree on synchronization from server,
            // But this can be long enough (~5 seconds) to cause confusion if the player reopens the WindowResearchTree.
            // Completely removing the research to null will allow players to unintentionally restart it.
            // While the server-side logic prevents this from taking items, it would be confusing.
            // Setting to NOT_STARTED means that it can't be sent, as only null research states
            // are eligible to send TryResearchMessages, and only IN_PROGRESS, or FINISHED
            // are eligible to drawUndo buttons.
            cancelResearch.setState(ResearchState.NOT_STARTED);
            Network.getNetwork().sendToServer(new TryResearchMessage(building, cancelResearch.getId(), cancelResearch.getBranch(), true));
            close();
        }
    } else if (ResourceLocation.isValidResourceLocation(button.getID()) && IGlobalResearchTree.getInstance().getResearch(branch, new ResourceLocation(button.getID())) != null && (building.getBuildingLevel() >= IGlobalResearchTree.getInstance().getResearch(branch, new ResourceLocation(button.getID())).getDepth() || building.getBuildingLevel() == building.getBuildingMaxLevel())) {
        final IGlobalResearch research = IGlobalResearchTree.getInstance().getResearch(branch, new ResourceLocation(button.getID()));
        final ILocalResearch localResearch = building.getColony().getResearchManager().getResearchTree().getResearch(branch, research.getId());
        if (localResearch == null && building.getBuildingLevel() > building.getColony().getResearchManager().getResearchTree().getResearchInProgress().size() && (research.hasEnoughResources(new InvWrapper(Minecraft.getInstance().player.inventory)) || (mc.player.isCreative()))) {
            // This side won't actually start research; it'll be overridden the next colony update from the server.
            // It will, however, update for the next WindowResearchTree if the colony update is slow to come back.
            // Again, the server will prevent someone from paying items twice, but this avoids some confusion.
            research.startResearch(building.getColony().getResearchManager().getResearchTree());
            // don't need to offset count here, as the startResearch will pad it until the new Colony data comes in.
            last.updateResearchCount(0);
            if (research.getDepth() > building.getBuildingMaxLevel()) {
                hasMax = true;
            }
            Network.getNetwork().sendToServer(new TryResearchMessage(building, research.getId(), research.getBranch(), false));
            close();
        } else if (localResearch != null) {
            // This still costs items, so mostly only beneficial to free up a researcher slot.
            if (localResearch.getState() == ResearchState.IN_PROGRESS) {
                drawUndoProgressButton(button);
            }
            if (localResearch.getState() == ResearchState.FINISHED) {
                // Autostart research should not allow undo of completed research as well, as it will attempt to restart it on colony reload.
                if (research.isImmutable() || research.isAutostart()) {
                    return;
                }
                // don't allow research with completed or in-progress children to be reset.  They must be reset individually.
                for (ResourceLocation childId : research.getChildren()) {
                    if (building.getColony().getResearchManager().getResearchTree().getResearch(branch, childId) != null && building.getColony().getResearchManager().getResearchTree().getResearch(branch, childId).getState() != ResearchState.NOT_STARTED) {
                        return;
                    }
                }
                // Probably not vital most of the time, but even some beneficial effects may not be desirable in all circumstances.
                if (branchType == ResearchBranchType.UNLOCKABLES) {
                    drawUndoCompleteButton(button);
                }
                // above-max-level research prohibits other options, and should be resetable.
                if (hasMax && research.getDepth() > building.getBuildingMaxLevel() && building.getBuildingLevel() == building.getBuildingMaxLevel()) {
                    drawUndoCompleteButton(button);
                    return;
                }
                // researches with an ancestor with OnlyChild status should be undoable, no children are complete or in-progress.
                ResourceLocation parentId = IGlobalResearchTree.getInstance().getResearch(branch, research.getId()).getParent();
                while (!parentId.getPath().isEmpty()) {
                    if (IGlobalResearchTree.getInstance().getResearch(branch, parentId) != null && IGlobalResearchTree.getInstance().getResearch(branch, parentId).hasOnlyChild()) {
                        drawUndoCompleteButton(button);
                        break;
                    }
                    parentId = IGlobalResearchTree.getInstance().getResearch(branch, parentId).getParent();
                }
            }
        }
    } else // Cancel the entire WindowResearchTree
    if (button.getID().equals("cancel")) {
        this.close();
        last.open();
    }
}
Also used : TryResearchMessage(com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage) ResourceLocation(net.minecraft.util.ResourceLocation) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper)

Aggregations

TryResearchMessage (com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage)6 ResearchState (com.minecolonies.api.research.util.ResearchState)2 CustomRecipeManagerMessage (com.minecolonies.coremod.colony.crafting.CustomRecipeManagerMessage)2 PermissionsMessage (com.minecolonies.coremod.network.messages.PermissionsMessage)2 BuilderSelectWorkOrderMessage (com.minecolonies.coremod.network.messages.server.colony.building.builder.BuilderSelectWorkOrderMessage)2 EnchanterWorkerSetMessage (com.minecolonies.coremod.network.messages.server.colony.building.enchanter.EnchanterWorkerSetMessage)2 AssignFieldMessage (com.minecolonies.coremod.network.messages.server.colony.building.farmer.AssignFieldMessage)2 AssignmentModeMessage (com.minecolonies.coremod.network.messages.server.colony.building.farmer.AssignmentModeMessage)2 GuardSetMinePosMessage (com.minecolonies.coremod.network.messages.server.colony.building.guard.GuardSetMinePosMessage)2 AssignUnassignMessage (com.minecolonies.coremod.network.messages.server.colony.building.home.AssignUnassignMessage)2 MinerRepairLevelMessage (com.minecolonies.coremod.network.messages.server.colony.building.miner.MinerRepairLevelMessage)2 MinerSetLevelMessage (com.minecolonies.coremod.network.messages.server.colony.building.miner.MinerSetLevelMessage)2 PostBoxRequestMessage (com.minecolonies.coremod.network.messages.server.colony.building.postbox.PostBoxRequestMessage)2 SortWarehouseMessage (com.minecolonies.coremod.network.messages.server.colony.building.warehouse.SortWarehouseMessage)2 UpgradeWarehouseMessage (com.minecolonies.coremod.network.messages.server.colony.building.warehouse.UpgradeWarehouseMessage)2 GlobalResearchTreeMessage (com.minecolonies.coremod.research.GlobalResearchTreeMessage)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 TargetPoint (net.minecraftforge.fml.network.PacketDistributor.TargetPoint)2 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)2 CrusherSetModeMessage (com.minecolonies.coremod.network.messages.server.colony.building.crusher.CrusherSetModeMessage)1