Search in sources :

Example 21 with NonNullList

use of net.minecraft.util.NonNullList in project SpongeCommon by SpongePowered.

the class MixinInventoryPlayer method onConstructed.

@Inject(method = "<init>*", at = @At("RETURN"), remap = false)
private void onConstructed(EntityPlayer playerIn, CallbackInfo ci) {
    // Find offhand slot
    for (NonNullList<ItemStack> inventory : this.allInventories) {
        if (inventory == this.offHandInventory) {
            break;
        }
        this.offhandIndex += inventory.size();
    }
    // Set Carrier if we got a real Player
    if (playerIn instanceof EntityPlayerMP) {
        this.carrier = (Player) playerIn;
        this.inventory = new IInventoryFabric((IInventory) this);
        Class clazz = this.getClass();
        if (clazz == InventoryPlayer.class) {
            // Build Player Lens
            // We only care about Server inventories
            this.slots = new SlotCollection.Builder().add(this.mainInventory.size()).add(this.offHandInventory.size()).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.BOOTS)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.LEGGINGS)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.CHESTPLATE)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.HEADWEAR)).add(this.armorInventory.size() - 4, EquipmentSlotAdapter.class).add(this.getSizeInventory() - this.mainInventory.size() - this.offHandInventory.size() - this.armorInventory.size()).build();
            this.lens = new PlayerInventoryLens(this, this.slots);
        } else if (this.getSizeInventory() != 0) {
            // Fallback OrderedLens when not 0 sized inventory
            this.slots = new SlotCollection.Builder().add(this.getSizeInventory()).build();
            this.lens = new OrderedInventoryLensImpl(0, this.getSizeInventory(), 1, slots);
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) Inventory(org.spongepowered.api.item.inventory.Inventory) PlayerInventory(org.spongepowered.api.item.inventory.entity.PlayerInventory) InventoryEventArgs(org.spongepowered.common.item.inventory.observer.InventoryEventArgs) Inject(org.spongepowered.asm.mixin.injection.Inject) EnumHand(net.minecraft.util.EnumHand) EquipmentInventory(org.spongepowered.api.item.inventory.equipment.EquipmentInventory) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) Overwrite(org.spongepowered.asm.mixin.Overwrite) MainPlayerInventoryAdapter(org.spongepowered.common.item.inventory.adapter.impl.comp.MainPlayerInventoryAdapter) ItemStackUtil(org.spongepowered.common.item.inventory.util.ItemStackUtil) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) IMixinInventoryPlayer(org.spongepowered.common.interfaces.entity.player.IMixinInventoryPlayer) Mixin(org.spongepowered.asm.mixin.Mixin) NonNullList(net.minecraft.util.NonNullList) At(org.spongepowered.asm.mixin.injection.At) Fabric(org.spongepowered.common.item.inventory.lens.Fabric) SlotProvider(org.spongepowered.common.item.inventory.lens.SlotProvider) IInventoryFabric(org.spongepowered.common.item.inventory.lens.impl.fabric.IInventoryFabric) Redirect(org.spongepowered.asm.mixin.injection.Redirect) EquipmentInventoryAdapter(org.spongepowered.common.item.inventory.adapter.impl.comp.EquipmentInventoryAdapter) EquipmentSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.EquipmentSlotLensImpl) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) Slot(org.spongepowered.api.item.inventory.Slot) Final(org.spongepowered.asm.mixin.Final) EquipmentSlotAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.EquipmentSlotAdapter) HotbarAdapter(org.spongepowered.common.item.inventory.adapter.impl.comp.HotbarAdapter) List(java.util.List) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IInventory(net.minecraft.inventory.IInventory) Lens(org.spongepowered.common.item.inventory.lens.Lens) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) SlotCollection(org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection) Player(org.spongepowered.api.entity.living.player.Player) EquipmentTypes(org.spongepowered.api.item.inventory.equipment.EquipmentTypes) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) SlotAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.SlotAdapter) PlayerInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.PlayerInventoryLens) SPacketHeldItemChange(net.minecraft.network.play.server.SPacketHeldItemChange) MainPlayerInventory(org.spongepowered.api.item.inventory.entity.MainPlayerInventory) IInventoryFabric(org.spongepowered.common.item.inventory.lens.impl.fabric.IInventoryFabric) EquipmentSlotAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.EquipmentSlotAdapter) PlayerInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.PlayerInventoryLens) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EquipmentSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.EquipmentSlotLensImpl) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 22 with NonNullList

use of net.minecraft.util.NonNullList in project Charset by CharsetMC.

the class RecipeReplacement method process.

public void process(Collection<IRecipe> registry) {
    for (IRecipe recipe : registry) {
        ResourceLocation recipeName = recipe.getRegistryName();
        boolean dirty = false;
        if (recipe instanceof ShapedRecipes || recipe instanceof ShapelessRecipes || recipe instanceof ShapedOreRecipe || recipe instanceof ShapelessOreRecipe) {
            NonNullList<Ingredient> ingredients = recipe.getIngredients();
            for (int i = 0; i < ingredients.size(); i++) {
                Ingredient ing = ingredients.get(i);
                Ingredient ingNew = replaceIngredient(ing);
                if (ingNew != null) {
                    ingredients.set(i, ingNew);
                    dirty = true;
                }
            }
        } else if (recipe instanceof RecipeCharset) {
            TCharObjectMap<Ingredient> charToIngredient = ((RecipeCharset) recipe).charToIngredient;
            NonNullList<Ingredient> ingredients = recipe.getIngredients();
            for (int i = 0; i < ingredients.size(); i++) {
                Ingredient ing = ingredients.get(i);
                Ingredient ingNew = replaceIngredient(ing);
                if (ingNew != null) {
                    ingredients.set(i, ingNew);
                    TCharIterator iterator = charToIngredient.keySet().iterator();
                    while (iterator.hasNext()) {
                        char c = iterator.next();
                        if (charToIngredient.get(c) == ing) {
                            charToIngredient.put(c, ing);
                        }
                    }
                    dirty = true;
                }
            }
        }
        if (dirty) {
            ModCharset.logger.info("Successfully edited " + recipeName + "!");
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) TCharIterator(gnu.trove.iterator.TCharIterator) TCharObjectMap(gnu.trove.map.TCharObjectMap) Ingredient(net.minecraft.item.crafting.Ingredient) OreIngredient(net.minecraftforge.oredict.OreIngredient) NonNullList(net.minecraft.util.NonNullList) ResourceLocation(net.minecraft.util.ResourceLocation) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 23 with NonNullList

use of net.minecraft.util.NonNullList in project ConvenientAdditions by Necr0.

the class ShapelessNBTOreRecipe method matches.

@SuppressWarnings("unchecked")
@Override
public boolean matches(InventoryCrafting var1, World world) {
    NonNullList<Object> required = NonNullList.create();
    required.addAll(input);
    for (int x = 0; x < var1.getSizeInventory(); x++) {
        ItemStack slot = var1.getStackInSlot(x);
        if (!slot.isEmpty()) {
            boolean inRecipe = false;
            Iterator<Object> req = required.iterator();
            while (req.hasNext()) {
                boolean match = false;
                Object next = req.next();
                if (next instanceof ItemStack) {
                    match = OreDictionary.itemMatches((ItemStack) next, slot, false) && (!((ItemStack) next).hasTagCompound() || ItemStack.areItemStackTagsEqual((ItemStack) next, slot));
                } else if (next instanceof List) {
                    Iterator<ItemStack> itr = ((List<ItemStack>) next).iterator();
                    while (itr.hasNext() && !match) {
                        ItemStack nxt = itr.next();
                        match = OreDictionary.itemMatches(nxt, slot, false) && (!nxt.hasTagCompound() || ItemStack.areItemStackTagsEqual(nxt, slot));
                    }
                }
                if (match) {
                    inRecipe = true;
                    required.remove(next);
                    break;
                }
            }
            if (!inRecipe) {
                return false;
            }
        }
    }
    return required.isEmpty();
}
Also used : Iterator(java.util.Iterator) List(java.util.List) NonNullList(net.minecraft.util.NonNullList) ItemStack(net.minecraft.item.ItemStack)

Example 24 with NonNullList

use of net.minecraft.util.NonNullList in project BuildCraft by BuildCraft.

the class GuidePageContents method loadMainGui.

public void loadMainGui() {
    TypeOrder order = GuiGuide.SORTING_TYPES[gui.sortingOrderIndex];
    contents.clear();
    quickSearcher = new SuffixArray<>();
    lastSearchText = "";
    Set<Item> itemsAdded = new HashSet<>();
    final String underline = TextFormatting.UNDERLINE.toString();
    for (PageEntry<?> entry : GuideManager.INSTANCE.getAllEntries()) {
        GuidePageFactory entryFactory = GuideManager.INSTANCE.getFactoryFor(entry);
        String[] ordered = entry.typeTags.getOrdered(order);
        String header = underline + LocaleUtil.localize(ordered[0]);
        String subHeader = underline + LocaleUtil.localize(ordered[1]);
        String translatedTitle = LocaleUtil.localize(entry.title);
        ISimpleDrawable icon = entry.createDrawable();
        PageLine line = new PageLine(icon, icon, 2, translatedTitle, true);
        GuideText text = new GuideText(gui, line);
        SubHeader pageHolder = contents.getOrAddSubHeader(header, subHeader);
        if (entryFactory == null) {
            if (entry.value instanceof ItemStackValueFilter) {
                ItemStack stack = ((ItemStackValueFilter) entry.value).stack.baseStack;
                itemsAdded.add(stack.getItem());
                PageLinkGenerated pageLink = pageHolder.addKnownPage(text, stack);
                if (pageLink != null) {
                    quickSearcher.add(pageLink, pageLink.joinedTooltip.toLowerCase(Locale.ROOT));
                }
            }
        } else {
            if (entry.value instanceof ItemStackValueFilter) {
                ItemStack stack = ((ItemStackValueFilter) entry.value).stack.baseStack;
                itemsAdded.add(stack.getItem());
            }
            PageLinkNormal pageLink = pageHolder.addNormalPage(text, entryFactory);
            quickSearcher.add(pageLink, pageLink.getName().toLowerCase(Locale.ROOT));
        }
    }
    String localizedGroup = underline + "\u0379" + LocaleUtil.localize("buildcraft.guide.contents.all_group");
    String localizedItems = underline + LocaleUtil.localize("buildcraft.guide.contents.item_stacks");
    Title allTitle = contents.getOrAddTitle(localizedGroup);
    SubHeader allHolder = allTitle.getOrAddSubHeader(localizedItems);
    for (Item item : ForgeRegistries.ITEMS) {
        if (itemsAdded.contains(item)) {
            continue;
        }
        NonNullList<ItemStack> stacks = NonNullList.create();
        item.getSubItems(CreativeTabs.SEARCH, stacks);
        for (int i = 0; i < stacks.size(); i++) {
            ItemStack stack = stacks.get(i);
            PageLinkGenerated pageLink = allHolder.addUnknownStack(stack);
            if (pageLink != null) {
                quickSearcher.add(pageLink, pageLink.joinedTooltip.toLowerCase(Locale.ROOT));
            }
            if (i > 50) {
                // most likely the same item
                break;
            }
        }
    }
    String localizedTriggers = underline + LocaleUtil.localize("buildcraft.guide.contents.triggers");
    String localizedActions = underline + LocaleUtil.localize("buildcraft.guide.contents.actions");
    SubHeader triggers = allTitle.getOrAddSubHeader(localizedTriggers);
    SubHeader actions = allTitle.getOrAddSubHeader(localizedActions);
    Set<IStatement> added = new HashSet<>();
    for (IStatement statement : new TreeMap<>(StatementManager.statements).values()) {
        if (!added.add(statement)) {
            continue;
        }
        if (GuideManager.INSTANCE.getEntryFor(statement) != null) {
            continue;
        }
        ISimpleDrawable icon = (x, y) -> GuiElementStatementSource.drawGuiSlot(statement, x, y);
        List<String> tooltip = statement.getTooltip();
        String title = tooltip.isEmpty() ? statement.getUniqueTag() : tooltip.get(0);
        GuideText text = new GuideText(gui, new PageLine(icon, icon, 2, title, true));
        final PageLinkNormal pageLink;
        if (statement instanceof ITrigger) {
            pageLink = triggers.addUnknownPage(text, g -> new GuidePage(gui, ImmutableList.of(), title));
        } else if (statement instanceof IAction) {
            pageLink = actions.addUnknownPage(text, g -> new GuidePage(gui, ImmutableList.of(), title));
        } else {
            pageLink = null;
        }
        if (pageLink != null) {
            String joinedTooltip = tooltip.stream().collect(Collectors.joining(" ", "", ""));
            String searchSr = statement.getUniqueTag() + " " + joinedTooltip;
            quickSearcher.add(pageLink, searchSr.toLowerCase(Locale.ROOT));
        }
    }
    quickSearcher.generate();
    contents.sortAll();
}
Also used : SuffixArray(net.minecraft.client.util.SuffixArray) GuideManager(buildcraft.lib.client.guide.GuideManager) GuidePage(buildcraft.lib.client.guide.parts.GuidePage) Title(buildcraft.lib.client.guide.parts.contents.ContentsList.Title) GuiElementStatementSource(buildcraft.lib.gui.statement.GuiElementStatementSource) Item(net.minecraft.item.Item) TypeOrder(buildcraft.lib.client.guide.TypeOrder) SubHeader(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader) HashSet(java.util.HashSet) PageLinkNormal(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLinkNormal) GuiIcon(buildcraft.lib.gui.GuiIcon) ItemStack(net.minecraft.item.ItemStack) ImmutableList(com.google.common.collect.ImmutableList) StatementManager(buildcraft.api.statements.StatementManager) Locale(java.util.Locale) IAction(buildcraft.api.statements.IAction) GuideChapter(buildcraft.lib.client.guide.parts.GuideChapter) BCLib(buildcraft.lib.BCLib) CreativeTabs(net.minecraft.creativetab.CreativeTabs) NonNullList(net.minecraft.util.NonNullList) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) PageEntry(buildcraft.lib.client.guide.PageEntry) PageLinkGenerated(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLinkGenerated) GuiTextField(net.minecraft.client.gui.GuiTextField) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GlStateManager(net.minecraft.client.renderer.GlStateManager) TextFormatting(net.minecraft.util.text.TextFormatting) ItemStackValueFilter(buildcraft.lib.client.guide.loader.entry.ItemStackValueFilter) GuidePageFactory(buildcraft.lib.client.guide.parts.GuidePageFactory) Set(java.util.Set) IOException(java.io.IOException) LocaleUtil(buildcraft.lib.misc.LocaleUtil) PageLine(buildcraft.lib.client.guide.PageLine) XmlPageLoader(buildcraft.lib.client.guide.loader.XmlPageLoader) ConfigurableFontRenderer(buildcraft.lib.client.render.font.ConfigurableFontRenderer) Collectors(java.util.stream.Collectors) GuiGuide(buildcraft.lib.client.guide.GuiGuide) IFontRenderer(buildcraft.lib.client.guide.font.IFontRenderer) RenderUtil(buildcraft.lib.misc.RenderUtil) List(java.util.List) TreeMap(java.util.TreeMap) FontRenderer(net.minecraft.client.gui.FontRenderer) IStatement(buildcraft.api.statements.IStatement) GuidePageBase(buildcraft.lib.client.guide.parts.GuidePageBase) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) GuideText(buildcraft.lib.client.guide.parts.GuideText) ITrigger(buildcraft.api.statements.ITrigger) PageLink(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLink) GuideText(buildcraft.lib.client.guide.parts.GuideText) TypeOrder(buildcraft.lib.client.guide.TypeOrder) Item(net.minecraft.item.Item) PageLine(buildcraft.lib.client.guide.PageLine) SubHeader(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader) HashSet(java.util.HashSet) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) IAction(buildcraft.api.statements.IAction) GuidePage(buildcraft.lib.client.guide.parts.GuidePage) Title(buildcraft.lib.client.guide.parts.contents.ContentsList.Title) ITrigger(buildcraft.api.statements.ITrigger) ItemStackValueFilter(buildcraft.lib.client.guide.loader.entry.ItemStackValueFilter) PageLinkGenerated(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLinkGenerated) GuidePageFactory(buildcraft.lib.client.guide.parts.GuidePageFactory) ItemStack(net.minecraft.item.ItemStack) IStatement(buildcraft.api.statements.IStatement) PageLinkNormal(buildcraft.lib.client.guide.parts.contents.ContentsList.Title.SubHeader.PageLinkNormal)

Example 25 with NonNullList

use of net.minecraft.util.NonNullList in project BuildCraft by BuildCraft.

the class GuideCraftingFactory method oreConvert.

@Nonnull
private static ItemStack oreConvert(Object object) {
    if (object == null) {
        return StackUtil.EMPTY;
    }
    if (object instanceof ItemStack) {
        return ((ItemStack) object).copy();
    }
    if (object instanceof String) {
        NonNullList<ItemStack> stacks = OreDictionary.getOres((String) object);
        // It will be sorted out below
        object = stacks;
    }
    if (object instanceof List<?>) {
        List<?> list = (List<?>) object;
        if (list.isEmpty()) {
            return StackUtil.EMPTY;
        }
        Object first = list.get(0);
        if (first == null) {
            return StackUtil.EMPTY;
        }
        if (first instanceof ItemStack) {
            ItemStack best = (ItemStack) first;
            for (Object obj : list) {
                if (!(obj instanceof ItemStack)) {
                    continue;
                }
                ItemStack stack = (ItemStack) obj;
                // The lower the ID of an item, the closer it is to minecraft. Hmmm.
                if (Item.getIdFromItem(stack.getItem()) < Item.getIdFromItem(best.getItem())) {
                    best = stack;
                }
            }
            return best.copy();
        }
        BCLog.logger.warn("Found a list with unknown contents! " + first.getClass());
    }
    BCLog.logger.warn("Found an ore with an unknown " + object.getClass());
    return StackUtil.EMPTY;
}
Also used : List(java.util.List) NBTTagList(net.minecraft.nbt.NBTTagList) NonNullList(net.minecraft.util.NonNullList) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

NonNullList (net.minecraft.util.NonNullList)42 ItemStack (net.minecraft.item.ItemStack)37 List (java.util.List)13 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 Item (net.minecraft.item.Item)8 TileEntity (net.minecraft.tileentity.TileEntity)8 BlockPos (net.minecraft.util.math.BlockPos)7 ArrayList (java.util.ArrayList)6 Collectors (java.util.stream.Collectors)6 ResourceLocation (net.minecraft.util.ResourceLocation)6 Iterator (java.util.Iterator)5 Map (java.util.Map)5 Nonnull (javax.annotation.Nonnull)5 Nullable (javax.annotation.Nullable)5 CreativeTabs (net.minecraft.creativetab.CreativeTabs)5 World (net.minecraft.world.World)5 Block (net.minecraft.block.Block)4 IBlockState (net.minecraft.block.state.IBlockState)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 RayTraceResult (net.minecraft.util.math.RayTraceResult)4