Java Code Examples for net.minecraft.enchantment.Enchantment#enchantmentsList()

The following examples show how to use net.minecraft.enchantment.Enchantment#enchantmentsList() . 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: ModuleVanilla.java    From OpenPeripheral-Integration with MIT License 6 votes vote down vote up
public static Object listEnchantments(NBTTagList ench) {
	List<Map<String, Object>> response = Lists.newArrayList();
	for (int i = 0; i < ench.tagCount(); ++i) {
		NBTTagCompound enchTag = ench.getCompoundTagAt(i);
		short id = enchTag.getShort("id");
		short lvl = enchTag.getShort("lvl");

		final Enchantment enchantment = Enchantment.enchantmentsList[id];
		if (enchantment != null) {
			Map<String, Object> entry = Maps.newHashMap();
			entry.put("name", enchantment.getName());
			entry.put("level", lvl);
			entry.put("fullName", enchantment.getTranslatedName(lvl));
			response.add(entry);
		}
	}
	return response;
}
 
Example 2
Source File: RegisteredEnchantments.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static int getUnassignedId(Class<? extends Enchantment> enchClass) {
    for(int i = 0; i < Enchantment.enchantmentsList.length; i++) {
        if(Enchantment.enchantmentsList[i] == null) {
            return i;
        }
    }
    throw new RuntimeException("Failed to find free id for " + Gadomancy.NAME + " enchantment (" + enchClass.getName() + ")! Please consider using the config option to change the enchantment id.");
}
 
Example 3
Source File: ContainerEnchantmentModifier.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public boolean addEnchantment(int e, int level) {
    if (e < Enchantment.enchantmentsList.length && Enchantment.enchantmentsList[e] != null) {
        ((Slot) inventorySlots.get(0)).getStack().addEnchantment(Enchantment.enchantmentsList[e], level);
        return true;
    }
    return false;
}
 
Example 4
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 5
Source File: PressureChamberPressureEnchantHandler.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack[] isValidRecipe(ItemStack[] inputStacks){
    List<ItemStack> enchantedBooks = new ArrayList<ItemStack>();
    for(ItemStack book : inputStacks) {
        if(book.getItem() == Items.enchanted_book) enchantedBooks.add(book);
    }
    if(enchantedBooks.size() == 0) return null;
    for(ItemStack inputStack : inputStacks) {
        if((inputStack.isItemEnchantable() || inputStack.isItemEnchanted()) && inputStack.getItem() != Items.enchanted_book) {
            //Map map = EnchantmentHelper.getEnchantments(inputStack);
            // Iterator toolEnchantIterator = map.keySet().iterator();
            // while(toolEnchantIterator.hasNext()){
            //    Enchantment toolEnchant = Enchantment.enchantmentsList[((Integer)toolEnchantIterator.next()).intValue()];
            for(ItemStack enchantedBook : enchantedBooks) {
                Map bookMap = EnchantmentHelper.getEnchantments(enchantedBook);
                Iterator bookEnchantIterator = bookMap.keySet().iterator();
                while(bookEnchantIterator.hasNext()) {
                    Enchantment bookEnchant = Enchantment.enchantmentsList[((Integer)bookEnchantIterator.next()).intValue()];
                    if(bookEnchant.canApply(inputStack)) {
                        return new ItemStack[]{inputStack, enchantedBook};
                    }
                }
            }
            //  }
        }
    }
    return null;
}
 
Example 6
Source File: GuiEnchantment.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
/**
 * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
 */
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
	super.drawScreen(mouseX, mouseY, partialTicks);
	boolean var4 = mc.thePlayer.capabilities.isCreativeMode;
	int var5 = field_147075_G.func_178147_e();

	for (int var6 = 0; var6 < 3; ++var6) {
		int var7 = field_147075_G.enchantLevels[var6];
		int var8 = field_147075_G.field_178151_h[var6];
		int var9 = var6 + 1;

		if (func_146978_c(60, 14 + 19 * var6, 108, 17, mouseX, mouseY) && var7 > 0 && var8 >= 0) {
			ArrayList<Object> var10 = Lists.newArrayList();
			String var11;
			if (var8 >= 0 && Enchantment.enchantmentsList[var8 & 255] != null) {
				var11 = Enchantment.enchantmentsList[var8 & 255].getTranslatedName((var8 & 65280) >> 8);
				var10.add(EnumChatFormatting.WHITE.toString() + EnumChatFormatting.ITALIC.toString() + I18n.format("container.enchant.clue", new Object[] { var11 }));
			}

			if (!var4) {
				if (var8 >= 0)
					var10.add("");

				if (mc.thePlayer.experienceLevel < var7)
					var10.add(EnumChatFormatting.RED.toString() + I18n.format("container.enchant.level.required", new Object[0]) + ": " + field_147075_G.enchantLevels[var6]);
				else {
					var11 = "";

					if (var9 == 1)
						var11 = I18n.format("container.enchant.lapis.one", new Object[0]);
					else
						var11 = I18n.format("container.enchant.lapis.many", new Object[] { Integer.valueOf(var9) });

					if (var5 >= var9)
						var10.add(EnumChatFormatting.GRAY.toString() + "" + var11);
					else
						var10.add(EnumChatFormatting.RED.toString() + "" + var11);

					if (var9 == 1)
						var11 = I18n.format("container.enchant.level.one", new Object[0]);
					else
						var11 = I18n.format("container.enchant.level.many", new Object[] { Integer.valueOf(var9) });

					var10.add(EnumChatFormatting.GRAY.toString() + "" + var11);
				}
			}

			drawHoveringText(var10, mouseX, mouseY, fontRendererObj);
			break;
		}
	}
}
 
Example 7
Source File: InfusionEnchantmentRecipe.java    From AdvancedMod with GNU General Public License v3.0 4 votes vote down vote up
/**
     * Used to check if a recipe matches current crafting inventory
     * @param player 
     */
	public boolean matches(ArrayList<ItemStack> input, ItemStack central, World world, EntityPlayer player) {
		if (research.length()>0 && !ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), research)) {
    		return false;
    	}
		
		if (!enchantment.canApply(central) || !central.getItem().isItemTool(central)) {
			return false;
		}
				
		Map map1 = EnchantmentHelper.getEnchantments(central);
		Iterator iterator = map1.keySet().iterator();
        while (iterator.hasNext())
        {
        	int j1 = ((Integer)iterator.next()).intValue();
            Enchantment ench = Enchantment.enchantmentsList[j1];
            if (j1 == enchantment.effectId &&
            		EnchantmentHelper.getEnchantmentLevel(j1, central)>=ench.getMaxLevel())
            	return false;
            if (enchantment.effectId != ench.effectId && 
            	(!enchantment.canApplyTogether(ench) ||
            	!ench.canApplyTogether(enchantment))) {
            	return false;
            }
        }
		
		ItemStack i2 = null;
		
		ArrayList<ItemStack> ii = new ArrayList<ItemStack>();
		for (ItemStack is:input) {
			ii.add(is.copy());
		}
		
		for (ItemStack comp:components) {
			boolean b=false;
			for (int a=0;a<ii.size();a++) {
				 i2 = ii.get(a).copy();
				if (comp.getItemDamage()==OreDictionary.WILDCARD_VALUE) {
					i2.setItemDamage(OreDictionary.WILDCARD_VALUE);
				}
				if (areItemStacksEqual(i2, comp,true)) {
					ii.remove(a);
					b=true;
					break;
				}
			}
			if (!b) return false;
		}
//		System.out.println(ii.size());
		return ii.size()==0?true:false;
    }
 
Example 8
Source File: InfusionEnchantmentRecipe.java    From Chisel-2 with GNU General Public License v2.0 4 votes vote down vote up
/**
     * Used to check if a recipe matches current crafting inventory
     * @param player 
     */
	public boolean matches(ArrayList<ItemStack> input, ItemStack central, World world, EntityPlayer player) {
		if (research.length()>0 && !ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), research)) {
    		return false;
    	}
		
		if (!enchantment.canApply(central) || !central.getItem().isItemTool(central)) {
			return false;
		}
				
		Map map1 = EnchantmentHelper.getEnchantments(central);
		Iterator iterator = map1.keySet().iterator();
        while (iterator.hasNext())
        {
        	int j1 = ((Integer)iterator.next()).intValue();
            Enchantment ench = Enchantment.enchantmentsList[j1];
            if (j1 == enchantment.effectId &&
            		EnchantmentHelper.getEnchantmentLevel(j1, central)>=ench.getMaxLevel())
            	return false;
            if (enchantment.effectId != ench.effectId && 
            	(!enchantment.canApplyTogether(ench) ||
            	!ench.canApplyTogether(enchantment))) {
            	return false;
            }
        }
		
		ItemStack i2 = null;
		
		ArrayList<ItemStack> ii = new ArrayList<ItemStack>();
		for (ItemStack is:input) {
			ii.add(is.copy());
		}
		
		for (ItemStack comp:components) {
			boolean b=false;
			for (int a=0;a<ii.size();a++) {
				 i2 = ii.get(a).copy();
				if (comp.getItemDamage()==OreDictionary.WILDCARD_VALUE) {
					i2.setItemDamage(OreDictionary.WILDCARD_VALUE);
				}
				if (areItemStacksEqual(i2, comp,true)) {
					ii.remove(a);
					b=true;
					break;
				}
			}
			if (!b) return false;
		}
//		System.out.println(ii.size());
		return ii.size()==0?true:false;
    }
 
Example 9
Source File: InfusionEnchantmentRecipe.java    From GardenCollection with MIT License 4 votes vote down vote up
/**
     * Used to check if a recipe matches current crafting inventory
     * @param player 
     */
	public boolean matches(ArrayList<ItemStack> input, ItemStack central, World world, EntityPlayer player) {
		if (research.length()>0 && !ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), research)) {
    		return false;
    	}
		
		if (!enchantment.canApply(central) || !central.getItem().isItemTool(central)) {
			return false;
		}
				
		Map map1 = EnchantmentHelper.getEnchantments(central);
		Iterator iterator = map1.keySet().iterator();
        while (iterator.hasNext())
        {
        	int j1 = ((Integer)iterator.next()).intValue();
            Enchantment ench = Enchantment.enchantmentsList[j1];
            if (j1 == enchantment.effectId &&
            		EnchantmentHelper.getEnchantmentLevel(j1, central)>=ench.getMaxLevel())
            	return false;
            if (enchantment.effectId != ench.effectId && 
            	(!enchantment.canApplyTogether(ench) ||
            	!ench.canApplyTogether(enchantment))) {
            	return false;
            }
        }
		
		ItemStack i2 = null;
		
		ArrayList<ItemStack> ii = new ArrayList<ItemStack>();
		for (ItemStack is:input) {
			ii.add(is.copy());
		}
		
		for (ItemStack comp:components) {
			boolean b=false;
			for (int a=0;a<ii.size();a++) {
				 i2 = ii.get(a).copy();
				if (comp.getItemDamage()==OreDictionary.WILDCARD_VALUE) {
					i2.setItemDamage(OreDictionary.WILDCARD_VALUE);
				}
				if (areItemStacksEqual(i2, comp,true)) {
					ii.remove(a);
					b=true;
					break;
				}
			}
			if (!b) return false;
		}
//		System.out.println(ii.size());
		return ii.size()==0?true:false;
    }
 
Example 10
Source File: InfusionEnchantmentRecipe.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 4 votes vote down vote up
/**
     * Used to check if a recipe matches current crafting inventory
     * @param player 
     */
	public boolean matches(ArrayList<ItemStack> input, ItemStack central, World world, EntityPlayer player) {
		if (research.length()>0 && !ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), research)) {
    		return false;
    	}
		
		if (!enchantment.canApply(central) || !central.getItem().isItemTool(central)) {
			return false;
		}
				
		Map map1 = EnchantmentHelper.getEnchantments(central);
		Iterator iterator = map1.keySet().iterator();
        while (iterator.hasNext())
        {
        	int j1 = ((Integer)iterator.next()).intValue();
            Enchantment ench = Enchantment.enchantmentsList[j1];
            if (j1 == enchantment.effectId &&
            		EnchantmentHelper.getEnchantmentLevel(j1, central)>=ench.getMaxLevel())
            	return false;
            if (enchantment.effectId != ench.effectId && 
            	(!enchantment.canApplyTogether(ench) ||
            	!ench.canApplyTogether(enchantment))) {
            	return false;
            }
        }
		
		ItemStack i2 = null;
		
		ArrayList<ItemStack> ii = new ArrayList<ItemStack>();
		for (ItemStack is:input) {
			ii.add(is.copy());
		}
		
		for (ItemStack comp:components) {
			boolean b=false;
			for (int a=0;a<ii.size();a++) {
				 i2 = ii.get(a).copy();
				if (comp.getItemDamage()==OreDictionary.WILDCARD_VALUE) {
					i2.setItemDamage(OreDictionary.WILDCARD_VALUE);
				}
				if (areItemStacksEqual(i2, comp,true)) {
					ii.remove(a);
					b=true;
					break;
				}
			}
			if (!b) return false;
		}
//		System.out.println(ii.size());
		return ii.size()==0?true:false;
    }
 
Example 11
Source File: InfusionEnchantmentRecipe.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
/**
     * Used to check if a recipe matches current crafting inventory
     * @param player 
     */
	public boolean matches(ArrayList<ItemStack> input, ItemStack central, World world, EntityPlayer player) {
		if (research.length()>0 && !ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), research)) {
    		return false;
    	}
		
		if (!enchantment.canApply(central) || !central.getItem().isItemTool(central)) {
			return false;
		}
				
		Map map1 = EnchantmentHelper.getEnchantments(central);
		Iterator iterator = map1.keySet().iterator();
        while (iterator.hasNext())
        {
        	int j1 = ((Integer)iterator.next()).intValue();
            Enchantment ench = Enchantment.enchantmentsList[j1];
            if (j1 == enchantment.effectId &&
            		EnchantmentHelper.getEnchantmentLevel(j1, central)>=ench.getMaxLevel())
            	return false;
            if (enchantment.effectId != ench.effectId && 
            	(!enchantment.canApplyTogether(ench) ||
            	!ench.canApplyTogether(enchantment))) {
            	return false;
            }
        }
		
		ItemStack i2 = null;
		
		ArrayList<ItemStack> ii = new ArrayList<ItemStack>();
		for (ItemStack is:input) {
			ii.add(is.copy());
		}
		
		for (ItemStack comp:components) {
			boolean b=false;
			for (int a=0;a<ii.size();a++) {
				 i2 = ii.get(a).copy();
				if (comp.getItemDamage()==OreDictionary.WILDCARD_VALUE) {
					i2.setItemDamage(OreDictionary.WILDCARD_VALUE);
				}
				if (areItemStacksEqual(i2, comp,true)) {
					ii.remove(a);
					b=true;
					break;
				}
			}
			if (!b) return false;
		}
//		System.out.println(ii.size());
		return ii.size()==0?true:false;
    }
 
Example 12
Source File: GuiSearcher.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
private void updateCreativeSearch(){
    ContainerSearcher containerSearcher = (ContainerSearcher)inventorySlots;
    containerSearcher.itemList.clear();

    Iterator iterator = Item.itemRegistry.iterator();

    while(iterator.hasNext()) {
        Item item = (Item)iterator.next();

        if(item != null && item.getCreativeTab() != null) {
            item.getSubItems(item, (CreativeTabs)null, containerSearcher.itemList);
        }
    }

    Enchantment[] aenchantment = Enchantment.enchantmentsList;
    int j = aenchantment.length;

    for(int i = 0; i < j; ++i) {
        Enchantment enchantment = aenchantment[i];

        if(enchantment != null && enchantment.type != null) {
            Items.enchanted_book.func_92113_a(enchantment, containerSearcher.itemList);
        }
    }

    iterator = containerSearcher.itemList.iterator();
    String s = searchField.getText().toLowerCase();

    while(iterator.hasNext()) {
        ItemStack itemstack = (ItemStack)iterator.next();
        boolean flag = false;
        Iterator iterator1 = itemstack.getTooltip(mc.thePlayer, mc.gameSettings.advancedItemTooltips).iterator();

        while(true) {
            if(iterator1.hasNext()) {
                String s1 = (String)iterator1.next();

                if(!s1.toLowerCase().contains(s)) {
                    continue;
                }

                flag = true;
            }

            if(!flag) {
                iterator.remove();
            }

            break;
        }
    }

    currentScroll = 0.0F;
    containerSearcher.scrollTo(0.0F);
}