Search in sources :

Example 1 with OredictionificatorItemFilter

use of mekanism.common.content.oredictionificator.OredictionificatorItemFilter in project Mekanism by mekanism.

the class PacketEditFilter method handle.

@Override
public void handle(NetworkEvent.Context context) {
    PlayerEntity player = context.getSender();
    if (player == null) {
        return;
    }
    TileEntity tile = WorldUtils.getTileEntity(player.level, pos);
    if (tile != null) {
        if (filter instanceof SorterFilter && tile instanceof TileEntityLogisticalSorter) {
            HashList<SorterFilter<?>> filters = ((TileEntityLogisticalSorter) tile).getFilters();
            int index = filters.indexOf(filter);
            if (index != -1) {
                filters.remove(index);
                if (!delete) {
                    filters.add(index, (SorterFilter<?>) edited);
                }
            }
        } else if (filter instanceof MinerFilter && tile instanceof TileEntityDigitalMiner) {
            HashList<MinerFilter<?>> filters = ((TileEntityDigitalMiner) tile).getFilters();
            int index = filters.indexOf(filter);
            if (index != -1) {
                filters.remove(index);
                if (!delete) {
                    filters.add(index, (MinerFilter<?>) edited);
                }
            }
        } else if (filter instanceof OredictionificatorItemFilter && tile instanceof TileEntityOredictionificator) {
            HashList<OredictionificatorItemFilter> filters = ((TileEntityOredictionificator) tile).getFilters();
            int index = filters.indexOf(filter);
            if (index != -1) {
                filters.remove(index);
                if (!delete) {
                    filters.add(index, (OredictionificatorItemFilter) edited);
                }
            }
        } else if (filter instanceof QIOFilter && tile instanceof TileEntityQIOFilterHandler) {
            HashList<QIOFilter<?>> filters = ((TileEntityQIOFilterHandler) tile).getFilters();
            int index = filters.indexOf(filter);
            if (index != -1) {
                filters.remove(index);
                if (!delete) {
                    filters.add(index, (QIOFilter<?>) edited);
                }
            }
        }
        tile.setChanged();
    }
}
Also used : SorterFilter(mekanism.common.content.transporter.SorterFilter) HashList(mekanism.common.lib.collection.HashList) TileEntityLogisticalSorter(mekanism.common.tile.TileEntityLogisticalSorter) MinerFilter(mekanism.common.content.miner.MinerFilter) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TileEntityOredictionificator(mekanism.common.tile.machine.TileEntityOredictionificator) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityDigitalMiner(mekanism.common.tile.machine.TileEntityDigitalMiner) TileEntityQIOFilterHandler(mekanism.common.tile.qio.TileEntityQIOFilterHandler) QIOFilter(mekanism.common.content.qio.filter.QIOFilter) OredictionificatorItemFilter(mekanism.common.content.oredictionificator.OredictionificatorItemFilter)

Example 2 with OredictionificatorItemFilter

use of mekanism.common.content.oredictionificator.OredictionificatorItemFilter in project Mekanism by mekanism.

the class CCArgumentWrapper method convertMapToFilter.

@Nullable
private static Object convertMapToFilter(Class<?> expectedType, Map<?, ?> map) {
    // We may want to try improving this at some point, or somehow making it slightly less hardcoded
    // but for now this will have to do
    Object type = map.get("type");
    if (type instanceof String) {
        // Handle filters as arguments, this may not be the best implementation, but it will do for now
        FilterType filterType = sanitizeStringToEnum(FilterType.class, (String) type);
        if (filterType != null) {
            IFilter<?> filter = BaseFilter.fromType(filterType);
            if (expectedType.isInstance(filter)) {
                // Validate the filter is of the type we expect
                if (filter instanceof IItemStackFilter) {
                    ItemStack stack = tryCreateFilterItem(map.get("item"), map.get("itemNBT"));
                    if (stack.isEmpty()) {
                        return null;
                    }
                    ((IItemStackFilter<?>) filter).setItemStack(stack);
                } else if (filter instanceof IMaterialFilter) {
                    ItemStack stack = tryCreateFilterItem(map.get("materialItem"), null);
                    if (stack.isEmpty()) {
                        return null;
                    }
                    ((IMaterialFilter<?>) filter).setMaterialItem(stack);
                } else if (filter instanceof IModIDFilter) {
                    String modId = tryGetFilterModId(map.get("modId"));
                    if (modId == null) {
                        return null;
                    }
                    ((IModIDFilter<?>) filter).setModID(modId);
                } else if (filter instanceof ITagFilter) {
                    String tag = tryGetFilterTag(map.get("tag"));
                    if (tag == null) {
                        return null;
                    }
                    ((ITagFilter<?>) filter).setTagName(tag);
                }
                if (filter instanceof MinerFilter) {
                    MinerFilter<?> minerFilter = (MinerFilter<?>) filter;
                    minerFilter.requiresReplacement = getBooleanFromRaw(map.get("requiresReplacement"));
                    minerFilter.replaceTarget = tryCreateItem(map.get("replaceTarget"));
                } else if (filter instanceof SorterFilter) {
                    SorterFilter<?> sorterFilter = (SorterFilter<?>) filter;
                    sorterFilter.allowDefault = getBooleanFromRaw(map.get("allowDefault"));
                    Object rawColor = map.get("color");
                    if (rawColor instanceof String) {
                        sorterFilter.color = sanitizeStringToEnum(EnumColor.class, (String) rawColor);
                    }
                    sorterFilter.sizeMode = getBooleanFromRaw(map.get("size"));
                    sorterFilter.min = getIntFromRaw(map.get("min"));
                    sorterFilter.max = getIntFromRaw(map.get("max"));
                    if (sorterFilter.min < 0 || sorterFilter.max < 0 || sorterFilter.min > sorterFilter.max || sorterFilter.max > 64) {
                        return null;
                    }
                    if (sorterFilter instanceof SorterItemStackFilter) {
                        SorterItemStackFilter sorterItemFilter = (SorterItemStackFilter) sorterFilter;
                        sorterItemFilter.fuzzyMode = getBooleanFromRaw(map.get("fuzzy"));
                    }
                } else if (filter instanceof QIOFilter) {
                    QIOFilter<?> qioFilter = (QIOFilter<?>) filter;
                    if (qioFilter instanceof QIOItemStackFilter) {
                        QIOItemStackFilter qioItemFilter = (QIOItemStackFilter) qioFilter;
                        qioItemFilter.fuzzyMode = getBooleanFromRaw(map.get("fuzzy"));
                    }
                } else if (filter instanceof OredictionificatorFilter) {
                    OredictionificatorFilter<?, ?, ?> oredictionificatorFilter = (OredictionificatorFilter<?, ?, ?>) filter;
                    Object rawTag = map.get("target");
                    if (!(rawTag instanceof String)) {
                        return null;
                    }
                    String tag = (String) rawTag;
                    if (tag.isEmpty()) {
                        return null;
                    }
                    ResourceLocation rl = ResourceLocation.tryParse(tag);
                    if (rl == null || !TileEntityOredictionificator.isValidTarget(rl)) {
                        return null;
                    }
                    oredictionificatorFilter.setFilter(rl);
                    if (oredictionificatorFilter instanceof OredictionificatorItemFilter) {
                        Item item = tryCreateItem(map.get("selected"));
                        if (item != Items.AIR) {
                            ((OredictionificatorItemFilter) oredictionificatorFilter).setSelectedOutput(item);
                        }
                    }
                }
                return filter;
            }
        }
    }
    return null;
}
Also used : SorterFilter(mekanism.common.content.transporter.SorterFilter) IMaterialFilter(mekanism.common.content.filter.IMaterialFilter) MinerFilter(mekanism.common.content.miner.MinerFilter) QIOItemStackFilter(mekanism.common.content.qio.filter.QIOItemStackFilter) ITagFilter(mekanism.common.content.filter.ITagFilter) Item(net.minecraft.item.Item) FilterType(mekanism.common.content.filter.FilterType) IItemStackFilter(mekanism.common.content.filter.IItemStackFilter) SorterItemStackFilter(mekanism.common.content.transporter.SorterItemStackFilter) ResourceLocation(net.minecraft.util.ResourceLocation) QIOFilter(mekanism.common.content.qio.filter.QIOFilter) OredictionificatorFilter(mekanism.common.content.oredictionificator.OredictionificatorFilter) ItemStack(net.minecraft.item.ItemStack) IModIDFilter(mekanism.common.content.filter.IModIDFilter) OredictionificatorItemFilter(mekanism.common.content.oredictionificator.OredictionificatorItemFilter) Nullable(javax.annotation.Nullable)

Example 3 with OredictionificatorItemFilter

use of mekanism.common.content.oredictionificator.OredictionificatorItemFilter in project Mekanism by mekanism.

the class GuiOredictionificator method addGuiElements.

@Override
protected void addGuiElements() {
    super.addGuiElements();
    // Filter holder
    addButton(new GuiElementHolder(this, 9, 17, 144, 68));
    // new filter button border
    addButton(new GuiElementHolder(this, 9, 85, 144, 22));
    scrollBar = addButton(new GuiScrollBar(this, 153, 17, 90, () -> tile.getFilters().size(), () -> FILTER_COUNT));
    addButton(new GuiProgress(() -> tile.didProcess, ProgressType.LARGE_RIGHT, this, 64, 119));
    addButton(new TranslationButton(this, 10, 86, 142, 20, MekanismLang.BUTTON_NEW_FILTER, () -> addWindow(GuiOredictionificatorFilter.create(this, tile))));
    // Add each of the buttons and then just change visibility state to match filter info
    for (int i = 0; i < FILTER_COUNT; i++) {
        addButton(new FilterButton(this, 10, 18 + i * 22, 142, 22, i, scrollBar::getCurrentSelection, tile::getFilters, this::onClick, filter -> {
            if (filter instanceof OredictionificatorItemFilter) {
                return Collections.singletonList(((OredictionificatorItemFilter) filter).getResult());
            }
            return Collections.emptyList();
        })).warning(WarningType.INVALID_OREDICTIONIFICATOR_FILTER, filter -> filter != null && !filter.hasFilter());
    }
    // While we track and show warnings on the slots themselves we also need to track the warning
    // for if any of the set filters have it even if one of them is not visible
    // Note: We add this after all the buttons have their warnings added so that it is further down the tracker
    // so the tracker can short circuit on this type of warning and not have to check all the filters if one of
    // the ones that are currently being shown has the warning
    trackWarning(WarningType.INVALID_OREDICTIONIFICATOR_FILTER, () -> tile.getFilters().stream().anyMatch(filter -> !filter.hasFilter()));
}
Also used : TranslationButton(mekanism.client.gui.element.button.TranslationButton) GuiOredictionificatorFilter(mekanism.client.gui.element.window.filter.GuiOredictionificatorFilter) GuiProgress(mekanism.client.gui.element.progress.GuiProgress) PlayerInventory(net.minecraft.entity.player.PlayerInventory) GuiElementHolder(mekanism.client.gui.element.GuiElementHolder) FilterButton(mekanism.client.gui.element.button.FilterButton) GuiConfigurableTile(mekanism.client.gui.GuiConfigurableTile) ITextComponent(net.minecraft.util.text.ITextComponent) WarningType(mekanism.client.gui.warning.WarningTracker.WarningType) OredictionificatorItemFilter(mekanism.common.content.oredictionificator.OredictionificatorItemFilter) ProgressType(mekanism.client.gui.element.progress.ProgressType) TileEntityOredictionificator(mekanism.common.tile.machine.TileEntityOredictionificator) MekanismTileContainer(mekanism.common.inventory.container.tile.MekanismTileContainer) MekanismLang(mekanism.common.MekanismLang) GuiScrollBar(mekanism.client.gui.element.scroll.GuiScrollBar) IFilter(mekanism.common.content.filter.IFilter) Collections(java.util.Collections) Nonnull(javax.annotation.Nonnull) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) TranslationButton(mekanism.client.gui.element.button.TranslationButton) GuiProgress(mekanism.client.gui.element.progress.GuiProgress) GuiElementHolder(mekanism.client.gui.element.GuiElementHolder) FilterButton(mekanism.client.gui.element.button.FilterButton) GuiScrollBar(mekanism.client.gui.element.scroll.GuiScrollBar) OredictionificatorItemFilter(mekanism.common.content.oredictionificator.OredictionificatorItemFilter)

Aggregations

OredictionificatorItemFilter (mekanism.common.content.oredictionificator.OredictionificatorItemFilter)3 MinerFilter (mekanism.common.content.miner.MinerFilter)2 QIOFilter (mekanism.common.content.qio.filter.QIOFilter)2 SorterFilter (mekanism.common.content.transporter.SorterFilter)2 TileEntityOredictionificator (mekanism.common.tile.machine.TileEntityOredictionificator)2 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 Collections (java.util.Collections)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 GuiConfigurableTile (mekanism.client.gui.GuiConfigurableTile)1 GuiElementHolder (mekanism.client.gui.element.GuiElementHolder)1 FilterButton (mekanism.client.gui.element.button.FilterButton)1 TranslationButton (mekanism.client.gui.element.button.TranslationButton)1 GuiProgress (mekanism.client.gui.element.progress.GuiProgress)1 ProgressType (mekanism.client.gui.element.progress.ProgressType)1 GuiScrollBar (mekanism.client.gui.element.scroll.GuiScrollBar)1 GuiOredictionificatorFilter (mekanism.client.gui.element.window.filter.GuiOredictionificatorFilter)1 WarningType (mekanism.client.gui.warning.WarningTracker.WarningType)1 MekanismLang (mekanism.common.MekanismLang)1 FilterType (mekanism.common.content.filter.FilterType)1