Search in sources :

Example 21 with Nonnull

use of javax.annotation.Nonnull in project MinecraftForge by MinecraftForge.

the class GameRegistry method makeItemStack.

/**
     * Makes an {@link ItemStack} based on the itemName reference, with supplied meta, stackSize and nbt, if possible
     * <p/>
     * Will return null if the item doesn't exist (because it's not from a loaded mod for example)
     * Will throw a {@link RuntimeException} if the nbtString is invalid for use in an {@link ItemStack}
     *
     * @param itemName  a registry name reference
     * @param meta      the meta
     * @param stackSize the stack size
     * @param nbtString an nbt stack as a string, will be processed by {@link JsonToNBT}
     * @return a new itemstack
     */
@Nonnull
public static ItemStack makeItemStack(String itemName, int meta, int stackSize, String nbtString) {
    if (itemName == null) {
        throw new IllegalArgumentException("The itemName cannot be null");
    }
    Item item = GameData.getItemRegistry().getObject(new ResourceLocation(itemName));
    if (item == null) {
        FMLLog.getLogger().log(Level.TRACE, "Unable to find item with name {}", itemName);
        return ItemStack.EMPTY;
    }
    ItemStack is = new ItemStack(item, stackSize, meta);
    if (!Strings.isNullOrEmpty(nbtString)) {
        NBTBase nbttag = null;
        try {
            nbttag = JsonToNBT.getTagFromJson(nbtString);
        } catch (NBTException e) {
            FMLLog.getLogger().log(Level.WARN, "Encountered an exception parsing ItemStack NBT string {}", nbtString, e);
            throw Throwables.propagate(e);
        }
        if (!(nbttag instanceof NBTTagCompound)) {
            FMLLog.getLogger().log(Level.WARN, "Unexpected NBT string - multiple values {}", nbtString);
            throw new RuntimeException("Invalid NBT JSON");
        } else {
            is.setTagCompound((NBTTagCompound) nbttag);
        }
    }
    return is;
}
Also used : Item(net.minecraft.item.Item) NBTBase(net.minecraft.nbt.NBTBase) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) NBTException(net.minecraft.nbt.NBTException) Nonnull(javax.annotation.Nonnull)

Example 22 with Nonnull

use of javax.annotation.Nonnull in project MinecraftForge by MinecraftForge.

the class CombinedInvWrapper method getStackInSlot.

@Override
@Nonnull
public ItemStack getStackInSlot(int slot) {
    int index = getIndexForSlot(slot);
    IItemHandlerModifiable handler = getHandlerFromIndex(index);
    slot = getSlotFromIndex(slot, index);
    return handler.getStackInSlot(slot);
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) Nonnull(javax.annotation.Nonnull)

Example 23 with Nonnull

use of javax.annotation.Nonnull in project MinecraftForge by MinecraftForge.

the class InvWrapper method insertItem.

@Override
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
    if (stack.isEmpty())
        return ItemStack.EMPTY;
    ItemStack stackInSlot = getInv().getStackInSlot(slot);
    int m;
    if (!stackInSlot.isEmpty()) {
        if (!ItemHandlerHelper.canItemStacksStack(stack, stackInSlot))
            return stack;
        if (!getInv().isItemValidForSlot(slot, stack))
            return stack;
        m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot)) - stackInSlot.getCount();
        if (stack.getCount() <= m) {
            if (!simulate) {
                ItemStack copy = stack.copy();
                copy.grow(stackInSlot.getCount());
                getInv().setInventorySlotContents(slot, copy);
                getInv().markDirty();
            }
            return ItemStack.EMPTY;
        } else {
            // copy the stack to not modify the original one
            stack = stack.copy();
            if (!simulate) {
                ItemStack copy = stack.splitStack(m);
                copy.grow(stackInSlot.getCount());
                getInv().setInventorySlotContents(slot, copy);
                getInv().markDirty();
                return stack;
            } else {
                stack.shrink(m);
                return stack;
            }
        }
    } else {
        if (!getInv().isItemValidForSlot(slot, stack))
            return stack;
        m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot));
        if (m < stack.getCount()) {
            // copy the stack to not modify the original one
            stack = stack.copy();
            if (!simulate) {
                getInv().setInventorySlotContents(slot, stack.splitStack(m));
                getInv().markDirty();
                return stack;
            } else {
                stack.shrink(m);
                return stack;
            }
        } else {
            if (!simulate) {
                getInv().setInventorySlotContents(slot, stack);
                getInv().markDirty();
            }
            return ItemStack.EMPTY;
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 24 with Nonnull

use of javax.annotation.Nonnull in project MinecraftForge by MinecraftForge.

the class SidedInvWrapper method extractItem.

@Override
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate) {
    if (amount == 0)
        return ItemStack.EMPTY;
    int slot1 = getSlot(inv, slot, side);
    if (slot1 == -1)
        return ItemStack.EMPTY;
    ItemStack stackInSlot = inv.getStackInSlot(slot1);
    if (stackInSlot.isEmpty())
        return ItemStack.EMPTY;
    if (!inv.canExtractItem(slot1, stackInSlot, side))
        return ItemStack.EMPTY;
    if (simulate) {
        if (stackInSlot.getCount() < amount) {
            return stackInSlot.copy();
        } else {
            ItemStack copy = stackInSlot.copy();
            copy.setCount(amount);
            return copy;
        }
    } else {
        int m = Math.min(stackInSlot.getCount(), amount);
        return inv.decrStackSize(slot1, m);
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 25 with Nonnull

use of javax.annotation.Nonnull in project MinecraftForge by MinecraftForge.

the class ReflectionHelper method findMethod.

/**
     * Finds a method with the specified name and parameters in the given class and makes it accessible.
     * Note: for performance, store the returned value and avoid calling this repeatedly.
     * <p>
     * Throws an exception if the method is not found.
     *
     * @param clazz          The class to find the method on.
     * @param methodName     The name of the method to find (used in developer environments, i.e. "getWorldTime").
     * @param methodObfName  The obfuscated name of the method to find (used in obfuscated environments, i.e. "func_72820_D").
     *                       If the name you are looking for is on a class that is never obfuscated, this should be null.
     * @param parameterTypes The parameter types of the method to find.
     * @return The method with the specified name and parameters in the given class.
     */
@Nonnull
public static Method findMethod(@Nonnull Class<?> clazz, @Nonnull String methodName, @Nullable String methodObfName, Class<?>... parameterTypes) {
    Preconditions.checkNotNull(clazz);
    Preconditions.checkArgument(StringUtils.isNotEmpty(methodName), "Method name cannot be empty");
    String nameToFind;
    if (methodObfName == null || (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment")) {
        nameToFind = methodName;
    } else {
        nameToFind = methodObfName;
    }
    try {
        Method m = clazz.getDeclaredMethod(nameToFind, parameterTypes);
        m.setAccessible(true);
        return m;
    } catch (Exception e) {
        throw new UnableToFindMethodException(e);
    }
}
Also used : Method(java.lang.reflect.Method) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)2624 Nullable (javax.annotation.Nullable)338 ArrayList (java.util.ArrayList)336 ItemStack (net.minecraft.item.ItemStack)327 List (java.util.List)305 Map (java.util.Map)229 Layer (com.simiacryptus.mindseye.lang.Layer)188 Tensor (com.simiacryptus.mindseye.lang.Tensor)185 Arrays (java.util.Arrays)182 Collectors (java.util.stream.Collectors)169 IOException (java.io.IOException)165 JsonObject (com.google.gson.JsonObject)156 HashMap (java.util.HashMap)145 IntStream (java.util.stream.IntStream)145 Test (org.junit.Test)143 LoggerFactory (org.slf4j.LoggerFactory)138 Logger (org.slf4j.Logger)137 Result (com.simiacryptus.mindseye.lang.Result)130 TensorList (com.simiacryptus.mindseye.lang.TensorList)123 DeltaSet (com.simiacryptus.mindseye.lang.DeltaSet)111