Java Code Examples for net.minecraft.enchantment.Enchantment

The following examples show how to use net.minecraft.enchantment.Enchantment. These examples are extracted from open source projects.
Example 1
Project: Gadomancy   File: EventHandlerRedirect.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public static int onGetEnchantmentLevel(int enchantmentId, ItemStack stack) {
    EntityPlayer possiblePlayer = null;
    if(stack != null) {
        MinecraftServer server = MinecraftServer.getServer();
        if(server != null && server.getConfigurationManager() != null) {
            for(EntityPlayer player : (List<EntityPlayer>) server.getConfigurationManager().playerEntityList) {
                if(player != null && player.getHeldItem() == stack) {
                    possiblePlayer = player;
                    break;
                }
            }
        }
    }

    if(possiblePlayer != null) {
        if(enchantmentId == Enchantment.fortune.effectId) {
            return getFortuneLevel(possiblePlayer);
        } else if(enchantmentId == Enchantment.looting.effectId) {
            return getLootingLevel(possiblePlayer);
        }

    }

    return getRealEnchantmentLevel(enchantmentId, stack);
}
 
Example 2
Project: Wurst7   File: EnchantCmd.java    License: 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 3
Project: Artifacts   File: ComponentExcavation.java    License: MIT License 6 votes vote down vote up
@Override
public boolean onBlockDestroyed(ItemStack itemStack, World world, Block destroyedBlock, int x, int y, int z, EntityLivingBase player) {
	//System.out.println("Test (" + x + "," + y + "," + z + ")");
	//player.getLookVec();
	int numBlocks = 0;
	for(int i=-1;i<=1;i++) {
		for(int j=-1;j<=1;j++) {
			for(int k=-1;k<=1;k++) {
				Block block = world.getBlock(x+i, y+j, z+k);
				if(block != null) {
					System.out.println("block: " + block.getUnlocalizedName());
					System.out.println("can:  " + itemStack.getItem().canHarvestBlock(block, itemStack));
					if(this.canHarvestBlock(block, itemStack)) {
						int fortuneLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemStack);
						block.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x+i, y+j, z+k), fortuneLevel);
						world.setBlockToAir(x+i, y+j, z+k);
						numBlocks++;
					}
				}
			}
		}
	}
	itemStack.damageItem(numBlocks/3, player);
	//Block block = Block.blocksList[l]
	return false;
}
 
Example 4
Project: NotEnoughItems   File: ContainerEnchantmentModifier.java    License: MIT License 5 votes vote down vote up
public void updateEnchantmentOptions(boolean validate) {
    int numoptions = slotEnchantment.size();
    slotEnchantment.clear();

    ItemStack toolstack = getSlot(0).getStack();
    if (toolstack == null) {
        percentscrolled = 0;
        return;
    }

    Item item = toolstack.getItem();
    int enchantablity = item.getItemEnchantability();
    if (enchantablity == 0 && validate) {
        percentscrolled = 0;
        return;
    }

    for (Enchantment e : Enchantment.enchantmentsList) {
        if (e == null || e.type == null || (!e.type.canEnchantItem(item) && validate)) {
            continue;
        }
        int state = 0;
        int level = -1;
        if (NEIServerUtils.stackHasEnchantment(toolstack, e.effectId)) {
            state = 2;
            level = NEIServerUtils.getEnchantmentLevel(toolstack, e.effectId);
        } else if (NEIServerUtils.doesEnchantmentConflict(NEIServerUtils.getEnchantments(toolstack), e) && validate) {
            state = 1;
        }
        slotEnchantment.add(new EnchantmentHash(e, state, level));
    }
    if (numoptions != slotEnchantment.size()) {
        percentscrolled = 0;
    }
}
 
Example 5
Project: Sakura_mod   File: ItemSheathKatana.java    License: MIT License 5 votes vote down vote up
public ItemStack setBlade(ItemStack blade) {
   	ItemStack result = new ItemStack(this,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 6
Project: Sakura_mod   File: ItemSheathKatana.java    License: 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 7
Project: NotEnoughItems   File: ContainerEnchantmentModifier.java    License: MIT License 5 votes vote down vote up
public boolean addEnchantment(String enchantmentLocation, int level) {
    Enchantment enchantment = Enchantment.getEnchantmentByLocation(enchantmentLocation);
    if (enchantment != null) {
        inventorySlots.get(0).getStack().addEnchantment(enchantment, level);
        return true;
    }
    return false;
}
 
Example 8
Project: seppuku   File: ItemUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static boolean isIllegalEnchant(Enchantment enc, short lvl) {
    final int maxPossibleLevel = enc.getMaxLevel();
    if (lvl == 0 || lvl > maxPossibleLevel)
        return true;

    return lvl == Short.MAX_VALUE;
}
 
Example 9
Project: enderutilities   File: ItemVoidPickaxe.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean canApplyEnchantment(ItemStack stackTool, Enchantment enchantment)
{
    return enchantment.type == EnumEnchantmentType.ALL ||
           enchantment.type == EnumEnchantmentType.BREAKABLE ||
           enchantment.type == EnumEnchantmentType.DIGGER;
}
 
Example 10
Project: ToroQuest   File: ShopkeeperTradesForWind.java    License: 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("Wind Boots V");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(0), 4);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(2), 4);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(70), 1);
	return stack;
}
 
Example 11
Project: multiconnect   File: Items_1_12_2.java    License: MIT License 5 votes vote down vote up
private static void newEnchantmentListToOld(ListTag enchantments) {
    for (int i = 0; i < enchantments.size(); i++) {
        CompoundTag ench = enchantments.getCompound(i);
        Identifier name = Identifier.tryParse(ench.getString("id"));
        Enchantment enchObj = Registry.ENCHANTMENT.get(name);
        if (enchObj == null) {
            enchantments.remove(i);
            i--;
        } else {
            ench.putInt("id", Registry.ENCHANTMENT.getRawId(enchObj));
        }
    }
}
 
Example 12
Project: ToroQuest   File: ShopkeeperTradesForMoon.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack level3Chestplate() {
	ItemStack stack = new ItemStack(Items.DIAMOND_CHESTPLATE);
	stack.setStackDisplayName("Moon Chestplate III");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(0), 1);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(7), 1);
	return stack;
}
 
Example 13
Project: bleachhack-1.14   File: RenderUtilsLiving.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void drawItem(double x, double y, double z, double offX, double offY, double scale, ItemStack item) {
	glSetup(x, y, z);
	
    GL11.glScaled(0.4*scale, 0.4*scale, 0);
    
    GL11.glTranslated(offX, offY, 0);
    if (item.getItem() instanceof BlockItem) GL11.glRotatef(180F, 1F, 180F, 10F);
    mc.getItemRenderer().renderItem(new ItemStack(item.getItem()), ItemCameraTransforms.TransformType.GUI);
    if (item.getItem() instanceof BlockItem) GL11.glRotatef(-180F, -1F, -180F, -10F);
    GL11.glDisable(GL11.GL_LIGHTING);
    
    GL11.glScalef(-0.05F, -0.05F, 0);
    
    if (item.getCount() > 0) {
	    int w = mc.fontRenderer.getStringWidth("x" + item.getCount()) / 2;
	    mc.fontRenderer.drawStringWithShadow("x" + item.getCount(), 7 - w, 5, 0xffffff);
    }
    
    GL11.glScalef(0.85F, 0.85F, 0.85F);
    
    int c = 0;
    for (Entry<Enchantment, Integer> m: EnchantmentHelper.getEnchantments(item).entrySet()) {
    	int w1 = mc.fontRenderer.getStringWidth(I18n.format(m.getKey().getName()).substring(0, 2) + m.getValue()) / 2;
    	mc.fontRenderer.drawStringWithShadow(
    			I18n.format(m.getKey().getName()).substring(0, 2) + m.getValue(), -4 - w1, c*10-1,
    			m.getKey() == Enchantments.VANISHING_CURSE || m.getKey() == Enchantments.BINDING_CURSE
    			? 0xff5050 : 0xffb0e0);
    	c--;
    }
    
    glCleanup();
}
 
Example 14
Project: bleachhack-1.14   File: CmdEnchant.java    License: GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public void enchant(ItemStack item, Enchantment e, int level) {
	if (item.getTag() == null) item.setTag(new CompoundNBT());
	if (!item.getTag().contains("Enchantments", 9)) {
		item.getTag().put("Enchantments", new ListNBT());
    }

    ListNBT listnbt = item.getTag().getList("Enchantments", 10);
    CompoundNBT compoundnbt = new CompoundNBT();
    compoundnbt.putString("id", String.valueOf(Registry.ENCHANTMENT.getKey(e)));
    compoundnbt.putInt("lvl", level);
    listnbt.add(compoundnbt);
}
 
Example 15
Project: bleachhack-1.14   File: RenderUtilsLiving.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void drawItem(double x, double y, double z, double offX, double offY, double scale, ItemStack item) {
	glSetup(x, y, z);
	
    GL11.glScaled(0.4*scale, 0.4*scale, 0);
    
    GL11.glTranslated(offX, offY, 0);
    if (item.getItem() instanceof BlockItem) GL11.glRotatef(180F, 1F, 180F, 10F);
    mc.getItemRenderer().renderItem(new ItemStack(
    		item.getItem()), Mode.GUI, 0, 0, new MatrixStack(), mc.getBufferBuilders().getEntityVertexConsumers());
    if (item.getItem() instanceof BlockItem) GL11.glRotatef(-180F, -1F, -180F, -10F);
    GL11.glDisable(GL11.GL_LIGHTING);
    
    GL11.glScalef(-0.05F, -0.05F, 0);
    
    if (item.getCount() > 0) {
	    int w = mc.textRenderer.getWidth("x" + item.getCount()) / 2;
	    mc.textRenderer.drawWithShadow(new MatrixStack(), "x" + item.getCount(), 7 - w, 5, 0xffffff);
    }
    
    GL11.glScalef(0.85F, 0.85F, 0.85F);
    
    int c = 0;
    for (Entry<Enchantment, Integer> m: EnchantmentHelper.get(item).entrySet()) {
    	int w1 = mc.textRenderer.getWidth(I18n.translate(m.getKey().getName(2).asString()).substring(0, 2) + m.getValue()) / 2;
    	mc.textRenderer.drawWithShadow(new MatrixStack(),
    			I18n.translate(m.getKey().getName(2).asString()).substring(0, 2) + m.getValue(), -4 - w1, c*10-1,
    			m.getKey() == Enchantments.VANISHING_CURSE || m.getKey() == Enchantments.BINDING_CURSE
    			? 0xff5050 : 0xffb0e0);
    	c--;
    }
    
    GL11.glScalef(0.6F, 0.6F, 0.6F);
    String dur = item.getMaxDamage() - item.getDamage() + "";
       int color = 0x000000;
       try{ color = MathHelper.hsvToRgb(((float) (item.getMaxDamage() - item.getDamage()) / item.getMaxDamage()) / 3.0F, 1.0F, 1.0F); } catch (Exception e) {}
    if (item.isDamageable()) mc.textRenderer.drawWithShadow(new MatrixStack(), dur, -8 - dur.length() * 3, 15,
    		new Color(color >> 16 & 255, color >> 8 & 255, color & 255).getRGB());
    
    glCleanup();
}
 
Example 16
Project: NotEnoughItems   File: NEIServerUtils.java    License: MIT License 5 votes vote down vote up
public static boolean doesEnchantmentConflict(List<int[]> enchantments, Enchantment e) {
    for (int[] ai : enchantments)
        if (!e.canApplyTogether(Enchantment.enchantmentsList[ai[0]]))
            return true;

    return false;
}
 
Example 17
Project: ToroQuest   File: ShopkeeperTradesForWind.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack level4Boots() {
	ItemStack stack = new ItemStack(Items.DIAMOND_BOOTS);
	stack.setStackDisplayName("Wind Boots IV");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(0), 2);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(2), 4);
	return stack;
}
 
Example 18
Project: NotEnoughItems   File: ContainerEnchantmentModifier.java    License: MIT License 5 votes vote down vote up
public void updateEnchantmentOptions(boolean validate) {
    int numoptions = slotEnchantment.size();
    slotEnchantment.clear();

    ItemStack toolstack = getSlot(0).getStack();
    if (toolstack.isEmpty()) {
        percentscrolled = 0;
        return;
    }

    Item item = toolstack.getItem();
    int enchantablity = item.getItemEnchantability(toolstack);
    if (enchantablity == 0 && validate) {
        percentscrolled = 0;
        return;
    }

    for (Enchantment enchantment : Enchantment.REGISTRY) {
        if (enchantment == null || enchantment.type == null || (!enchantment.type.canEnchantItem(item) && validate)) {
            continue;
        }
        int state = 0;
        int level = -1;
        if (NEIServerUtils.stackHasEnchantment(toolstack, Enchantment.getEnchantmentID(enchantment))) {
            state = 2;
            level = NEIServerUtils.getEnchantmentLevel(toolstack, Enchantment.getEnchantmentID(enchantment));
        } else if (NEIServerUtils.doesEnchantmentConflict(NEIServerUtils.getEnchantments(toolstack), enchantment) && validate) {
            state = 1;
        }
        slotEnchantment.add(new EnchantmentHash(enchantment, state, level));
    }
    if (numoptions != slotEnchantment.size()) {
        percentscrolled = 0;
    }
}
 
Example 19
Project: ToroQuest   File: ShopkeeperTradesForMoon.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack level1Sword() {
	ItemStack stack = new ItemStack(Items.IRON_SWORD);
	stack.setStackDisplayName("Moon Sword I");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(17), 1);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(18), 1);
	return stack;
}
 
Example 20
Project: Gadomancy   File: RegisteredEnchantments.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public static <T extends Enchantment> T registerEnchantment(Class<T> enchClass) {
    int id = ModConfig.loadEnchantmentId(enchClass.getSimpleName());
    if(id == -1) {
        id = getUnassignedId(enchClass);
    }
    return new Injector(enchClass).invokeConstructor(int.class, id);
}
 
Example 21
Project: ToroQuest   File: QuestEnemyEncampment.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void addGoldenSword(QuestData data, List<ItemStack> in) {
	ItemStack sword = new ItemStack(Items.GOLDEN_SWORD);
	sword.addEnchantment(Enchantment.getEnchantmentByID(16), 5);
	sword.addEnchantment(Enchantment.getEnchantmentByID(21), 3);
	Province inProvince = PlayerCivilizationCapabilityImpl.get(data.getPlayer()).getInCivilization();
	if (inProvince.id.equals(data.getProvinceId())) {
		// TODO lang
		sword.setStackDisplayName("Golden Sword of " + inProvince.name);
	}
	in.add(sword);
}
 
Example 22
Project: ForgeHax   File: EnchantmentUtils.java    License: MIT License 5 votes vote down vote up
public String getShortName() {
  int id = Enchantment.getEnchantmentID(enchantment);
  if (SHORT_ENCHANT_NAMES.containsKey(id)) {
    if (enchantment.getMaxLevel() <= 1) {
      return SHORT_ENCHANT_NAMES.get(id);
    } else {
      return SHORT_ENCHANT_NAMES.get(id) + this.level;
    }
  } else {
    return toString();
  }
}
 
Example 23
Project: PneumaticCraft   File: InfusionEnchantmentRecipe.java    License: GNU General Public License v3.0 5 votes vote down vote up
public InfusionEnchantmentRecipe(String research, Enchantment input, int inst, 
		AspectList aspects2, ItemStack[] recipe) {
	this.research = research;
	this.enchantment = input;
	this.aspects = aspects2;
	this.components = recipe;
	this.instability = inst;
	this.recipeXP = Math.max(1, input.getMinEnchantability(1)/3);
}
 
Example 24
Project: ToroQuest   File: ShopkeeperTradesForSun.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack level4Sword() {
	ItemStack stack = new ItemStack(Items.DIAMOND_SWORD);
	stack.setStackDisplayName("Amaterasu Sword");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(17), 3);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(16), 3);
	return stack;
}
 
Example 25
Project: ToroQuest   File: ShopkeeperTradesForMoon.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack level5Chestplate() {
	ItemStack stack = new ItemStack(Items.DIAMOND_CHESTPLATE);
	stack.setStackDisplayName("Moon Chestplate V");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(0), 4);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(7), 4);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(70), 1);
	return stack;
}
 
Example 26
Project: ToroQuest   File: ShopkeeperTradesForMoon.java    License: 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("Moon Sword II");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(16), 1);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(17), 2);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(18), 2);
	return stack;
}
 
Example 27
Project: ToroQuest   File: ShopkeeperTradesForWater.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack level4Helmet() {
	ItemStack stack = new ItemStack(Items.DIAMOND_HELMET);
	stack.setStackDisplayName("Oceanus Helmet");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(0), 2);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(6), 4);
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(5), 4);
	return stack;
}
 
Example 28
Project: ToroQuest   File: ShopkeeperTradesForWater.java    License: 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 29
Project: ForbiddenMagic   File: EnchantmentEducational.java    License: Do What The F*ck You Want To Public License 4 votes vote down vote up
@Override
public boolean canApplyTogether(Enchantment ench) {
    return super.canApplyTogether(ench) && ench.effectId != Enchantment.looting.effectId && ench.effectId != DarkEnchantments.greedy.effectId;
}
 
Example 30
Project: TofuCraftReload   File: EnchantmentLoader.java    License: MIT License 4 votes vote down vote up
@SubscribeEvent
public static void registerEnchantment(RegistryEvent.Register<Enchantment> event) {
	event.getRegistry().registerAll(Drain,Batch);
}
 
Example 31
Project: OpenModsLib   File: EnchantingRecipe.java    License: MIT License 4 votes vote down vote up
@Override
public BooleanSupplier parse(JsonContext context, JsonObject json) {
	final String enchId = JsonUtils.getString(json, "id");
	return () -> Enchantment.REGISTRY.containsKey(new ResourceLocation(enchId));
}
 
Example 32
Project: enderutilities   File: ItemEnderTool.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public float getDestroySpeed(ItemStack stack, IBlockState state)
{
    if (this.isToolBroken(stack))
    {
        return 0.2f;
    }

    ToolType tool = ToolType.fromStack(stack);

    if (this.isCreativeLikeBreakingEnabled(stack) &&  this.canHarvestBlock(state, stack))
    {
        return 1600f;
    }

    // Allow instant mine of leaves with the axe
    if (state.getMaterial() == Material.LEAVES && tool.equals(ToolType.AXE))
    {
        // This seems to be enough to instant mine leaves even when jumping/flying
        return 100.0f;
    }

    float eff = this.efficiencyOnProperMaterial;
    // 34 is the minimum to allow instant mining with just Efficiency V (= no beacon/haste) on cobble,
    // 124 is the minimum for iron blocks @ hardness 5.0f (which is about the highest of "normal" blocks), 1474 on obsidian.
    // So maybe around 160 might be ok? I don't want insta-mining on obsidian, but all other types of "rock".
    if (PowerStatus.fromStack(stack) == PowerStatus.POWERED)
    {
        if (EnchantmentHelper.getEnchantmentLevel(Enchantment.getEnchantmentByLocation("efficiency"), stack) >= 5)
        {
            eff = 124.0f;
        }
        // This is enough to give instant mining for sandstone and netherrack without any Efficiency enchants.
        else
        {
            eff = 24.0f;
        }
    }

    //if (ForgeHooks.isToolEffective(stack, block, meta))
    if (state.getBlock().isToolEffective(tool.getToolClass(), state))
    {
        //System.out.println("getStrVsBlock(); isToolEffective() true: " + eff);
        return eff;
    }

    if (this.canHarvestBlock(state, stack))
    {
        //System.out.println("getStrVsBlock(); canHarvestBlock() true: " + eff);
        return eff;
    }

    //System.out.println("getStrVsBlock(); not effective: " + super.getStrVsBlock(stack, block, meta));
    return super.getDestroySpeed(stack, state);
}
 
Example 33
Project: ToroQuest   File: ShopkeeperTradesForFire.java    License: GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level1FireProtection() {
	ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK);
	stack.setStackDisplayName("Fire Protection I");
	ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(Enchantment.REGISTRY.getObjectById(1), 1));
	return stack;
}
 
Example 34
Project: the-hallow   File: LifestealEnchantment.java    License: MIT License 4 votes vote down vote up
public LifestealEnchantment(Enchantment.Weight weight, EnchantmentTarget target, EquipmentSlot[] slots) {
	super(weight, target, slots);
}
 
Example 35
Project: CommunityMod   File: BiJump.java    License: GNU Lesser General Public License v2.1 4 votes vote down vote up
@SubscribeEvent
public static void registerEnchants(RegistryEvent.Register<Enchantment> event) {
    event.getRegistry().register(BOINGBOING);
}
 
Example 36
Project: Et-Futurum   File: ServerEventHandler.java    License: The Unlicense 4 votes vote down vote up
@SubscribeEvent
public void arrowLoose(ArrowLooseEvent event) {
	if (event.bow == null)
		return;

	IInventory invt = event.entityPlayer.inventory;
	for (int i = 0; i < invt.getSizeInventory(); i++) {
		ItemStack arrow = invt.getStackInSlot(i);
		if (arrow != null && arrow.stackSize > 0 && arrow.getItem() == ModItems.tipped_arrow) {
			float charge = event.charge / 20.0F;
			charge = (charge * charge + charge * 2.0F) / 3.0F;

			if (charge < 0.1D)
				return;
			if (charge > 1.0F)
				charge = 1.0F;

			EntityTippedArrow arrowEntity = new EntityTippedArrow(event.entityPlayer.worldObj, event.entityPlayer, charge * 2.0F);
			arrowEntity.setEffect(TippedArrow.getEffect(arrow));

			if (charge == 1.0F)
				arrowEntity.setIsCritical(true);

			int power = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, event.bow);
			if (power > 0)
				arrowEntity.setDamage(arrowEntity.getDamage() + power * 0.5D + 0.5D);

			int punch = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, event.bow);
			if (punch > 0)
				arrowEntity.setKnockbackStrength(punch);

			if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, event.bow) > 0)
				arrowEntity.setFire(100);

			event.bow.damageItem(1, event.entityPlayer);
			event.entityPlayer.worldObj.playSoundAtEntity(event.entityPlayer, "random.bow", 1.0F, 1.0F / (event.entityPlayer.worldObj.rand.nextFloat() * 0.4F + 1.2F) + charge * 0.5F);

			if (!event.entityPlayer.capabilities.isCreativeMode && --arrow.stackSize <= 0)
				event.entityPlayer.inventory.setInventorySlotContents(i, null);

			if (!event.entityPlayer.worldObj.isRemote)
				event.entityPlayer.worldObj.spawnEntityInWorld(arrowEntity);
			event.setCanceled(true);
			return;
		}
	}
}
 
Example 37
Project: multiconnect   File: Protocol_1_10.java    License: MIT License 4 votes vote down vote up
private void mutateEnchantmentRegistry(ISimpleRegistry<Enchantment> registry) {
    registry.purge(Enchantments.BINDING_CURSE);
    registry.purge(Enchantments.VANISHING_CURSE);
}
 
Example 38
Project: multiconnect   File: Protocol_1_11.java    License: MIT License 4 votes vote down vote up
private void mutateEnchantmentRegistry(ISimpleRegistry<Enchantment> registry) {
    registry.purge(Enchantments.SWEEPING);
}
 
Example 39
Project: multiconnect   File: Enchantments_1_12_2.java    License: MIT License 4 votes vote down vote up
private static void register(ISimpleRegistry<Enchantment> registry, Enchantment enchantment, int id, String name) {
    RegistryKey<Enchantment> key = RegistryKey.of(registry.getRegistryKey(), new Identifier(name));
    registry.register(enchantment, id, key, false);
}
 
Example 40
Project: ToroQuest   File: ShopkeeperTradesForWater.java    License: 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;
}