Search in sources :

Example 1 with LumberjackSaplingSelectorMessage

use of com.minecolonies.coremod.network.messages.LumberjackSaplingSelectorMessage in project minecolonies by Minecolonies.

the class WindowHutLumberjack method onButtonClicked.

@Override
public void onButtonClicked(@NotNull final Button button) {
    if (button.getID().equals(BUTTON_CURRENT_SAPLING)) {
        final int row = saplingsList.getListElementIndexByPane(button);
        final ItemStorage saplingStack = treesToFell.keySet().toArray(new ItemStorage[treesToFell.size()])[row];
        final boolean shouldCut = !treesToFell.get(saplingStack);
        treesToFell.put(saplingStack, shouldCut);
        MineColonies.getNetwork().sendToServer(new LumberjackSaplingSelectorMessage(building, saplingStack.getItemStack(), shouldCut));
        this.ownBuilding.treesToFell.clear();
        this.ownBuilding.treesToFell.putAll(treesToFell);
    } else if (button.getID().equals(BUTTON_TOGGLE_ALL)) {
        final boolean on = button.getLabel().equals(LanguageHandler.format(TOGGLE_ALL_OPTIONS_ON));
        if (on) {
            button.setLabel(LanguageHandler.format(TOGGLE_ALL_OPTIONS_OFF));
        } else {
            button.setLabel(LanguageHandler.format(TOGGLE_ALL_OPTIONS_ON));
        }
        for (final Map.Entry<ItemStorage, Boolean> entry : new HashSet<Map.Entry<ItemStorage, Boolean>>(treesToFell.entrySet())) {
            treesToFell.put(entry.getKey(), on);
        }
        this.ownBuilding.treesToFell.clear();
        this.ownBuilding.treesToFell.putAll(treesToFell);
    } else {
        super.onButtonClicked(button);
    }
}
Also used : LumberjackSaplingSelectorMessage(com.minecolonies.coremod.network.messages.LumberjackSaplingSelectorMessage) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Aggregations

ItemStorage (com.minecolonies.api.crafting.ItemStorage)1 LumberjackSaplingSelectorMessage (com.minecolonies.coremod.network.messages.LumberjackSaplingSelectorMessage)1