Search in sources :

Example 1 with FrequencyIdentity

use of mekanism.common.lib.frequency.Frequency.FrequencyIdentity in project Mekanism by mekanism.

the class IFrequencyItem method getFrequency.

@Nullable
default Frequency getFrequency(ItemStack stack) {
    if (hasFrequency(stack)) {
        CompoundNBT frequencyCompound = ItemDataUtils.getCompound(stack, NBTConstants.FREQUENCY);
        FrequencyIdentity identity = FrequencyIdentity.load(getFrequencyType(), frequencyCompound);
        if (identity != null) {
            UUID owner;
            if (frequencyCompound.hasUUID(NBTConstants.OWNER_UUID)) {
                // TODO - 1.18: Require the compound to actually have an owner uuid stored as well
                // having a fallback to the tile's owner is mostly for properly loading legacy data
                owner = frequencyCompound.getUUID(NBTConstants.OWNER_UUID);
            } else {
                owner = getOwnerUUID(stack);
                if (owner == null) {
                    return null;
                }
            }
            return getFrequencyType().getManager(identity, owner).getFrequency(identity.getKey());
        }
    }
    return null;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) FrequencyIdentity(mekanism.common.lib.frequency.Frequency.FrequencyIdentity) UUID(java.util.UUID) Nullable(javax.annotation.Nullable)

Example 2 with FrequencyIdentity

use of mekanism.common.lib.frequency.Frequency.FrequencyIdentity in project Mekanism by mekanism.

the class GuiQIOItemViewer method addGuiElements.

@Override
protected void addGuiElements() {
    super.addGuiElements();
    int slotsY = MekanismConfig.client.qioItemViewerSlotsY.get();
    getMinecraft().keyboardHandler.setSendRepeatsToGui(true);
    addButton(new GuiInnerScreen(this, 7, 15, imageWidth - 16, 12, () -> {
        List<ITextComponent> list = new ArrayList<>();
        FrequencyIdentity freq = getFrequency();
        if (freq == null) {
            list.add(MekanismLang.NO_FREQUENCY.translate());
        } else {
            list.add(MekanismLang.FREQUENCY.translate(freq.getKey()));
        }
        return list;
    }).tooltip(() -> {
        List<ITextComponent> list = new ArrayList<>();
        if (getFrequency() != null) {
            list.add(MekanismLang.QIO_ITEMS_DETAIL.translateColored(EnumColor.GRAY, EnumColor.INDIGO, TextUtils.format(menu.getTotalItems()), TextUtils.format(menu.getCountCapacity())));
            list.add(MekanismLang.QIO_TYPES_DETAIL.translateColored(EnumColor.GRAY, EnumColor.INDIGO, TextUtils.format(menu.getTotalTypes()), TextUtils.format(menu.getTypeCapacity())));
        }
        return list;
    }));
    searchField = addButton(new GuiTextField(this, 50, 15 + 12 + 3, imageWidth - 50 - 10, 10));
    searchField.setOffset(0, -1);
    searchField.setInputValidator(this::isValidSearchChar);
    searchField.setResponder(menu::updateSearch);
    searchField.setMaxStringLength(50);
    searchField.setBackground(BackgroundType.ELEMENT_HOLDER);
    searchField.setVisible(true);
    searchField.setTextColor(0xFFFFFF);
    searchField.setFocused(true);
    addButton(new GuiSlotScroll(this, 7, QIOItemViewerContainer.SLOTS_START_Y, MekanismConfig.client.qioItemViewerSlotsX.get(), slotsY, menu::getQIOItemList, menu));
    addButton(new GuiDropdown<>(this, imageWidth - 9 - 54, QIOItemViewerContainer.SLOTS_START_Y + slotsY * 18 + 1, 41, ListSortType.class, menu::getSortType, menu::setSortType));
    addButton(new GuiDigitalIconToggle<>(this, imageWidth - 9 - 12, QIOItemViewerContainer.SLOTS_START_Y + slotsY * 18 + 1, 12, 12, SortDirection.class, menu::getSortDirection, menu::setSortDirection));
    addButton(new GuiResizeControls(this, (getMinecraft().getWindow().getGuiScaledHeight() / 2) - 20 - topPos, this::resize));
    craftingWindowTab = addButton(new GuiCraftingWindowTab(this, () -> craftingWindowTab, menu));
}
Also used : ListSortType(mekanism.common.inventory.container.QIOItemViewerContainer.ListSortType) GuiSlotScroll(mekanism.client.gui.element.scroll.GuiSlotScroll) FrequencyIdentity(mekanism.common.lib.frequency.Frequency.FrequencyIdentity) ITextComponent(net.minecraft.util.text.ITextComponent) ArrayList(java.util.ArrayList) GuiTextField(mekanism.client.gui.element.text.GuiTextField) GuiResizeControls(mekanism.client.gui.element.custom.GuiResizeControls) GuiInnerScreen(mekanism.client.gui.element.GuiInnerScreen) SortDirection(mekanism.common.inventory.container.QIOItemViewerContainer.SortDirection) ArrayList(java.util.ArrayList) List(java.util.List) GuiCraftingWindowTab(mekanism.client.gui.element.tab.window.GuiCraftingWindowTab)

Example 3 with FrequencyIdentity

use of mekanism.common.lib.frequency.Frequency.FrequencyIdentity in project Mekanism by mekanism.

the class CCArgumentWrapper method wrapReturnType.

private static Object wrapReturnType(Object result) {
    if (result == null || result instanceof Number || result instanceof Boolean || result instanceof String) {
        // Short circuit if it doesn't need wrapping
        return result;
    } else if (result instanceof ResourceLocation || result instanceof UUID) {
        return result.toString();
    } else if (result instanceof ForgeRegistryEntry<?>) {
        return getName((ForgeRegistryEntry<?>) result);
    } else if (result instanceof ChemicalStack<?>) {
        ChemicalStack<?> stack = (ChemicalStack<?>) result;
        Map<String, Object> wrapped = new HashMap<>(2);
        wrapped.put("name", getName(stack.getType()));
        wrapped.put("amount", stack.getAmount());
        return wrapped;
    } else if (result instanceof FluidStack) {
        FluidStack stack = (FluidStack) result;
        return wrapStack(stack.getFluid(), "amount", stack.getAmount(), stack.getTag());
    } else if (result instanceof ItemStack) {
        ItemStack stack = (ItemStack) result;
        return wrapStack(stack.getItem(), "count", stack.getCount(), stack.getTag());
    } else if (result instanceof INBT) {
        Object wrapped = wrapNBT((INBT) result);
        if (wrapped != null) {
            return wrapped;
        }
    } else if (result instanceof Vector3i) {
        // BlockPos is covered by this case
        Vector3i pos = (Vector3i) result;
        Map<String, Object> wrapped = new HashMap<>(3);
        wrapped.put("x", pos.getX());
        wrapped.put("y", pos.getY());
        wrapped.put("z", pos.getZ());
        return wrapped;
    } else if (result instanceof Coord4D) {
        // BlockPos is covered by this case
        Coord4D coord = (Coord4D) result;
        Map<String, Object> wrapped = new HashMap<>(4);
        wrapped.put("x", coord.getX());
        wrapped.put("y", coord.getY());
        wrapped.put("z", coord.getZ());
        wrapped.put("dimension", wrapReturnType(coord.dimension.location()));
        return wrapped;
    } else if (result instanceof Frequency) {
        FrequencyIdentity identity = ((Frequency) result).getIdentity();
        Map<String, Object> wrapped = new HashMap<>(2);
        wrapped.put("key", wrapReturnType(identity.getKey()));
        wrapped.put("public", identity.isPublic());
        return wrapped;
    } else if (result instanceof Enum) {
        return ((Enum<?>) result).name();
    } else if (result instanceof IFilter) {
        Map<String, Object> wrapped = new HashMap<>();
        wrapped.put("type", wrapReturnType(((IFilter<?>) result).getFilterType()));
        if (result instanceof IItemStackFilter) {
            ItemStack stack = ((IItemStackFilter<?>) result).getItemStack();
            wrapped.put("item", wrapReturnType(stack.getItem()));
            if (!stack.isEmpty()) {
                CompoundNBT tag = stack.getTag();
                if (tag != null && !tag.isEmpty()) {
                    wrapped.put("itemNBT", wrapNBT(tag));
                }
            }
        } else if (result instanceof IMaterialFilter) {
            wrapped.put("materialItem", wrapReturnType(((IMaterialFilter<?>) result).getMaterialItem().getItem()));
        } else if (result instanceof IModIDFilter) {
            wrapped.put("modId", ((IModIDFilter<?>) result).getModID());
        } else if (result instanceof ITagFilter) {
            wrapped.put("tag", ((ITagFilter<?>) result).getTagName());
        }
        if (result instanceof MinerFilter) {
            MinerFilter<?> minerFilter = (MinerFilter<?>) result;
            wrapped.put("requiresReplacement", minerFilter.requiresReplacement);
            wrapped.put("replaceTarget", wrapReturnType(minerFilter.replaceTarget));
        } else if (result instanceof SorterFilter) {
            SorterFilter<?> sorterFilter = (SorterFilter<?>) result;
            wrapped.put("allowDefault", sorterFilter.allowDefault);
            wrapped.put("color", wrapReturnType(sorterFilter.color));
            wrapped.put("size", sorterFilter.sizeMode);
            wrapped.put("min", sorterFilter.min);
            wrapped.put("max", sorterFilter.max);
            if (sorterFilter instanceof SorterItemStackFilter) {
                SorterItemStackFilter filter = (SorterItemStackFilter) sorterFilter;
                wrapped.put("fuzzy", filter.fuzzyMode);
            }
        } else if (result instanceof QIOFilter) {
            QIOFilter<?> qioFilter = (QIOFilter<?>) result;
            if (qioFilter instanceof QIOItemStackFilter) {
                QIOItemStackFilter filter = (QIOItemStackFilter) qioFilter;
                wrapped.put("fuzzy", filter.fuzzyMode);
            }
        } else if (result instanceof OredictionificatorFilter) {
            OredictionificatorFilter<?, ?, ?> filter = (OredictionificatorFilter<?, ?, ?>) result;
            wrapped.put("target", filter.getFilterText());
            wrapped.put("selected", wrapReturnType(filter.getResultElement()));
        }
        return wrapped;
    } else if (result instanceof Map) {
        return ((Map<?, ?>) result).entrySet().stream().collect(Collectors.toMap(entry -> wrapReturnType(entry.getKey()), entry -> wrapReturnType(entry.getValue()), (a, b) -> b));
    } else if (result instanceof Collection) {
        // so there is no real difference at that point about the type it is
        return ((Collection<?>) result).stream().map(CCArgumentWrapper::wrapReturnType).collect(Collectors.toList());
    } else if (result instanceof Object[]) {
        // Note: This doesn't handle/deal with primitive arrays
        return Arrays.stream((Object[]) result).map(CCArgumentWrapper::wrapReturnType).toArray();
    }
    return result;
}
Also used : SorterFilter(mekanism.common.content.transporter.SorterFilter) Arrays(java.util.Arrays) OredictionificatorFilter(mekanism.common.content.oredictionificator.OredictionificatorFilter) ByteArrayNBT(net.minecraft.nbt.ByteArrayNBT) ChemicalStack(mekanism.api.chemical.ChemicalStack) Item(net.minecraft.item.Item) BiFunction(java.util.function.BiFunction) Constants(net.minecraftforge.common.util.Constants) Frequency(mekanism.common.lib.frequency.Frequency) CompoundNBT(net.minecraft.nbt.CompoundNBT) FloatNBT(net.minecraft.nbt.FloatNBT) QIOItemStackFilter(mekanism.common.content.qio.filter.QIOItemStackFilter) InputValidator(mekanism.common.util.text.InputValidator) IArguments(dan200.computercraft.api.lua.IArguments) TileEntityOredictionificator(mekanism.common.tile.machine.TileEntityOredictionificator) Locale(java.util.Locale) Map(java.util.Map) QIOFilter(mekanism.common.content.qio.filter.QIOFilter) SorterFilter(mekanism.common.content.transporter.SorterFilter) ByteNBT(net.minecraft.nbt.ByteNBT) ListNBT(net.minecraft.nbt.ListNBT) ForgeRegistryEntry(net.minecraftforge.registries.ForgeRegistryEntry) FilterType(mekanism.common.content.filter.FilterType) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ITagFilter(mekanism.common.content.filter.ITagFilter) IntNBT(net.minecraft.nbt.IntNBT) BaseFilter(mekanism.common.content.filter.BaseFilter) IModIDFilter(mekanism.common.content.filter.IModIDFilter) Optional(java.util.Optional) Vector3i(net.minecraft.util.math.vector.Vector3i) FluidStack(net.minecraftforge.fluids.FluidStack) IFilter(mekanism.common.content.filter.IFilter) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) IntStream(java.util.stream.IntStream) MethodResult(dan200.computercraft.api.lua.MethodResult) EnumColor(mekanism.api.text.EnumColor) LuaException(dan200.computercraft.api.lua.LuaException) ComputerArgumentHandler(mekanism.common.integration.computer.ComputerArgumentHandler) HashMap(java.util.HashMap) OredictionificatorItemFilter(mekanism.common.content.oredictionificator.OredictionificatorItemFilter) ItemStack(net.minecraft.item.ItemStack) FloatingLong(mekanism.api.math.FloatingLong) BiConsumer(java.util.function.BiConsumer) NumberNBT(net.minecraft.nbt.NumberNBT) Nullable(javax.annotation.Nullable) INBT(net.minecraft.nbt.INBT) LongArrayNBT(net.minecraft.nbt.LongArrayNBT) StringNBT(net.minecraft.nbt.StringNBT) EndNBT(net.minecraft.nbt.EndNBT) DoubleNBT(net.minecraft.nbt.DoubleNBT) VisibleForTesting(org.jetbrains.annotations.VisibleForTesting) IMaterialFilter(mekanism.common.content.filter.IMaterialFilter) CollectionNBT(net.minecraft.nbt.CollectionNBT) ShortNBT(net.minecraft.nbt.ShortNBT) MinerFilter(mekanism.common.content.miner.MinerFilter) Items(net.minecraft.item.Items) IntArrayNBT(net.minecraft.nbt.IntArrayNBT) Coord4D(mekanism.api.Coord4D) SorterItemStackFilter(mekanism.common.content.transporter.SorterItemStackFilter) IItemStackFilter(mekanism.common.content.filter.IItemStackFilter) LongNBT(net.minecraft.nbt.LongNBT) ResourceLocation(net.minecraft.util.ResourceLocation) DoublePredicate(java.util.function.DoublePredicate) Collections(java.util.Collections) FrequencyIdentity(mekanism.common.lib.frequency.Frequency.FrequencyIdentity) HashMap(java.util.HashMap) FluidStack(net.minecraftforge.fluids.FluidStack) FrequencyIdentity(mekanism.common.lib.frequency.Frequency.FrequencyIdentity) QIOItemStackFilter(mekanism.common.content.qio.filter.QIOItemStackFilter) IItemStackFilter(mekanism.common.content.filter.IItemStackFilter) INBT(net.minecraft.nbt.INBT) SorterItemStackFilter(mekanism.common.content.transporter.SorterItemStackFilter) ResourceLocation(net.minecraft.util.ResourceLocation) Coord4D(mekanism.api.Coord4D) QIOFilter(mekanism.common.content.qio.filter.QIOFilter) UUID(java.util.UUID) ChemicalStack(mekanism.api.chemical.ChemicalStack) CompoundNBT(net.minecraft.nbt.CompoundNBT) IMaterialFilter(mekanism.common.content.filter.IMaterialFilter) MinerFilter(mekanism.common.content.miner.MinerFilter) ForgeRegistryEntry(net.minecraftforge.registries.ForgeRegistryEntry) ITagFilter(mekanism.common.content.filter.ITagFilter) IFilter(mekanism.common.content.filter.IFilter) Vector3i(net.minecraft.util.math.vector.Vector3i) Frequency(mekanism.common.lib.frequency.Frequency) OredictionificatorFilter(mekanism.common.content.oredictionificator.OredictionificatorFilter) Collection(java.util.Collection) ItemStack(net.minecraft.item.ItemStack) IModIDFilter(mekanism.common.content.filter.IModIDFilter) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with FrequencyIdentity

use of mekanism.common.lib.frequency.Frequency.FrequencyIdentity in project Mekanism by mekanism.

the class TileEntityQuantumEntangloporter method createFrequency.

@ComputerMethod
private void createFrequency(String name) throws ComputerException {
    validateSecurityIsPublic();
    InventoryFrequency frequency = FrequencyType.INVENTORY.getManagerWrapper().getPublicManager().getFrequency(name);
    if (frequency != null) {
        throw new ComputerException("Unable to create public inventory frequency with name '%s' as one already exists.", name);
    }
    setFrequency(FrequencyType.INVENTORY, new FrequencyIdentity(name, true), getOwnerUUID());
}
Also used : FrequencyIdentity(mekanism.common.lib.frequency.Frequency.FrequencyIdentity) InventoryFrequency(mekanism.common.content.entangloporter.InventoryFrequency) ComputerException(mekanism.common.integration.computer.ComputerException) WrappingComputerMethod(mekanism.common.integration.computer.annotation.WrappingComputerMethod) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod)

Example 5 with FrequencyIdentity

use of mekanism.common.lib.frequency.Frequency.FrequencyIdentity in project Mekanism by mekanism.

the class TileEntityQIOComponent method createFrequency.

@ComputerMethod
private void createFrequency(String name) throws ComputerException {
    validateSecurityIsPublic();
    QIOFrequency frequency = FrequencyType.QIO.getManagerWrapper().getPublicManager().getFrequency(name);
    if (frequency != null) {
        throw new ComputerException("Unable to create public QIO frequency with name '%s' as one already exists.", name);
    }
    setFrequency(FrequencyType.QIO, new FrequencyIdentity(name, true), getOwnerUUID());
}
Also used : FrequencyIdentity(mekanism.common.lib.frequency.Frequency.FrequencyIdentity) QIOFrequency(mekanism.common.content.qio.QIOFrequency) ComputerException(mekanism.common.integration.computer.ComputerException) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod)

Aggregations

FrequencyIdentity (mekanism.common.lib.frequency.Frequency.FrequencyIdentity)11 UUID (java.util.UUID)3 CompoundNBT (net.minecraft.nbt.CompoundNBT)3 Nullable (javax.annotation.Nullable)2 ComputerException (mekanism.common.integration.computer.ComputerException)2 ComputerMethod (mekanism.common.integration.computer.annotation.ComputerMethod)2 IFrequencyItem (mekanism.common.lib.frequency.IFrequencyItem)2 IArguments (dan200.computercraft.api.lua.IArguments)1 LuaException (dan200.computercraft.api.lua.LuaException)1 MethodResult (dan200.computercraft.api.lua.MethodResult)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1