Search in sources :

Example 1 with EnchanterRecipe

use of crazypants.enderio.base.recipe.enchanter.EnchanterRecipe in project EnderIO by SleepyTrousers.

the class ContainerEnchanter method addSlots.

@Override
protected void addSlots(@Nonnull InventoryPlayer playerInv) {
    final TileEnchanter te = getInv();
    addSlotToContainer(new Slot(te, 0, 16, 35) {

        @Override
        public int getSlotStackLimit() {
            return 1;
        }

        @Override
        public boolean isItemValid(@Nonnull ItemStack itemStack) {
            return te.isItemValidForSlot(0, itemStack);
        }

        @Override
        public void onSlotChanged() {
            updateOutput();
        }
    });
    addSlotToContainer(new Slot(te, 1, 65, 35) {

        @Override
        public boolean isItemValid(@Nonnull ItemStack itemStack) {
            return te.isItemValidForSlot(1, itemStack);
        }

        @Override
        public void onSlotChanged() {
            updateOutput();
        }
    });
    addSlotToContainer(new Slot(te, 2, 85, 35) {

        @Override
        public boolean isItemValid(@Nonnull ItemStack itemStack) {
            return te.isItemValidForSlot(2, itemStack);
        }

        @Override
        public void onSlotChanged() {
            updateOutput();
        }
    });
    addSlotToContainer(new Slot(te, 3, 144, 35) {

        @Override
        public int getSlotStackLimit() {
            return 1;
        }

        @Override
        public boolean isItemValid(@Nullable ItemStack itemStack) {
            return false;
        }

        @Override
        @Nonnull
        public ItemStack onTake(@Nonnull EntityPlayer player, @Nonnull ItemStack stack) {
            EnchanterRecipe currentEnchantmentRecipe = getInv().getCurrentEnchantmentRecipe();
            if (currentEnchantmentRecipe != null) {
                final int xpCost = currentEnchantmentRecipe.getXPCost(getInv().getInvAsMachineRecipeInput());
                List<MachineRecipeInput> quantitiesConsumed = currentEnchantmentRecipe.getQuantitiesConsumed(getInv().getInvAsMachineRecipeInput());
                for (MachineRecipeInput machineRecipeInput : quantitiesConsumed) {
                    te.decrStackSize(machineRecipeInput.slotNumber, machineRecipeInput.item.getCount());
                }
                if (!player.capabilities.isCreativeMode) {
                    player.addExperienceLevel(-xpCost);
                }
            } else {
                Log.error("Enchanting yielded result without resources");
            }
            if (!te.getWorld().isRemote) {
                te.getWorld().playEvent(1030, te.getPos(), 0);
                te.getWorld().playEvent(2005, te.getPos().up(), 0);
            }
            return stack;
        }

        @Override
        public boolean canTakeStack(@Nonnull EntityPlayer player) {
            return playerHasEnoughLevels(player);
        }
    });
}
Also used : EnchanterRecipe(crazypants.enderio.base.recipe.enchanter.EnchanterRecipe) Nonnull(javax.annotation.Nonnull) MachineRecipeInput(crazypants.enderio.base.recipe.MachineRecipeInput) GhostSlot(com.enderio.core.client.gui.widget.GhostSlot) GhostBackgroundItemSlot(com.enderio.core.client.gui.widget.GhostBackgroundItemSlot) Slot(net.minecraft.inventory.Slot) EntityPlayer(net.minecraft.entity.player.EntityPlayer) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 2 with EnchanterRecipe

use of crazypants.enderio.base.recipe.enchanter.EnchanterRecipe in project EnderIO by SleepyTrousers.

the class Enchanting method register.

@Override
public void register(@Nonnull String recipeName) {
    if (isValid() && isActive()) {
        final Things thing = input.getThing();
        final net.minecraft.enchantment.Enchantment enchantment2 = enchantment.getEnchantment();
        if (!thing.isEmpty() && enchantment2 != null) {
            EnchanterRecipe recipe = new EnchanterRecipe(thing, input.getAmount(), enchantment2, enchantment.getCostMultiplier());
            MachineRecipeRegistry.instance.registerRecipe(MachineRecipeRegistry.ENCHANTER, recipe);
        }
    }
}
Also used : EnchanterRecipe(crazypants.enderio.base.recipe.enchanter.EnchanterRecipe) Things(com.enderio.core.common.util.stackable.Things)

Example 3 with EnchanterRecipe

use of crazypants.enderio.base.recipe.enchanter.EnchanterRecipe in project EnderIO by SleepyTrousers.

the class ContainerEnchanter method updateOutput.

private void updateOutput() {
    EnchanterRecipe currentEnchantmentRecipe = getInv().getCurrentEnchantmentRecipe();
    if (currentEnchantmentRecipe != null) {
        ResultStack[] completedResult = currentEnchantmentRecipe.getCompletedResult(0, 1F, getInv().getInvAsMachineRecipeInput());
        getInv().setOutput(completedResult[0].item);
    } else {
        getInv().setOutput(Prep.getEmpty());
    }
}
Also used : EnchanterRecipe(crazypants.enderio.base.recipe.enchanter.EnchanterRecipe) ResultStack(crazypants.enderio.base.recipe.IMachineRecipe.ResultStack)

Aggregations

EnchanterRecipe (crazypants.enderio.base.recipe.enchanter.EnchanterRecipe)3 GhostBackgroundItemSlot (com.enderio.core.client.gui.widget.GhostBackgroundItemSlot)1 GhostSlot (com.enderio.core.client.gui.widget.GhostSlot)1 Things (com.enderio.core.common.util.stackable.Things)1 ResultStack (crazypants.enderio.base.recipe.IMachineRecipe.ResultStack)1 MachineRecipeInput (crazypants.enderio.base.recipe.MachineRecipeInput)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Slot (net.minecraft.inventory.Slot)1 ItemStack (net.minecraft.item.ItemStack)1