Search in sources :

Example 1 with EnumAssemblyRecipeState

use of buildcraft.silicon.EnumAssemblyRecipeState in project BuildCraft by BuildCraft.

the class TileAssemblyTable method activateNextRecipe.

private void activateNextRecipe() {
    AssemblyInstruction activeRecipe = getActiveRecipe();
    if (activeRecipe != null) {
        int index = 0;
        int activeIndex = 0;
        boolean isActiveLast = false;
        long enoughCount = recipesStates.values().stream().filter(state -> state == EnumAssemblyRecipeState.SAVED_ENOUGH || state == EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE).count();
        if (enoughCount <= 1) {
            return;
        }
        for (Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState> entry : recipesStates.entrySet()) {
            EnumAssemblyRecipeState state = entry.getValue();
            if (state == EnumAssemblyRecipeState.SAVED_ENOUGH) {
                isActiveLast = false;
            }
            if (state == EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE) {
                state = EnumAssemblyRecipeState.SAVED_ENOUGH;
                entry.setValue(state);
                activeIndex = index;
                isActiveLast = true;
            }
            index++;
        }
        index = 0;
        for (Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState> entry : recipesStates.entrySet()) {
            AssemblyRecipe recipe = entry.getKey().recipe;
            EnumAssemblyRecipeState state = entry.getValue();
            if (state == EnumAssemblyRecipeState.SAVED_ENOUGH && recipe != activeRecipe.recipe && (index > activeIndex || isActiveLast)) {
                state = EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE;
                entry.setValue(state);
                break;
            }
            index++;
        }
    }
}
Also used : EnumAssemblyRecipeState(buildcraft.silicon.EnumAssemblyRecipeState) AssemblyRecipe(buildcraft.api.recipes.AssemblyRecipe) Constants(net.minecraftforge.common.util.Constants) IMessage(net.minecraftforge.fml.common.network.simpleimpl.IMessage) ItemHandlerSimple(buildcraft.lib.tile.item.ItemHandlerSimple) ItemStack(net.minecraft.item.ItemStack) NBTTagList(net.minecraft.nbt.NBTTagList) Side(net.minecraftforge.fml.relauncher.Side) Map(java.util.Map) MessageManager(buildcraft.lib.net.MessageManager) Nullable(javax.annotation.Nullable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) InventoryUtil(buildcraft.lib.misc.InventoryUtil) PacketBufferBC(buildcraft.lib.net.PacketBufferBC) Iterator(java.util.Iterator) IdAllocator(buildcraft.lib.misc.data.IdAllocator) ItemHandlerManager(buildcraft.lib.tile.item.ItemHandlerManager) Set(java.util.Set) EnumFacing(net.minecraft.util.EnumFacing) TileBC_Neptune(buildcraft.lib.tile.TileBC_Neptune) IOException(java.io.IOException) LocaleUtil(buildcraft.lib.misc.LocaleUtil) List(java.util.List) TreeMap(java.util.TreeMap) MessageContext(net.minecraftforge.fml.common.network.simpleimpl.MessageContext) AssemblyRecipeRegistry(buildcraft.lib.recipe.AssemblyRecipeRegistry) ResourceLocation(net.minecraft.util.ResourceLocation) Optional(java.util.Optional) SortedMap(java.util.SortedMap) AdvancementUtil(buildcraft.lib.misc.AdvancementUtil) EnumPipePart(buildcraft.api.core.EnumPipePart) AssemblyRecipe(buildcraft.api.recipes.AssemblyRecipe) EnumAssemblyRecipeState(buildcraft.silicon.EnumAssemblyRecipeState) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 2 with EnumAssemblyRecipeState

use of buildcraft.silicon.EnumAssemblyRecipeState in project BuildCraft by BuildCraft.

the class TileAssemblyTable method readPayload.

@Override
public void readPayload(int id, PacketBufferBC buffer, Side side, MessageContext ctx) throws IOException {
    super.readPayload(id, buffer, side, ctx);
    if (id == NET_GUI_DATA) {
        recipesStates.clear();
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            AssemblyInstruction instruction = lookupRecipe(buffer.readString(), buffer.readItemStack());
            recipesStates.put(instruction, EnumAssemblyRecipeState.values()[buffer.readInt()]);
        }
    }
    if (id == NET_RECIPE_STATE) {
        AssemblyInstruction recipe = lookupRecipe(buffer.readString(), buffer.readItemStack());
        EnumAssemblyRecipeState state = EnumAssemblyRecipeState.values()[buffer.readInt()];
        if (recipesStates.containsKey(recipe)) {
            recipesStates.put(recipe, state);
        }
    }
}
Also used : EnumAssemblyRecipeState(buildcraft.silicon.EnumAssemblyRecipeState)

Example 3 with EnumAssemblyRecipeState

use of buildcraft.silicon.EnumAssemblyRecipeState in project BuildCraft by BuildCraft.

the class GuiAssemblyTable method drawBackgroundLayer.

@Override
protected void drawBackgroundLayer(float partialTicks) {
    ICON_GUI.drawAt(mainGui.rootElement);
    long target = container.tile.getTarget();
    if (target != 0) {
        double v = (double) container.tile.power / target;
        ICON_PROGRESS.drawCutInside(new GuiRectangle(RECT_PROGRESS.x, (int) (RECT_PROGRESS.y + RECT_PROGRESS.height * Math.max(1 - v, 0)), RECT_PROGRESS.width, (int) Math.ceil(RECT_PROGRESS.height * Math.min(v, 1))).offset(mainGui.rootElement));
    }
    for (int i = 0; i < container.tile.recipesStates.size(); i++) {
        EnumAssemblyRecipeState state = new ArrayList<>(container.tile.recipesStates.values()).get(i);
        if (state == EnumAssemblyRecipeState.SAVED) {
            ICON_SAVED.drawAt(getArea(i));
        }
        if (state == EnumAssemblyRecipeState.SAVED_ENOUGH) {
            ICON_SAVED_ENOUGH.drawAt(getArea(i));
        }
        if (state == EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE) {
            ICON_SAVED_ENOUGH_ACTIVE.drawAt(getArea(i));
        }
    }
}
Also used : GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) EnumAssemblyRecipeState(buildcraft.silicon.EnumAssemblyRecipeState)

Example 4 with EnumAssemblyRecipeState

use of buildcraft.silicon.EnumAssemblyRecipeState in project BuildCraft by BuildCraft.

the class TileAssemblyTable method updateRecipes.

private void updateRecipes() {
    // TODO: rework this to not iterate over every recipe every tick
    int count = recipesStates.size();
    for (AssemblyRecipe recipe : AssemblyRecipeRegistry.REGISTRY.values()) {
        Set<ItemStack> outputs = recipe.getOutputs(inv.stacks);
        for (ItemStack out : outputs) {
            boolean found = false;
            for (AssemblyInstruction instruction : recipesStates.keySet()) {
                if (instruction.recipe == recipe && out == instruction.output) {
                    found = true;
                    break;
                }
            }
            AssemblyInstruction instruction = new AssemblyInstruction(recipe, out);
            if (!found && !recipesStates.containsKey(instruction)) {
                recipesStates.put(instruction, EnumAssemblyRecipeState.POSSIBLE);
            }
        }
    }
    boolean findActive = false;
    for (Iterator<Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState>> iterator = recipesStates.entrySet().iterator(); iterator.hasNext(); ) {
        Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState> entry = iterator.next();
        AssemblyInstruction instruction = entry.getKey();
        EnumAssemblyRecipeState state = entry.getValue();
        boolean enough = extract(inv, instruction.recipe.getInputsFor(instruction.output), true, false);
        if (state == EnumAssemblyRecipeState.POSSIBLE) {
            if (!enough) {
                iterator.remove();
            }
        } else {
            if (enough) {
                if (state == EnumAssemblyRecipeState.SAVED) {
                    state = EnumAssemblyRecipeState.SAVED_ENOUGH;
                }
            } else {
                if (state != EnumAssemblyRecipeState.SAVED) {
                    state = EnumAssemblyRecipeState.SAVED;
                }
            }
        }
        if (state == EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE) {
            findActive = true;
        }
        entry.setValue(state);
    }
    if (!findActive) {
        for (Map.Entry<AssemblyInstruction, EnumAssemblyRecipeState> entry : recipesStates.entrySet()) {
            EnumAssemblyRecipeState state = entry.getValue();
            if (state == EnumAssemblyRecipeState.SAVED_ENOUGH) {
                state = EnumAssemblyRecipeState.SAVED_ENOUGH_ACTIVE;
                entry.setValue(state);
                break;
            }
        }
    }
    if (count != recipesStates.size()) {
        sendNetworkGuiUpdate(NET_GUI_DATA);
    }
}
Also used : AssemblyRecipe(buildcraft.api.recipes.AssemblyRecipe) EnumAssemblyRecipeState(buildcraft.silicon.EnumAssemblyRecipeState) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 5 with EnumAssemblyRecipeState

use of buildcraft.silicon.EnumAssemblyRecipeState in project BuildCraft by BuildCraft.

the class GuiAssemblyTable method mouseClicked.

@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
    super.mouseClicked(mouseX, mouseY, mouseButton);
    if (mouseButton == 0) {
        for (int i = 0; i < container.tile.recipesStates.size(); i++) {
            TileAssemblyTable.AssemblyInstruction instruction = new ArrayList<>(container.tile.recipesStates.keySet()).get(i);
            EnumAssemblyRecipeState state = new ArrayList<>(container.tile.recipesStates.values()).get(i);
            if (getArea(i).contains(mouseX, mouseY)) {
                container.tile.sendRecipeStateToServer(instruction, state == EnumAssemblyRecipeState.POSSIBLE ? EnumAssemblyRecipeState.SAVED : EnumAssemblyRecipeState.POSSIBLE);
            }
        }
    }
}
Also used : TileAssemblyTable(buildcraft.silicon.tile.TileAssemblyTable) EnumAssemblyRecipeState(buildcraft.silicon.EnumAssemblyRecipeState)

Aggregations

EnumAssemblyRecipeState (buildcraft.silicon.EnumAssemblyRecipeState)5 AssemblyRecipe (buildcraft.api.recipes.AssemblyRecipe)2 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 ItemStack (net.minecraft.item.ItemStack)2 EnumPipePart (buildcraft.api.core.EnumPipePart)1 GuiRectangle (buildcraft.lib.gui.pos.GuiRectangle)1 AdvancementUtil (buildcraft.lib.misc.AdvancementUtil)1 InventoryUtil (buildcraft.lib.misc.InventoryUtil)1 LocaleUtil (buildcraft.lib.misc.LocaleUtil)1 IdAllocator (buildcraft.lib.misc.data.IdAllocator)1 MessageManager (buildcraft.lib.net.MessageManager)1 PacketBufferBC (buildcraft.lib.net.PacketBufferBC)1 AssemblyRecipeRegistry (buildcraft.lib.recipe.AssemblyRecipeRegistry)1 TileBC_Neptune (buildcraft.lib.tile.TileBC_Neptune)1 ItemHandlerManager (buildcraft.lib.tile.item.ItemHandlerManager)1 ItemHandlerSimple (buildcraft.lib.tile.item.ItemHandlerSimple)1 TileAssemblyTable (buildcraft.silicon.tile.TileAssemblyTable)1 IOException (java.io.IOException)1