net.minecraft.enchantment.Enchantment Java Examples

The following examples show how to use net.minecraft.enchantment.Enchantment. 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: ComponentExcavation.java    From Artifacts with 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 #2
Source File: EventHandlerRedirect.java    From Gadomancy with 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 #3
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 #4
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 #5
Source File: ShopkeeperTradesForWind.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("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 #6
Source File: ItemUtil.java    From seppuku with 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 #7
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 #8
Source File: ItemSheathKatana.java    From Sakura_mod with 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 #9
Source File: ContainerEnchantmentModifier.java    From NotEnoughItems with 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 #10
Source File: ItemVoidPickaxe.java    From enderutilities with 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 #11
Source File: ContainerEnchantmentModifier.java    From NotEnoughItems with 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 #12
Source File: Items_1_12_2.java    From multiconnect with 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 #13
Source File: ShopkeeperTradesForMoon.java    From ToroQuest with 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 #14
Source File: RenderUtilsLiving.java    From bleachhack-1.14 with 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 #15
Source File: CmdEnchant.java    From bleachhack-1.14 with 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 #16
Source File: RenderUtilsLiving.java    From bleachhack-1.14 with 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 #17
Source File: NEIServerUtils.java    From NotEnoughItems with 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 #18
Source File: ShopkeeperTradesForWind.java    From ToroQuest with 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 #19
Source File: ContainerEnchantmentModifier.java    From NotEnoughItems with 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 #20
Source File: RegisteredEnchantments.java    From Gadomancy with 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
Source File: QuestEnemyEncampment.java    From ToroQuest with 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
Source File: EnchantmentUtils.java    From ForgeHax with 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
Source File: InfusionEnchantmentRecipe.java    From PneumaticCraft with 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
Source File: ShopkeeperTradesForSun.java    From ToroQuest with 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
Source File: ShopkeeperTradesForMoon.java    From ToroQuest with 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
Source File: ShopkeeperTradesForMoon.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("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
Source File: ShopkeeperTradesForWater.java    From ToroQuest with 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
Source File: ShopkeeperTradesForMoon.java    From ToroQuest with 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 #29
Source File: ToolJackHammer.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean canApplyEnchantment(ItemStack stack, Enchantment enchantment) {
    return enchantment.type.canEnchantItem(Items.IRON_PICKAXE);
}
 
Example #30
Source File: ShopkeeperTradesForFire.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level4Sword() {
	ItemStack stack = new ItemStack(Items.DIAMOND_SWORD);
	stack.setStackDisplayName("Hephaestus Sword");
	stack.addEnchantment(Enchantment.REGISTRY.getObjectById(20), 2);
	return stack;
}