Search in sources :

Example 26 with NonNullList

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

the class GuiList method initGui.

@Override
public void initGui() {
    super.initGui();
    for (int line = 0; line < container.slots.length; line++) {
        WidgetListSlot[] arr = container.slots[line];
        for (int slot = 0; slot < arr.length; slot++) {
            final WidgetListSlot listSlot = arr[slot];
            GuiRectangle rectangle = new GuiRectangle(8 + slot * 18, 32 + line * 34, 16, 16);
            IGuiArea phantomSlotArea = rectangle.offset(mainGui.rootElement);
            mainGui.shownElements.add(listSlot.new GuiElementPhantomSlot(mainGui, phantomSlotArea) {

                @Override
                protected boolean shouldDrawHighlight() {
                    if (listSlot.slotIndex == 0) {
                        return true;
                    }
                    return !GuiList.this.container.lines[listSlot.lineIndex].isOneStackMode();
                }

                @Override
                public void drawBackground(float partialTicks) {
                    if (!shouldDrawHighlight()) {
                        ICON_HIGHLIGHT.drawAt(this);
                    }
                }

                @Nonnull
                @Override
                public ItemStack getStack() {
                    if (shouldDrawHighlight()) {
                        return super.getStack();
                    } else {
                        NonNullList<ItemStack> data = GuiList.this.getExamplesList(listSlot.lineIndex, container.lines[listSlot.lineIndex].getSortingType());
                        if (data.size() >= listSlot.slotIndex) {
                            return data.get(listSlot.slotIndex - 1);
                        } else {
                            return StackUtil.EMPTY;
                        }
                    }
                }

                @Override
                public void onMouseClicked(int button) {
                    super.onMouseClicked(button);
                    if (contains(gui.mouse)) {
                        clearExamplesCache(listSlot.lineIndex);
                    }
                }
            });
        }
    }
    buttonList.clear();
    for (int sy = 0; sy < ListHandler.HEIGHT; sy++) {
        int bOff = sy * BUTTON_COUNT;
        int bOffX = this.guiLeft + 8 + ListHandler.WIDTH * 18 - BUTTON_COUNT * 11;
        int bOffY = this.guiTop + 32 + sy * 34 + 18;
        GuiImageButton buttonPrecise = new GuiImageButton(mainGui, bOff + 0, bOffX, bOffY, 11, TEXTURE_BASE, 176, 16, 176, 28);
        buttonPrecise.setToolTip(ToolTip.createLocalized("gui.list.nbt"));
        buttonPrecise.setBehaviour(IButtonBehaviour.TOGGLE);
        mainGui.shownElements.add(buttonPrecise);
        GuiImageButton buttonType = new GuiImageButton(mainGui, bOff + 1, bOffX + 11, bOffY, 11, TEXTURE_BASE, 176, 16, 185, 28);
        buttonType.setToolTip(ToolTip.createLocalized("gui.list.metadata"));
        buttonType.setBehaviour(IButtonBehaviour.TOGGLE);
        mainGui.shownElements.add(buttonType);
        GuiImageButton buttonMaterial = new GuiImageButton(mainGui, bOff + 2, bOffX + 22, bOffY, 11, TEXTURE_BASE, 176, 16, 194, 28);
        buttonMaterial.setToolTip(ToolTip.createLocalized("gui.list.oredict"));
        buttonMaterial.setBehaviour(IButtonBehaviour.TOGGLE);
        mainGui.shownElements.add(buttonMaterial);
    }
    for (IGuiElement elem : mainGui.shownElements) {
        if (elem instanceof GuiImageButton) {
            GuiImageButton b = (GuiImageButton) elem;
            int id = Integer.parseInt(b.id);
            int lineId = id / BUTTON_COUNT;
            int buttonId = id % BUTTON_COUNT;
            if (container.lines[lineId].getOption(buttonId)) {
                b.activate();
            }
            b.registerListener(this);
        }
    }
    textField = new GuiTextField(6, this.fontRenderer, guiLeft + 10, guiTop + 10, 156, 12);
    textField.setMaxStringLength(32);
    textField.setText(BCCoreItems.list.getName(container.getListItemStack()));
    textField.setFocused(false);
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) Nonnull(javax.annotation.Nonnull) GuiTextField(net.minecraft.client.gui.GuiTextField) WidgetListSlot(buildcraft.core.list.ContainerList.WidgetListSlot) GuiImageButton(buildcraft.lib.gui.button.GuiImageButton) NonNullList(net.minecraft.util.NonNullList) IGuiElement(buildcraft.lib.gui.IGuiElement) ItemStack(net.minecraft.item.ItemStack)

Example 27 with NonNullList

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

the class ListMatchHandlerFluid method getClientExamples.

@Override
public NonNullList<ItemStack> getClientExamples(Type type, @Nonnull ItemStack stack) {
    buildClientExampleList();
    if (type == Type.MATERIAL) {
        FluidStack fStack = FluidUtil.getFluidContained(stack);
        if (fStack != null) {
            NonNullList<ItemStack> examples = NonNullList.create();
            for (ItemStack potentialHolder : clientExampleHolders) {
                potentialHolder = potentialHolder.copy();
                IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(potentialHolder);
                if (fluidHandler != null && (fluidHandler.fill(fStack, true) > 0 || fluidHandler.drain(fStack, false) != null)) {
                    examples.add(fluidHandler.getContainer());
                }
            }
            return examples;
        }
    } else if (type == Type.TYPE) {
        IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(stack.copy());
        if (fluidHandler != null) {
            NonNullList<ItemStack> examples = NonNullList.create();
            examples.add(stack);
            FluidStack contained = fluidHandler.drain(Integer.MAX_VALUE, true);
            if (contained != null) {
                examples.add(fluidHandler.getContainer());
                for (ItemStack potential : clientExampleHolders) {
                    IFluidHandlerItem potentialHolder = FluidUtil.getFluidHandler(potential);
                    if (potentialHolder.fill(contained, true) > 0) {
                        examples.add(potentialHolder.getContainer());
                    }
                }
            }
            return examples;
        }
    }
    return null;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) NonNullList(net.minecraft.util.NonNullList) ItemStack(net.minecraft.item.ItemStack)

Example 28 with NonNullList

use of net.minecraft.util.NonNullList in project BaseMetals by MinecraftModDevelopmentMods.

the class ShieldUpgradeRecipe method matchAndFind.

private Pair<Map<Enchantment, Integer>, ItemStack> matchAndFind(final ItemStack curItem, final Map<String, NonNullList<ItemStack>> plates) {
    final ItemStack comp = new ItemStack(curItem.getItem(), 1, curItem.getMetadata());
    Map<Enchantment, Integer> enchants = Collections.emptyMap();
    ItemStack plateMatched = null;
    final ItemStack matcher = new ItemStack(Materials.getMaterialByName(materialName).getItem(Names.SHIELD), 1, 0);
    for (final Entry<String, NonNullList<ItemStack>> ent : plates.entrySet()) {
        if (OreDictionary.containsMatch(false, ent.getValue(), comp)) {
            plateMatched = new ItemStack(Materials.getMaterialByName(ent.getKey().toLowerCase()).getItem(Names.SHIELD), 1, 0);
        }
    }
    if (OreDictionary.itemMatches(matcher, comp, false)) {
        enchants = EnchantmentHelper.getEnchantments(curItem);
    }
    return Pair.of(enchants, plateMatched);
}
Also used : NonNullList(net.minecraft.util.NonNullList) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment)

Example 29 with NonNullList

use of net.minecraft.util.NonNullList in project Skree by Skelril.

the class ZoneMasterOrb method onBlockInteract.

@Listener
public void onBlockInteract(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<org.spongepowered.api.item.inventory.ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optItemStack.isPresent()) {
        return;
    }
    ItemStack itemStack = tf(optItemStack.get());
    if (!isZoneMasterItem(itemStack)) {
        return;
    }
    if (isAttuned(itemStack)) {
        if (isInInstanceWorld(player)) {
            player.sendMessage(Text.of(TextColors.RED, "You cannot start an instance from within an instance."));
            event.setCancelled(true);
            return;
        }
        Optional<ZoneService> optService = Sponge.getServiceManager().provide(ZoneService.class);
        if (optService.isPresent()) {
            Task.builder().execute(() -> {
                ZoneService service = optService.get();
                List<Player> group = new ArrayList<>();
                group.add(player);
                for (Player aPlayer : Sponge.getServer().getOnlinePlayers()) {
                    NonNullList<ItemStack> itemStacks = tf(aPlayer).inventory.mainInventory;
                    for (ItemStack aStack : itemStacks) {
                        if (!hasSameZoneID(itemStack, aStack)) {
                            continue;
                        }
                        if (isAttuned(aStack) && isZoneSlaveItem(aStack)) {
                            Optional<Player> optZoneOwner = getGroupOwner(aStack);
                            if (optZoneOwner.isPresent()) {
                                group.add(aPlayer);
                                break;
                            }
                        }
                    }
                }
                for (int i = group.size() - 1; i >= 0; --i) {
                    purgeZoneItems(group.get(i), itemStack);
                    // createLightningStrike(group.get(i)); SpongeCommon/420
                    saveLocation(group.get(i));
                    getMainWorldWrapper().getLobby().add(group.get(i));
                }
                service.requestZone(getZone(itemStack).get(), group, () -> {
                    getMainWorldWrapper().getLobby().remove(group);
                }, result -> {
                    if (result.isPresent()) {
                        result.get().stream().filter(entry -> entry.getValue() != ZoneStatus.ADDED).forEach(entry -> {
                            player.setLocation(getRespawnLocation(player));
                            player.sendMessage(Text.of(TextColors.RED, "You could not be added to the zone."));
                        });
                    }
                });
            }).delayTicks(1).submit(SkreePlugin.inst());
        }
    }
    event.setUseBlockResult(Tristate.FALSE);
}
Also used : WorldService(com.skelril.skree.service.WorldService) InstanceWorldWrapper(com.skelril.skree.content.world.instance.InstanceWorldWrapper) SpawnCause(org.spongepowered.api.event.cause.entity.spawn.SpawnCause) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) Craftable(com.skelril.nitro.registry.Craftable) SkreePlugin(com.skelril.skree.SkreePlugin) WorldEffectWrapper(com.skelril.skree.service.internal.world.WorldEffectWrapper) Side(net.minecraftforge.fml.relauncher.Side) NonNullList(net.minecraft.util.NonNullList) ForgeTransformer.tf(com.skelril.nitro.transformer.ForgeTransformer.tf) ZoneItemUtil(com.skelril.skree.content.registry.item.zone.ZoneItemUtil) EntityItem(net.minecraft.entity.item.EntityItem) Lightning(org.spongepowered.api.entity.weather.Lightning) Location(org.spongepowered.api.world.Location) InteractEntityEvent(org.spongepowered.api.event.entity.InteractEntityEvent) CustomItem(com.skelril.nitro.registry.item.CustomItem) Sponge(org.spongepowered.api.Sponge) CustomItemTypes(com.skelril.skree.content.registry.item.CustomItemTypes) EventAwareContent(com.skelril.nitro.selector.EventAwareContent) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) Tristate(org.spongepowered.api.util.Tristate) Cause(org.spongepowered.api.event.cause.Cause) List(java.util.List) RespawnService(com.skelril.skree.service.RespawnService) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(org.spongepowered.api.world.World) HandTypes(org.spongepowered.api.data.type.HandTypes) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) First(org.spongepowered.api.event.filter.cause.First) Blocks(net.minecraft.init.Blocks) Getter(org.spongepowered.api.event.filter.Getter) Keys(org.spongepowered.api.data.key.Keys) MainWorldWrapper(com.skelril.skree.content.world.main.MainWorldWrapper) GameRegistry(net.minecraftforge.fml.common.registry.GameRegistry) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) EntityTypes(org.spongepowered.api.entity.EntityTypes) Text(org.spongepowered.api.text.Text) Task(org.spongepowered.api.scheduler.Task) ZoneStatus(com.skelril.skree.service.internal.zone.ZoneStatus) CreativeTabs(net.minecraft.creativetab.CreativeTabs) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) TextColors(org.spongepowered.api.text.format.TextColors) ZoneService(com.skelril.skree.service.ZoneService) Items(net.minecraft.init.Items) Item(org.spongepowered.api.entity.Item) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Player(org.spongepowered.api.entity.living.player.Player) ArrayList(java.util.ArrayList) ZoneService(com.skelril.skree.service.ZoneService) ItemStack(net.minecraft.item.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener)

Example 30 with NonNullList

use of net.minecraft.util.NonNullList in project Metalworks by canitzp.

the class Metalworks method postInit.

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
    SimpleSteelRecipeHandler.addBlastFurnaceRecipe(new RecipeBlastFurnace(new OreDictStack("ingotIron").setStacksize(2), new OreDictStack(Items.COAL).setStacksize(3), OreDictStack.EMPTY, new ItemStack(Registry.steelIngot), ItemStack.EMPTY, 0, 400, -1));
    SimpleSteelRecipeHandler.addBlastFurnaceRecipe(new RecipeBlastFurnace(new OreDictStack("ingotIron").setStacksize(3), new OreDictStack("gemDiamond"), OreDictStack.EMPTY, new ItemStack(Registry.metalShielding, 4), new ItemStack(Items.IRON_NUGGET), 25, 250, -1));
    // Generic Crusher
    for (String name : OreDictionary.getOreNames()) {
        if (name.startsWith("ore")) {
            String dustName = name.replaceFirst("ore", "dust");
            NonNullList<ItemStack> oreEntries = OreDictionary.getOres(dustName);
            if (!oreEntries.isEmpty()) {
                ItemStack dust = oreEntries.get(0).copy();
                dust.setCount(2);
                MACHINE_RECIPE_REGISTRY.register(new RecipeCrusher(name + "_" + dustName, new OreDictStack(name), dust, ItemStack.EMPTY, 0, 200, 0));
            }
        } else if (name.startsWith("ingot")) {
            String dustName = name.replaceFirst("ingot", "dust");
            NonNullList<ItemStack> oreEntries = OreDictionary.getOres(dustName);
            if (!oreEntries.isEmpty()) {
                ItemStack dust = oreEntries.get(0).copy();
                dust.setCount(1);
                MACHINE_RECIPE_REGISTRY.register(new RecipeCrusher(name + "_" + dustName, new OreDictStack(name), dust, ItemStack.EMPTY, 0, 150, 0));
            }
        }
    }
}
Also used : NonNullList(net.minecraft.util.NonNullList) RecipeBlastFurnace(de.canitzp.metalworks.machine.blastfurnace.RecipeBlastFurnace) ItemStack(net.minecraft.item.ItemStack) RecipeCrusher(de.canitzp.metalworks.machine.crusher.RecipeCrusher) OreDictStack(de.canitzp.metalworks.recipe.OreDictStack)

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