Search in sources :

Example 91 with ItemStack

use of net.minecraft.world.item.ItemStack in project MinecraftForge by MinecraftForge.

the class CompoundIngredient method getItems.

@Override
@Nonnull
public ItemStack[] getItems() {
    if (stacks == null) {
        List<ItemStack> tmp = Lists.newArrayList();
        for (Ingredient child : children) Collections.addAll(tmp, child.getItems());
        stacks = tmp.toArray(new ItemStack[tmp.size()]);
    }
    return stacks;
}
Also used : Ingredient(net.minecraft.world.item.crafting.Ingredient) ItemStack(net.minecraft.world.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 92 with ItemStack

use of net.minecraft.world.item.ItemStack in project MinecraftForge by MinecraftForge.

the class ForgeHooksClient method gatherTooltipComponents.

public static List<ClientTooltipComponent> gatherTooltipComponents(ItemStack stack, List<? extends FormattedText> textElements, Optional<TooltipComponent> itemComponent, int mouseX, int screenWidth, int screenHeight, @Nullable Font forcedFont, Font fallbackFont) {
    Font font = getTooltipFont(forcedFont, stack, fallbackFont);
    List<Either<FormattedText, TooltipComponent>> elements = textElements.stream().map((Function<FormattedText, Either<FormattedText, TooltipComponent>>) Either::left).collect(Collectors.toCollection(ArrayList::new));
    itemComponent.ifPresent(c -> elements.add(1, Either.right(c)));
    var event = new RenderTooltipEvent.GatherComponents(stack, screenWidth, screenHeight, elements, -1);
    MinecraftForge.EVENT_BUS.post(event);
    if (event.isCanceled())
        return List.of();
    // text wrapping
    int tooltipTextWidth = event.getTooltipElements().stream().mapToInt(either -> either.map(font::width, component -> 0)).max().orElse(0);
    boolean needsWrap = false;
    int tooltipX = mouseX + 12;
    if (tooltipX + tooltipTextWidth + 4 > screenWidth) {
        tooltipX = mouseX - 16 - tooltipTextWidth;
        if (// if the tooltip doesn't fit on the screen
        tooltipX < 4) {
            if (mouseX > screenWidth / 2)
                tooltipTextWidth = mouseX - 12 - 8;
            else
                tooltipTextWidth = screenWidth - 16 - mouseX;
            needsWrap = true;
        }
    }
    if (event.getMaxWidth() > 0 && tooltipTextWidth > event.getMaxWidth()) {
        tooltipTextWidth = event.getMaxWidth();
        needsWrap = true;
    }
    int tooltipTextWidthF = tooltipTextWidth;
    if (needsWrap) {
        return event.getTooltipElements().stream().flatMap(either -> either.map(text -> font.split(text, tooltipTextWidthF).stream().map(ClientTooltipComponent::create), component -> Stream.of(ClientTooltipComponent.create(component)))).toList();
    }
    return event.getTooltipElements().stream().map(either -> either.map(text -> ClientTooltipComponent.create(text instanceof Component ? ((Component) text).getVisualOrderText() : Language.getInstance().getVisualOrder(text)), ClientTooltipComponent::create)).toList();
}
Also used : Camera(net.minecraft.client.Camera) Font(net.minecraft.client.gui.Font) Arrays(java.util.Arrays) Connection(net.minecraft.network.Connection) ForgeMod(net.minecraftforge.common.ForgeMod) Dist(net.minecraftforge.api.distmarker.Dist) net.minecraftforge.fml(net.minecraftforge.fml) Pair(org.apache.commons.lang3.tuple.Pair) MultiPlayerGameMode(net.minecraft.client.multiplayer.MultiPlayerGameMode) Map(java.util.Map) AbstractClientPlayer(net.minecraft.client.player.AbstractClientPlayer) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) TooltipComponent(net.minecraft.world.inventory.tooltip.TooltipComponent) WorldPreset(net.minecraft.client.gui.screens.worldselection.WorldPreset) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Window(com.mojang.blaze3d.platform.Window) ForgeVersion(net.minecraftforge.versions.forge.ForgeVersion) SoundInstance(net.minecraft.client.resources.sounds.SoundInstance) Screen(net.minecraft.client.gui.screens.Screen) ResourceManager(net.minecraft.server.packs.resources.ResourceManager) Set(java.util.Set) Language(net.minecraft.locale.Language) NetworkRegistry(net.minecraftforge.network.NetworkRegistry) TextComponent(net.minecraft.network.chat.TextComponent) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) FormattedText(net.minecraft.network.chat.FormattedText) FluidState(net.minecraft.world.level.material.FluidState) ForgeI18n(net.minecraftforge.common.ForgeI18n) ItemStack(net.minecraft.world.item.ItemStack) GameType(net.minecraft.world.level.GameType) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) BETA(net.minecraftforge.fml.VersionChecker.Status.BETA) Resource(net.minecraft.server.packs.resources.Resource) WorldGenSettings(net.minecraft.world.level.levelgen.WorldGenSettings) com.mojang.blaze3d.vertex(com.mojang.blaze3d.vertex) HumanoidArm(net.minecraft.world.entity.HumanoidArm) BlockState(net.minecraft.world.level.block.state.BlockState) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) Supplier(java.util.function.Supplier) Vector3f(com.mojang.math.Vector3f) ArrayList(java.util.ArrayList) I18n(net.minecraft.client.resources.language.I18n) MouseHandler(net.minecraft.client.MouseHandler) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance) ModelManager(net.minecraft.client.resources.model.ModelManager) TitleScreen(net.minecraft.client.gui.screens.TitleScreen) Marker(org.apache.logging.log4j.Marker) Nullable(javax.annotation.Nullable) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) BlockAndTintGetter(net.minecraft.world.level.BlockAndTintGetter) ServerData(net.minecraft.client.multiplayer.ServerData) BakedModel(net.minecraft.client.resources.model.BakedModel) Transformation(com.mojang.math.Transformation) ItemTransforms(net.minecraft.client.renderer.block.model.ItemTransforms) Component(net.minecraft.network.chat.Component) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) TransformationHelper(net.minecraftforge.common.model.TransformationHelper) IOException(java.io.IOException) NarratorChatListener(net.minecraft.client.gui.chat.NarratorChatListener) File(java.io.File) ItemRenderer(net.minecraft.client.renderer.entity.ItemRenderer) LerpingBossEvent(net.minecraft.client.gui.components.LerpingBossEvent) MinecraftForge(net.minecraftforge.common.MinecraftForge) EquipmentSlot(net.minecraft.world.entity.EquipmentSlot) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ClientTooltipComponent(net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent) InteractionHand(net.minecraft.world.InteractionHand) Material(net.minecraft.client.resources.model.Material) net.minecraftforge.client.event(net.minecraftforge.client.event) ResourceLocation(net.minecraft.resources.ResourceLocation) Either(com.mojang.datafixers.util.Either) LivingEntity(net.minecraft.world.entity.LivingEntity) TextureAtlas(net.minecraft.client.renderer.texture.TextureAtlas) Direction(net.minecraft.core.Direction) Matrix4f(com.mojang.math.Matrix4f) Random(java.util.Random) ServerStatus(net.minecraft.network.protocol.status.ServerStatus) ForgeTextureMetadata(net.minecraftforge.client.textures.ForgeTextureMetadata) GameData(net.minecraftforge.registries.GameData) ChatFormatting(net.minecraft.ChatFormatting) BETA_OUTDATED(net.minecraftforge.fml.VersionChecker.Status.BETA_OUTDATED) FogMode(net.minecraft.client.renderer.FogRenderer.FogMode) Event(net.minecraftforge.eventbus.api.Event) Input(net.minecraft.client.player.Input) ImmutableMap(com.google.common.collect.ImmutableMap) BlockHitResult(net.minecraft.world.phys.BlockHitResult) Matrix3f(com.mojang.math.Matrix3f) Collectors(java.util.stream.Collectors) Player(net.minecraft.world.entity.player.Player) Objects(java.util.Objects) MarkerManager(org.apache.logging.log4j.MarkerManager) List(java.util.List) RecipeManager(net.minecraft.world.item.crafting.RecipeManager) BlockPos(net.minecraft.core.BlockPos) Optional(java.util.Optional) BOSSINFO(net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType.BOSSINFO) Level(net.minecraft.world.level.Level) net.minecraft.client.renderer(net.minecraft.client.renderer) PlayerInfo(net.minecraft.client.multiplayer.PlayerInfo) GuiComponent(net.minecraft.client.gui.GuiComponent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) SoundEngine(net.minecraft.client.sounds.SoundEngine) PlaySoundEvent(net.minecraftforge.client.event.sound.PlaySoundEvent) Function(java.util.function.Function) Stack(java.util.Stack) ItemColors(net.minecraft.client.color.item.ItemColors) BlockRenderDispatcher(net.minecraft.client.renderer.block.BlockRenderDispatcher) ParticleRenderType(net.minecraft.client.particle.ParticleRenderType) Minecraft(net.minecraft.client.Minecraft) JoinMultiplayerScreen(net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen) Fluid(net.minecraft.world.level.material.Fluid) Mod(net.minecraftforge.fml.common.Mod) HumanoidModel(net.minecraft.client.model.HumanoidModel) NativeImage(com.mojang.blaze3d.platform.NativeImage) Nonnull(javax.annotation.Nonnull) EntityHitResult(net.minecraft.world.phys.EntityHitResult) NetworkConstants(net.minecraftforge.network.NetworkConstants) LayerDefinition(net.minecraft.client.model.geom.builders.LayerDefinition) LocalPlayer(net.minecraft.client.player.LocalPlayer) ModelLayerLocation(net.minecraft.client.model.geom.ModelLayerLocation) HitResult(net.minecraft.world.phys.HitResult) Entity(net.minecraft.world.entity.Entity) Model(net.minecraft.client.model.Model) BlockColors(net.minecraft.client.color.block.BlockColors) KeyMapping(net.minecraft.client.KeyMapping) Comparator(java.util.Comparator) LogManager(org.apache.logging.log4j.LogManager) ForgeModelBakery(net.minecraftforge.client.model.ForgeModelBakery) FormattedText(net.minecraft.network.chat.FormattedText) ClientTooltipComponent(net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent) Font(net.minecraft.client.gui.Font) Function(java.util.function.Function) Either(com.mojang.datafixers.util.Either) TooltipComponent(net.minecraft.world.inventory.tooltip.TooltipComponent) ClientTooltipComponent(net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent) TooltipComponent(net.minecraft.world.inventory.tooltip.TooltipComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) TextComponent(net.minecraft.network.chat.TextComponent) Component(net.minecraft.network.chat.Component) ClientTooltipComponent(net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent) GuiComponent(net.minecraft.client.gui.GuiComponent)

Example 93 with ItemStack

use of net.minecraft.world.item.ItemStack in project MinecraftForge by MinecraftForge.

the class DispenseFluidContainer method fillContainer.

/**
 * Picks up fluid in front of a Dispenser and fills a container with it.
 */
@Nonnull
private ItemStack fillContainer(@Nonnull BlockSource source, @Nonnull ItemStack stack) {
    Level world = source.getLevel();
    Direction dispenserFacing = source.getBlockState().getValue(DispenserBlock.FACING);
    BlockPos blockpos = source.getPos().relative(dispenserFacing);
    FluidActionResult actionResult = FluidUtil.tryPickUpFluid(stack, null, world, blockpos, dispenserFacing.getOpposite());
    ItemStack resultStack = actionResult.getResult();
    if (!actionResult.isSuccess() || resultStack.isEmpty()) {
        return super.execute(source, stack);
    }
    if (stack.getCount() == 1) {
        return resultStack;
    } else if (((DispenserBlockEntity) source.getEntity()).addItem(resultStack) < 0) {
        this.dispenseBehavior.dispense(source, resultStack);
    }
    ItemStack stackCopy = stack.copy();
    stackCopy.shrink(1);
    return stackCopy;
}
Also used : DispenserBlockEntity(net.minecraft.world.level.block.entity.DispenserBlockEntity) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction) Nonnull(javax.annotation.Nonnull)

Example 94 with ItemStack

use of net.minecraft.world.item.ItemStack in project MinecraftForge by MinecraftForge.

the class FluidUtil method interactWithFluidHandler.

/**
 * Used to handle the common case of a player holding a fluid item and right-clicking on a fluid handler.
 * First it tries to fill the item from the handler,
 * if that action fails then it tries to drain the item into the handler.
 * Automatically updates the item in the player's hand and stashes any extra items created.
 *
 * @param player  The player doing the interaction between the item and fluid handler.
 * @param hand    The player's hand that is holding an item that should interact with the fluid handler.
 * @param handler The fluid handler.
 * @return true if the interaction succeeded and updated the item held by the player, false otherwise.
 */
public static boolean interactWithFluidHandler(@Nonnull Player player, @Nonnull InteractionHand hand, @Nonnull IFluidHandler handler) {
    Preconditions.checkNotNull(player);
    Preconditions.checkNotNull(hand);
    Preconditions.checkNotNull(handler);
    ItemStack heldItem = player.getItemInHand(hand);
    if (!heldItem.isEmpty()) {
        return player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).map(playerInventory -> {
            FluidActionResult fluidActionResult = tryFillContainerAndStow(heldItem, handler, playerInventory, Integer.MAX_VALUE, player, true);
            if (!fluidActionResult.isSuccess()) {
                fluidActionResult = tryEmptyContainerAndStow(heldItem, handler, playerInventory, Integer.MAX_VALUE, player, true);
            }
            if (fluidActionResult.isSuccess()) {
                player.setItemInHand(hand, fluidActionResult.getResult());
                return true;
            }
            return false;
        }).orElse(false);
    }
    return false;
}
Also used : SoundSource(net.minecraft.sounds.SoundSource) IItemHandler(net.minecraftforge.items.IItemHandler) Items(net.minecraft.world.item.Items) FluidBlockWrapper(net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper) BucketPickup(net.minecraft.world.level.block.BucketPickup) LiquidBlockContainer(net.minecraft.world.level.block.LiquidBlockContainer) Direction(net.minecraft.core.Direction) BlockState(net.minecraft.world.level.block.state.BlockState) BlockWrapper(net.minecraftforge.fluids.capability.wrappers.BlockWrapper) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) Fluid(net.minecraft.world.level.material.Fluid) Fluids(net.minecraft.world.level.material.Fluids) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) BlockHitResult(net.minecraft.world.phys.BlockHitResult) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) BucketPickupHandlerWrapper(net.minecraftforge.fluids.capability.wrappers.BucketPickupHandlerWrapper) Material(net.minecraft.world.level.material.Material) Player(net.minecraft.world.entity.player.Player) BlockPos(net.minecraft.core.BlockPos) Vec3(net.minecraft.world.phys.Vec3) SoundEvent(net.minecraft.sounds.SoundEvent) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) BlockPlaceContext(net.minecraft.world.item.context.BlockPlaceContext) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Block(net.minecraft.world.level.block.Block) BucketItem(net.minecraft.world.item.BucketItem) ItemStack(net.minecraft.world.item.ItemStack) InteractionHand(net.minecraft.world.InteractionHand) Level(net.minecraft.world.level.Level) ItemStack(net.minecraft.world.item.ItemStack)

Example 95 with ItemStack

use of net.minecraft.world.item.ItemStack in project MinecraftForge by MinecraftForge.

the class RecipeWrapper method removeItemNoUpdate.

/**
 * Removes the stack contained in this slot from the underlying handler, and returns it.
 */
@Override
public ItemStack removeItemNoUpdate(int index) {
    ItemStack s = getItem(index);
    if (s.isEmpty())
        return ItemStack.EMPTY;
    setItem(index, ItemStack.EMPTY);
    return s;
}
Also used : ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

ItemStack (net.minecraft.world.item.ItemStack)178 Level (net.minecraft.world.level.Level)62 ItemEntity (net.minecraft.world.entity.item.ItemEntity)61 InteractionHand (net.minecraft.world.InteractionHand)58 Player (net.minecraft.world.entity.player.Player)57 Items (net.minecraft.world.item.Items)55 InvocationTargetException (java.lang.reflect.InvocationTargetException)54 InteractionResult (net.minecraft.world.InteractionResult)54 EntitySize (de.Keyle.MyPet.api.entity.EntitySize)52 MyPet (de.Keyle.MyPet.api.entity.MyPet)52 EntityDataAccessor (net.minecraft.network.syncher.EntityDataAccessor)44 EntityDataSerializers (net.minecraft.network.syncher.EntityDataSerializers)44 SynchedEntityData (net.minecraft.network.syncher.SynchedEntityData)44 ServerLevel (net.minecraft.server.level.ServerLevel)44 MyPetApi (de.Keyle.MyPet.MyPetApi)40 Pair (com.mojang.datafixers.util.Pair)39 Bukkit (org.bukkit.Bukkit)39 CraftItemStack (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)39 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)39 Util (de.Keyle.MyPet.api.Util)38