Search in sources :

Example 76 with ZenMethod

use of stanhebben.zenscript.annotations.ZenMethod in project RandomTweaker by Project-RT.

the class IPlayerExpansionAS method setPerkExp.

@ZenMethod
public static boolean setPerkExp(IPlayer player, double exp) {
    PlayerProgress prog = ResearchManager.getProgress(CraftTweakerMC.getPlayer(player));
    if (IPlayerExpansionAS.getAttunedConstellation(player) == null) {
        CraftTweakerAPI.logInfo("This Player is not constellations");
        return false;
    }
    try {
        Class<? extends PlayerProgress> progClass = prog.getClass();
        Method setExp = progClass.getDeclaredMethod("setExp", double.class);
        setExp.setAccessible(true);
        setExp.invoke(prog, exp);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        CraftTweakerAPI.logError("Maybe you need to report this error", e);
    }
    return true;
}
Also used : ZenMethod(stanhebben.zenscript.annotations.ZenMethod) Method(java.lang.reflect.Method) PlayerProgress(hellfirepvp.astralsorcery.common.data.research.PlayerProgress) InvocationTargetException(java.lang.reflect.InvocationTargetException) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Example 77 with ZenMethod

use of stanhebben.zenscript.annotations.ZenMethod in project RandomTweaker by Project-RT.

the class IPlayerExpansionMO method isUnlocked.

@ZenMethod
public static boolean isUnlocked(IPlayer player, int id, int level) {
    EntityPlayer mcPlayer = CraftTweakerMC.getPlayer(player);
    boolean unlocked;
    if (IMatterOverdriveAndroid.isPlayerAndroid(mcPlayer)) {
        unlocked = IMatterOverdriveAndroid.isUnlocked(mcPlayer, id, level);
    } else {
        unlocked = false;
    }
    return unlocked;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Example 78 with ZenMethod

use of stanhebben.zenscript.annotations.ZenMethod in project RandomTweaker by Project-RT.

the class IPlayerExpansionTAN method addExhaustion.

@ZenMethod
public static void addExhaustion(IPlayer player, float exhaustion) {
    EntityPlayer mcPlayer = CraftTweakerMC.getPlayer(player);
    ThirstHandler thirstHandler = (ThirstHandler) mcPlayer.getCapability(TANCapabilities.THIRST, null);
    Objects.requireNonNull(thirstHandler).addExhaustion(exhaustion);
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ThirstHandler(toughasnails.thirst.ThirstHandler) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Example 79 with ZenMethod

use of stanhebben.zenscript.annotations.ZenMethod in project MrCrayfishFurnitureMod by MrCrayfish.

the class Blender method remove.

@ZenMethod
@ZenDoc("Remove matching blended drinks.")
public static void remove(@Optional final String name, @Optional final IItemStack[] ingredients, @Optional final Integer food, @Optional final int[] colour) {
    final StringBuilder description = new StringBuilder();
    Predicate<RecipeData> matcher = recipeData -> true;
    boolean first = true;
    description.append("Remove drink(s) matching '");
    if (name != null) {
        matcher = matcher.and((data) -> data.getDrinkName().equals(name));
        if (first)
            first = false;
        else
            description.append(',');
        description.append("name=").append(name);
    }
    if (ingredients != null) {
        matcher = matcher.and((data) -> {
            if (data.getIngredients().size() != ingredients.length)
                return false;
            LinkedList<IItemStack> toCheck = new LinkedList<>();
            Collections.addAll(toCheck, ingredients);
            outer: for (ItemStack stack : data.getIngredients()) {
                for (Iterator<IItemStack> it = toCheck.iterator(); it.hasNext(); ) {
                    IItemStack checker = it.next();
                    if (CraftTweakerMC.matchesExact(checker, stack)) {
                        it.remove();
                        continue outer;
                    }
                }
                return false;
            }
            return true;
        });
        if (first)
            first = false;
        else
            description.append(',');
        description.append("ingredients=").append(Arrays.toString(ingredients));
    }
    if (food != null) {
        matcher = matcher.and((data) -> data.getHealAmount() == food);
        if (first)
            first = false;
        else
            description.append(',');
        description.append("food=").append(food);
    }
    if (colour != null) {
        if (colour.length != 3)
            throw new IllegalArgumentException("colour must have 3 components");
        for (int c : colour) if (c < 0 || c > 255)
            throw new IllegalArgumentException("colour components must be between 0 and 255 inclusive");
        matcher = matcher.and((data) -> data.getRed() == colour[0] && data.getGreen() == colour[1] && data.getBlue() == colour[2]);
        if (first)
            first = false;
        else
            description.append(',');
        description.append("colour=").append(Arrays.toString(colour));
    }
    description.append("' from Blender");
    if (first) {
        description.setLength(0);
        description.append("Remove all drinks from Blender");
    }
    final Predicate<RecipeData> finalMatcher = matcher;
    CraftTweakerIntegration.defer(description.toString(), () -> {
        if (!Recipes.localBlenderRecipes.removeIf((data) -> {
            if (finalMatcher.test(data)) {
                CraftTweakerAPI.logInfo("Blender: Removed blended drink " + data);
                return true;
            }
            return false;
        })) {
            CraftTweakerAPI.logError("Blender: No blended drinks matched");
        }
    });
}
Also used : Optional(stanhebben.zenscript.annotations.Optional) Arrays(java.util.Arrays) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) ZenDoc(crafttweaker.annotations.ZenDoc) ZenClass(stanhebben.zenscript.annotations.ZenClass) ItemStack(net.minecraft.item.ItemStack) CraftTweakerAPI(crafttweaker.CraftTweakerAPI) IItemStack(crafttweaker.api.item.IItemStack) CraftTweakerMC(crafttweaker.api.minecraft.CraftTweakerMC) ZenMethod(stanhebben.zenscript.annotations.ZenMethod) LinkedList(java.util.LinkedList) RecipeData(com.mrcrayfish.furniture.api.RecipeData) Recipes(com.mrcrayfish.furniture.api.Recipes) Nonnull(javax.annotation.Nonnull) Collections(java.util.Collections) ZenRegister(crafttweaker.annotations.ZenRegister) IItemStack(crafttweaker.api.item.IItemStack) ItemStack(net.minecraft.item.ItemStack) IItemStack(crafttweaker.api.item.IItemStack) LinkedList(java.util.LinkedList) RecipeData(com.mrcrayfish.furniture.api.RecipeData) ZenDoc(crafttweaker.annotations.ZenDoc) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Example 80 with ZenMethod

use of stanhebben.zenscript.annotations.ZenMethod in project MrCrayfishFurnitureMod by MrCrayfish.

the class Blender method addDrink.

@ZenMethod
@ZenDoc("Add a blended drink.")
public static void addDrink(@Nonnull final String name, @Nonnull final IItemStack[] ingredients, final int food, @Nonnull final int[] colour) {
    if (name == null)
        throw new IllegalArgumentException("name cannot be null");
    if (ingredients == null)
        throw new IllegalArgumentException("ingredients cannot be null");
    if (food < 0)
        throw new IllegalArgumentException("food value must be non-negative");
    if (colour == null)
        throw new IllegalArgumentException("colour cannot be null");
    if (colour.length != 3)
        throw new IllegalArgumentException("colour must have 3 components");
    for (int c : colour) if (c < 0 || c > 255)
        throw new IllegalArgumentException("colour components must be between 0 and 255 inclusive");
    final RecipeData data = new RecipeData();
    data.setName(name);
    for (IItemStack i : ingredients) {
        data.addIngredient(CraftTweakerMC.getItemStack(i));
    }
    data.setHeal(food);
    data.setColour(colour[0], colour[1], colour[2]);
    CraftTweakerIntegration.defer("Add blended drink " + data + " to Blender", () -> {
        Recipes.localBlenderRecipes.add(data);
        CraftTweakerAPI.logInfo("Blender: Added trade " + data);
    });
}
Also used : IItemStack(crafttweaker.api.item.IItemStack) RecipeData(com.mrcrayfish.furniture.api.RecipeData) ZenDoc(crafttweaker.annotations.ZenDoc) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Aggregations

ZenMethod (stanhebben.zenscript.annotations.ZenMethod)147 ItemStack (net.minecraft.item.ItemStack)52 IItemStack (minetweaker.api.item.IItemStack)28 IItemStack (crafttweaker.api.item.IItemStack)23 EntityPlayer (net.minecraft.entity.player.EntityPlayer)16 FluidStack (net.minecraftforge.fluids.FluidStack)10 IDecayCapability (thebetweenlands.api.capability.IDecayCapability)8 PharmacologyEffect (minechem.potion.PharmacologyEffect)6 IIngredient (crafttweaker.api.item.IIngredient)5 RecipeData (com.mrcrayfish.furniture.api.RecipeData)4 IThirst (toughasnails.api.stat.capability.IThirst)4 NetRecipe (betterwithaddons.crafting.recipes.NetRecipe)3 TableRecipeShaped (com.blakebr0.extendedcrafting.crafting.table.TableRecipeShaped)3 ZenDoc (crafttweaker.annotations.ZenDoc)3 HashMap (java.util.HashMap)3 Function (java.util.function.Function)3 PotionChemical (minechem.potion.PotionChemical)3 MineTweakerMC.getItemStack (minetweaker.api.minecraft.MineTweakerMC.getItemStack)3 Ingredient (net.minecraft.item.crafting.Ingredient)3 CherryBoxRecipe (betterwithaddons.crafting.recipes.CherryBoxRecipe)2