Search in sources :

Example 1 with RecipeData

use of com.mrcrayfish.furniture.api.RecipeData in project MrCrayfishFurnitureMod by MrCrayfish.

the class ContainerFreezer method transferStackInSlot.

public ItemStack transferStackInSlot(EntityPlayer player, int slotNum) {
    ItemStack itemCopy = ItemStack.EMPTY;
    Slot slot = this.inventorySlots.get(slotNum);
    if (slot != null && slot.getHasStack()) {
        ItemStack item = slot.getStack();
        itemCopy = item.copy();
        if (slotNum == 2) {
            if (!this.mergeItemStack(item, 3, 39, true)) {
                return ItemStack.EMPTY;
            }
            slot.onSlotChange(item, itemCopy);
        } else if (slotNum != 1 && slotNum != 0) {
            RecipeData data = RecipeAPI.getFreezerRecipeFromInput(item);
            if (data != null) {
                if (!this.mergeItemStack(item, 1, 2, false)) {
                    return ItemStack.EMPTY;
                }
            } else if (TileEntityFreezer.isFuel(item)) {
                if (!this.mergeItemStack(item, 0, 1, false)) {
                    return ItemStack.EMPTY;
                }
            } else if (slotNum >= 3 && slotNum < 30) {
                if (!this.mergeItemStack(item, 30, 39, false)) {
                    return ItemStack.EMPTY;
                }
            } else if (slotNum >= 30 && slotNum < 39 && !this.mergeItemStack(item, 3, 30, false)) {
                return ItemStack.EMPTY;
            }
        } else if (!this.mergeItemStack(item, 3, 39, false)) {
            return ItemStack.EMPTY;
        }
        if (item.getCount() == 0) {
            slot.putStack(ItemStack.EMPTY);
        } else {
            slot.onSlotChanged();
        }
        if (item.getCount() == itemCopy.getCount()) {
            return ItemStack.EMPTY;
        }
        slot.onTake(player, item);
    }
    return itemCopy;
}
Also used : Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack) RecipeData(com.mrcrayfish.furniture.api.RecipeData)

Example 2 with RecipeData

use of com.mrcrayfish.furniture.api.RecipeData in project MrCrayfishFurnitureMod by MrCrayfish.

the class ContainerMicrowave method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotNum) {
    ItemStack itemCopy = ItemStack.EMPTY;
    Slot slot = this.inventorySlots.get(slotNum);
    if (slot != null && slot.getHasStack()) {
        ItemStack item = slot.getStack();
        itemCopy = item.copy();
        RecipeData data = RecipeAPI.getMicrowaveRecipeFromIngredients(item);
        if (slotNum < 1) {
            if (!this.mergeItemStack(item, 1, this.inventorySlots.size(), false)) {
                return ItemStack.EMPTY;
            }
        } else if (data != null) {
            if (!this.mergeItemStack(item, 0, 1, false)) {
                return ItemStack.EMPTY;
            }
        } else if (slotNum > 0 && slotNum < 27) {
            if (!this.mergeItemStack(item, 27, this.inventorySlots.size(), true)) {
                return ItemStack.EMPTY;
            }
        } else if (!this.mergeItemStack(item, 1, 27, false)) {
            return ItemStack.EMPTY;
        }
        if (item.getCount() == 0) {
            slot.putStack(ItemStack.EMPTY);
        } else {
            slot.onSlotChanged();
        }
    }
    return itemCopy;
}
Also used : Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack) RecipeData(com.mrcrayfish.furniture.api.RecipeData)

Example 3 with RecipeData

use of com.mrcrayfish.furniture.api.RecipeData 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 4 with RecipeData

use of com.mrcrayfish.furniture.api.RecipeData 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)

Example 5 with RecipeData

use of com.mrcrayfish.furniture.api.RecipeData in project MrCrayfishFurnitureMod by MrCrayfish.

the class MineBay method addTrade.

@ZenMethod
@ZenDoc("Add a trade.")
public static void addTrade(@Nonnull IItemStack item, @Nonnull IItemStack currency) {
    if (item == null)
        throw new IllegalArgumentException("item cannot be null");
    if (currency == null)
        throw new IllegalArgumentException("currency cannot be null");
    final RecipeData data = new RecipeData();
    // MineBay RecipeData uses setInput for the purchasable item
    data.setInput(CraftTweakerMC.getItemStack(item));
    // MineBar RecipeData uses setCurrency for the currency item and setPrice for the amount of that item
    data.setCurrency(CraftTweakerMC.getItemStack(currency.withAmount(1)));
    data.setPrice(currency.getAmount());
    CraftTweakerIntegration.defer("Add trade " + data + " to MineBay", () -> {
        if (data.getPrice() < 1 || data.getPrice() > 64) {
            CraftTweakerAPI.logError("MineBay: Invalid trade price. Must be from 1 to 64.");
            return;
        }
        Recipes.localMineBayRecipes.add(data);
        CraftTweakerAPI.logInfo("MineBay: Added trade " + data);
    });
}
Also used : RecipeData(com.mrcrayfish.furniture.api.RecipeData) ZenDoc(crafttweaker.annotations.ZenDoc) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Aggregations

RecipeData (com.mrcrayfish.furniture.api.RecipeData)33 ItemStack (net.minecraft.item.ItemStack)8 Slot (net.minecraft.inventory.Slot)6 ZenDoc (crafttweaker.annotations.ZenDoc)3 EntityItem (net.minecraft.entity.item.EntityItem)3 ZenMethod (stanhebben.zenscript.annotations.ZenMethod)3 IItemStack (crafttweaker.api.item.IItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 Recipes (com.mrcrayfish.furniture.api.Recipes)1 TileEntityComputer (com.mrcrayfish.furniture.tileentity.TileEntityComputer)1 TileEntityToaster (com.mrcrayfish.furniture.tileentity.TileEntityToaster)1 CraftTweakerAPI (crafttweaker.CraftTweakerAPI)1 ZenRegister (crafttweaker.annotations.ZenRegister)1 CraftTweakerMC (crafttweaker.api.minecraft.CraftTweakerMC)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 Predicate (java.util.function.Predicate)1 Nonnull (javax.annotation.Nonnull)1