Java Code Examples for net.minecraft.item.ItemStack#addEnchantment()

The following examples show how to use net.minecraft.item.ItemStack#addEnchantment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnchantCmd.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
private void enchant(ItemStack stack)
{
	for(Enchantment enchantment : Registry.ENCHANTMENT)
	{
		if(enchantment == Enchantments.SILK_TOUCH)
			continue;
		
		if(enchantment.isCursed())
			continue;
		
		if(enchantment == Enchantments.QUICK_CHARGE)
		{
			stack.addEnchantment(enchantment, 5);
			continue;
		}
		
		stack.addEnchantment(enchantment, 127);
	}
}
 
Example 2
Source File: RenderBlockTileEntity.java    From MiningGadgets with MIT License 6 votes vote down vote up
public void setBlockAllowed() {
    if (!UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.VOID_JUNK)) {
        this.blockAllowed = true;
        return;
    }
    PlayerEntity player = world.getPlayerByUuid(playerUUID);
    if (player == null) return;
    int silk = 0;
    int fortune = 0;

    ItemStack tempTool = new ItemStack(ModItems.MININGGADGET.get());

    // If silk is in the upgrades, apply it without a tier.
    if (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.SILK)) {
        tempTool.addEnchantment(Enchantments.SILK_TOUCH, 1);
        silk = 1;
    }

    // FORTUNE_1 is eval'd against the basename so this'll support all fortune upgrades
    if (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.FORTUNE_1)) {
        Optional<Upgrade> upgrade = UpgradeTools.getUpgradeFromList(gadgetUpgrades, Upgrade.FORTUNE_1);
        if (upgrade.isPresent()) {
            fortune = upgrade.get().getTier();
            tempTool.addEnchantment(Enchantments.FORTUNE, fortune);
        }
    }

    List<ItemStack> drops = Block.getDrops(renderBlock, (ServerWorld) world, this.pos, null, player, tempTool);

    this.blockAllowed = blockAllowed(drops, getGadgetFilters(), isGadgetIsWhitelist());
}
 
Example 3
Source File: ItemSheathKatana.java    From Sakura_mod with MIT License 5 votes vote down vote up
public ItemStack setKatana(ItemStack blade) {
   	ItemStack result = new ItemStack(katana,1);
   	result.setItemDamage(blade.getItemDamage());
   	if(blade.isItemEnchanted()){
   		Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(blade);
   		for(Enchantment ench : map.keySet()){
   			result.addEnchantment(ench, map.get(ench));
   		}
   	}
	return result;
}
 
Example 4
Source File: ShopkeeperTradesForFire.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack level2Bow() {
	ItemStack stack = new ItemStack(Items.BOW);
	stack.setStackDisplayName("Apollo Bow");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(48), 5);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(50), 1);
	return stack;
}
 
Example 5
Source File: ShopkeeperTradesForMoon.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack level3Sword() {
	ItemStack stack = new ItemStack(Items.DIAMOND_SWORD);
	stack.setStackDisplayName("Moon Sword III");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(16), 1);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(17), 2);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(18), 2);
	return stack;
}
 
Example 6
Source File: ShopkeeperTradesForWater.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack level3Helmet() {
	ItemStack stack = new ItemStack(Items.DIAMOND_HELMET);
	stack.setStackDisplayName("Charybdis Helmet");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(0), 1);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(6), 2);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(5), 2);
	return stack;
}
 
Example 7
Source File: ShopkeeperTradesForSun.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack level2Sword() {
	ItemStack stack = new ItemStack(Items.IRON_SWORD);
	stack.setStackDisplayName("Sol Sword");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(17), 3);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(16), 3);
	return stack;
}
 
Example 8
Source File: ShopkeeperTradesForMoon.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack level2Chestplate() {
	ItemStack stack = new ItemStack(Items.LEATHER_CHESTPLATE);
	stack.setStackDisplayName("Moon Chestplate II");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(0), 1);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(7), 4);
	return stack;
}
 
Example 9
Source File: ShopkeeperTradesForWater.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack level5Helmet() {
	ItemStack stack = new ItemStack(Items.DIAMOND_HELMET);
	stack.setStackDisplayName("Poseidon Helmet");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(0), 4);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(6), 4);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(5), 4);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(70), 1);
	return stack;
}
 
Example 10
Source File: ShopkeeperTradesForWater.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack level5Boots() {
	ItemStack stack = new ItemStack(Items.DIAMOND_BOOTS);
	stack.setStackDisplayName("Poseidon Boots");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(0), 4);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(8), 4);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(70), 1);
	return stack;
}
 
Example 11
Source File: GTItemRockCutter.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
	if (!isInCreativeTab(tab)) {
		return;
	}
	ItemStack empty = new ItemStack(this, 1, 0);
	ItemStack full = new ItemStack(this, 1, 0);
	ElectricItem.manager.discharge(empty, 2.147483647E9D, Integer.MAX_VALUE, true, false, false);
	ElectricItem.manager.charge(full, 2.147483647E9D, Integer.MAX_VALUE, true, false);
	empty.addEnchantment(Enchantments.SILK_TOUCH, 1);
	full.addEnchantment(Enchantments.SILK_TOUCH, 1);
	items.add(empty);
	items.add(full);
}
 
Example 12
Source File: ShopkeeperTradesForEarth.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack level5Pick() {
	ItemStack stack = new ItemStack(Items.DIAMOND_PICKAXE);
	stack.setStackDisplayName("Paul's Prick");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(32), 5);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(34), 3);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(35), 3);
	return stack;
}
 
Example 13
Source File: RenderBlockTileEntity.java    From MiningGadgets with MIT License 5 votes vote down vote up
private void removeBlock() {
    if(world == null || world.isRemote)
        return;

    PlayerEntity player = world.getPlayerByUuid(playerUUID);
    if (player == null)
        return;

    int silk = 0;
    int fortune = 0;

    ItemStack tempTool = new ItemStack(ModItems.MININGGADGET.get());

    // If silk is in the upgrades, apply it without a tier.
    if (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.SILK)) {
        tempTool.addEnchantment(Enchantments.SILK_TOUCH, 1);
        silk = 1;
    }

    // FORTUNE_1 is eval'd against the basename so this'll support all fortune upgrades
    if (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.FORTUNE_1)) {
        Optional<Upgrade> upgrade = UpgradeTools.getUpgradeFromList(gadgetUpgrades, Upgrade.FORTUNE_1);
        if (upgrade.isPresent()) {
            fortune = upgrade.get().getTier();
            tempTool.addEnchantment(Enchantments.FORTUNE, fortune);
        }
    }

    List<ItemStack> drops = Block.getDrops(renderBlock, (ServerWorld) world, this.pos, null, player, tempTool);

    if ( blockAllowed ) {
        int exp = renderBlock.getExpDrop(world, pos, fortune, silk);
        boolean magnetMode = (UpgradeTools.containsActiveUpgradeFromList(gadgetUpgrades, Upgrade.MAGNET));
        for (ItemStack drop : drops) {
            if (drop != null) {
                if (magnetMode) {
                    int wasPickedUp = ForgeEventFactory.onItemPickup(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), drop), player);
                    // 1  = someone allowed the event meaning it's handled,
                    // -1 = someone blocked the event and thus we shouldn't drop it nor insert it
                    // 0  = no body captured the event and we should handle it by hand.
                    if( wasPickedUp == 0 ) {
                        if (!player.addItemStackToInventory(drop))
                            Block.spawnAsEntity(world, pos, drop);
                    }
                } else {
                    Block.spawnAsEntity(world, pos, drop);
                }
            }
        }
        if (magnetMode) {
            if (exp > 0)
                player.giveExperiencePoints(exp);
        } else {
            if (exp > 0)
                renderBlock.getBlock().dropXpOnBlockBreak(world, pos, exp);
        }

        renderBlock.spawnAdditionalDrops(world, pos, tempTool); // Fixes silver fish basically...
    }

    world.removeTileEntity(this.pos);
    world.setBlockState(this.pos, Blocks.AIR.getDefaultState());

    // Add to the break stats
    player.addStat(Stats.BLOCK_MINED.get(renderBlock.getBlock()));

    // Handle special cases
    if(SpecialBlockActions.getRegister().containsKey(renderBlock.getBlock()))
        SpecialBlockActions.getRegister().get(renderBlock.getBlock()).accept(world, pos, renderBlock);
}
 
Example 14
Source File: ShopkeeperTradesForWater.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level1Boots() {
	ItemStack stack = new ItemStack(Items.LEATHER_BOOTS);
	stack.setStackDisplayName("Delphin Boots");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(8), 1);
	return stack;
}
 
Example 15
Source File: ShopkeeperTradesForFire.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level1Bow() {
	ItemStack stack = new ItemStack(Items.BOW);
	stack.setStackDisplayName("Agni Bow");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(50), 1);
	return stack;
}
 
Example 16
Source File: ShopkeeperTradesForWind.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level1Boots() {
	ItemStack stack = new ItemStack(Items.LEATHER_BOOTS);
	stack.setStackDisplayName("Wind Boots I");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(2), 1);
	return stack;
}
 
Example 17
Source File: ShopkeeperTradesForMoon.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level1Chestplate() {
	ItemStack stack = new ItemStack(Items.LEATHER_CHESTPLATE);
	stack.setStackDisplayName("Moon Chestplate I");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(7), 1);
	return stack;
}
 
Example 18
Source File: MetaTool.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void registerFlintToolRecipes() {
    Function<ToolMetaItem.MetaToolValueItem, ItemStack> toolDataApplier = item -> {
        ItemStack itemStack = item.setToolData(item.getStackForm(), Materials.Flint, 80, 1, 6.0f, 2.0f);
        if (itemStack.getItem().canApplyAtEnchantingTable(itemStack, Enchantments.FIRE_ASPECT)) {
            itemStack.addEnchantment(Enchantments.FIRE_ASPECT, 2);
        }
        return itemStack;
    };
    ModHandler.addShapedRecipe("mortar_flint", toolDataApplier.apply(MORTAR),
        " I ", "SIS", "SSS",
        'I', new ItemStack(Items.FLINT, 1),
        'S', OrePrefix.stone);

    ModHandler.addShapedRecipe("sword_flint", toolDataApplier.apply(SWORD),
        "F", "F", "S",
        'S', new UnificationEntry(OrePrefix.stick, Materials.Wood),
        'F', new ItemStack(Items.FLINT, 1));

    ModHandler.addShapedRecipe("pickaxe_flint", toolDataApplier.apply(PICKAXE),
        "FFF", " S ", " S ",
        'S', new UnificationEntry(OrePrefix.stick, Materials.Wood),
        'F', new ItemStack(Items.FLINT, 1));

    ModHandler.addShapedRecipe("shovel_flint", toolDataApplier.apply(SHOVEL),
        "F", "S", "S",
        'S', new UnificationEntry(OrePrefix.stick, Materials.Wood),
        'F', new ItemStack(Items.FLINT, 1));

    ModHandler.addMirroredShapedRecipe("axe_flint", toolDataApplier.apply(AXE),
        "FF", "FS", " S",
        'S', new UnificationEntry(OrePrefix.stick, Materials.Wood),
        'F', new ItemStack(Items.FLINT, 1));

    ModHandler.addMirroredShapedRecipe("hoe_flint", toolDataApplier.apply(HOE),
        "FF", " S", " S",
        'S', new UnificationEntry(OrePrefix.stick, Materials.Wood),
        'F', new ItemStack(Items.FLINT, 1));

    ModHandler.addShapedRecipe("knife_flint", toolDataApplier.apply(KNIFE),
        "F", "S",
        'S', new UnificationEntry(OrePrefix.stick, Materials.Wood),
        'F', new ItemStack(Items.FLINT, 1));
}
 
Example 19
Source File: ShopkeeperTradesForFire.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level3Sword() {
	ItemStack stack = new ItemStack(Items.DIAMOND_SWORD);
	stack.setStackDisplayName("Agni Sword");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(20), 1);
	return stack;
}
 
Example 20
Source File: ShopkeeperTradesForFire.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level1Sword() {
	ItemStack stack = new ItemStack(Items.IRON_SWORD);
	stack.setStackDisplayName("Logi Sword");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(20), 1);
	return stack;
}