use of net.minecraft.enchantment.Enchantment in project SilentGems by SilentChaos512.
the class ItemEnchantmentToken method setEnchantments.
public void setEnchantments(ItemStack token, Map<Enchantment, Integer> map) {
if (StackHelper.isEmpty(token))
return;
if (!token.hasTagCompound())
token.setTagCompound(new NBTTagCompound());
if (token.getTagCompound().hasKey(NBT_ENCHANTMENTS))
token.getTagCompound().removeTag(NBT_ENCHANTMENTS);
NBTTagList tagList = new NBTTagList();
for (Entry<Enchantment, Integer> entry : map.entrySet()) {
String name = entry.getKey().getRegistryName().toString();
int level = entry.getValue();
NBTTagCompound compound = new NBTTagCompound();
compound.setString("name", name);
compound.setShort("lvl", (short) level);
tagList.appendTag(compound);
}
token.getTagCompound().setTag(NBT_ENCHANTMENTS, tagList);
}
use of net.minecraft.enchantment.Enchantment in project SilentGems by SilentChaos512.
the class ItemEnchantmentToken method addModTokenRecipe.
public void addModTokenRecipe(String enchantmentName, EnumGem gem, Object other, int otherCount) {
SilentGems.logHelper.info(" Attempting to add token recipe for " + enchantmentName + "...");
Enchantment enchantment = Enchantment.REGISTRY.getObject(new ResourceLocation(enchantmentName));
if (enchantment == null) {
SilentGems.logHelper.info(" Failed to add! Enchantment is null?");
return;
}
addTokenRecipe(enchantment, gem, other, otherCount);
}
use of net.minecraft.enchantment.Enchantment in project RFTools by McJty.
the class EnvironmentalSetup method createEnchantedItem.
public static ItemStack createEnchantedItem(Item item, Enchantment effectId, int amount) {
ItemStack stack = new ItemStack(item);
Map<Enchantment, Integer> enchant = new HashMap<>();
enchant.put(effectId, amount);
EnchantmentHelper.setEnchantments(enchant, stack);
return stack;
}
use of net.minecraft.enchantment.Enchantment in project pnc-repressurized by TeamPneumatic.
the class IntegratorPressureChamber method handleDisenchanting.
private void handleDisenchanting(int x, int y, List<LocatedStack> locatedStacks) {
List<ItemStack> input = new ArrayList<ItemStack>();
List<ItemStack> output = new ArrayList<ItemStack>();
ItemStack enchantedItem = new ItemStack(Items.DIAMOND_SWORD);
EnchantmentHelper.addRandomEnchantment(new Random(), enchantedItem, 30, true);
input.add(enchantedItem);
output.add(new ItemStack(Items.DIAMOND_SWORD));
Map<Enchantment, Integer> enchants = EnchantmentHelper.getEnchantments(enchantedItem);
for (Map.Entry<Enchantment, Integer> enchant : enchants.entrySet()) {
ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK);
Map<Enchantment, Integer> newMap = new HashMap<>();
newMap.put(enchant.getKey(), enchant.getValue());
EnchantmentHelper.setEnchantments(newMap, enchantedBook);
output.add(enchantedBook);
input.add(new ItemStack(Items.BOOK));
}
for (int i = 0; i < input.size(); i++) {
LocatedStack stack = new LocatedStack(input.get(i), (int) ((x + 36 + i % 3 * 34) * GuiWiki.TEXT_SCALE), (int) ((y + 102 - i / 3 * 34) * GuiWiki.TEXT_SCALE));
locatedStacks.add(stack);
}
for (int i = 0; i < output.size(); i++) {
LocatedStack stack = new LocatedStack(output.get(i), (int) ((x + 180 + i % 3 * 36) * GuiWiki.TEXT_SCALE), (int) ((y + 60 + i / 3 * 36) * GuiWiki.TEXT_SCALE));
locatedStacks.add(stack);
}
}
use of net.minecraft.enchantment.Enchantment in project pnc-repressurized by TeamPneumatic.
the class PressureChamberVacuumEnchantHandler method craftRecipe.
@Override
public NonNullList<ItemStack> craftRecipe(ItemStackHandler inputStacks) {
ItemStack enchantedStack = getDisenchantableItem(inputStacks);
getBook(inputStacks).shrink(1);
// take a random enchantment off the enchanted item...
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(enchantedStack);
List<Enchantment> l = new ArrayList<>(enchantments.keySet());
Enchantment strippedEnchantment = l.get(new Random().nextInt(l.size()));
int level = enchantments.get(strippedEnchantment);
enchantments.remove(strippedEnchantment);
EnchantmentHelper.setEnchantments(enchantments, enchantedStack);
// ...and create an enchanted book with it
ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK);
EnchantmentHelper.setEnchantments(ImmutableMap.of(strippedEnchantment, level), enchantedBook);
return NonNullList.from(ItemStack.EMPTY, enchantedBook);
}
Aggregations