use of net.minecraft.enchantment.Enchantment in project EnderIO by SleepyTrousers.
the class DarkSteelRecipeManager method getEnchantmentRepairCost.
private static int getEnchantmentRepairCost(@Nonnull ItemStack itemStack) {
// derived from ContainerRepair
int res = 0;
Map<Enchantment, Integer> map1 = EnchantmentHelper.getEnchantments(itemStack);
Iterator<Enchantment> iter = map1.keySet().iterator();
while (iter.hasNext()) {
Enchantment i1 = iter.next();
Enchantment enchantment = i1;
int level = map1.get(enchantment).intValue();
if (enchantment.canApply(itemStack)) {
if (level > enchantment.getMaxLevel()) {
level = enchantment.getMaxLevel();
}
int costPerLevel = 0;
switch(enchantment.getRarity()) {
case VERY_RARE:
costPerLevel = 8;
break;
case RARE:
costPerLevel = 4;
case UNCOMMON:
costPerLevel = 2;
break;
case COMMON:
costPerLevel = 1;
}
res += costPerLevel * level;
}
}
return res;
}
use of net.minecraft.enchantment.Enchantment in project EnderIO by SleepyTrousers.
the class DarkSteelUpgradeRecipeCategory method registerBookEnchantmentRecipes.
private static int registerBookEnchantmentRecipes(@Nonnull IModRegistry registry, @Nonnull NNList<ItemStack> ingredients) {
int count = 0;
Collection<Enchantment> enchantments = ForgeRegistries.ENCHANTMENTS.getValuesCollection();
List<IRecipeWrapper> anvilRecipes = new ArrayList<>();
IVanillaRecipeFactory factory = registry.getJeiHelpers().getVanillaRecipeFactory();
for (ItemStack ingredient : ingredients) {
if (ingredient.isItemEnchantable()) {
for (Enchantment enchantment : enchantments) {
if (enchantment.canApply(ingredient)) {
Item item = ingredient.getItem();
List<ItemStack> perLevelBooks = Lists.newArrayList();
List<ItemStack> perLevelOutputs = Lists.newArrayList();
for (int level = 1; level <= enchantment.getMaxLevel(); level++) {
Map<Enchantment, Integer> enchMap = Collections.singletonMap(enchantment, level);
ItemStack bookEnchant = new ItemStack(Items.ENCHANTED_BOOK);
EnchantmentHelper.setEnchantments(enchMap, bookEnchant);
if (item.isBookEnchantable(ingredient, bookEnchant)) {
perLevelBooks.add(bookEnchant);
ItemStack withEnchant = ingredient.copy();
EnchantmentHelper.setEnchantments(enchMap, withEnchant);
perLevelOutputs.add(withEnchant);
}
}
if (!perLevelBooks.isEmpty() && !perLevelOutputs.isEmpty()) {
anvilRecipes.add(factory.createAnvilRecipe(ingredient, perLevelBooks, perLevelOutputs));
count++;
}
}
}
}
}
registry.addRecipes(anvilRecipes, VanillaRecipeCategoryUid.ANVIL);
return count;
}
use of net.minecraft.enchantment.Enchantment in project EnderIO by SleepyTrousers.
the class DarkSteelUpgradeSubtypeInterpreter method apply.
@Override
@Nonnull
public String apply(ItemStack itemStack) {
if (itemStack == null) {
throw new NullPointerException("You want me to return something Nonnull for a null ItemStack? F.U.");
}
String result = DarkSteelRecipeManager.getUpgradesAsString(itemStack);
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(itemStack);
final List<Enchantment> keyList = new NNList<>(enchantments.keySet());
keyList.sort(new Comparator<Enchantment>() {
@Override
public int compare(Enchantment o1, Enchantment o2) {
return safeString(o1).compareTo(safeString(o2));
}
});
for (Enchantment enchantment : keyList) {
result += "/" + safeString(enchantment);
}
return "DS:" + result;
}
use of net.minecraft.enchantment.Enchantment in project EnderIO by SleepyTrousers.
the class TankRecipeCategory method register.
// -------------------------------------
public static void register(IModRegistry registry, IGuiHelper guiHelper) {
registry.addRecipeCategories(new TankRecipeCategory(guiHelper));
registry.addRecipeCategoryCraftingItem(new ItemStack(block_tank.getBlockNN(), 1, 0), TankRecipeCategory.UID);
registry.addRecipeCategoryCraftingItem(new ItemStack(block_tank.getBlockNN(), 1, 1), TankRecipeCategory.UID);
registry.addRecipeClickArea(GuiTank.class, 155, 42, 16, 16, TankRecipeCategory.UID);
long start = System.nanoTime();
Map<String, Fluid> fluids = FluidRegistry.getRegisteredFluids();
List<ItemStack> validItems = registry.getIngredientRegistry().getIngredients(ItemStack.class);
List<TankRecipeWrapper> result = new ArrayList<TankRecipeWrapper>();
for (ItemStack stack : validItems) {
ItemStack drainedStack = stack.copy();
IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(drainedStack);
if (fluidHandler != null) {
FluidStack drain = fluidHandler.drain(16000, true);
drainedStack = fluidHandler.getContainer();
// Log.debug("Draining a " + stack + " gives " + fluidString(drain) + " and " + drainedStack);
if (drain != null && drain.amount > 0) {
// filled container
result.add(new TankRecipeWrapper(null, drain, stack.copy(), drainedStack));
} else {
// empty container
for (Fluid fluid : fluids.values()) {
ItemStack filledStack = stack.copy();
fluidHandler = FluidUtil.getFluidHandler(filledStack);
if (fluidHandler != null) {
int filled = fluidHandler.fill(new FluidStack(fluid, 16000), true);
filledStack = fluidHandler.getContainer();
if (filled > 0) {
// Log.debug("Filling a " + stack + " with " + fluidString(new FluidStack(fluid, filled)) + " gives " + filledStack);
result.add(new TankRecipeWrapper(new FluidStack(fluid, filled), null, stack.copy(), filledStack));
}
}
}
}
}
}
// add mending recipes
Map<Enchantment, Integer> enchMap = Collections.singletonMap(Enchantments.MENDING, 1);
final int maxMendable = TileTank.xpToDurability(XpUtil.liquidToExperience(16000));
for (ItemStack stack : validItems) {
if (stack.isItemStackDamageable()) {
ItemStack enchantedStack;
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.MENDING, stack) > 0) {
enchantedStack = stack.copy();
} else if (Enchantments.MENDING.canApply(stack)) {
enchantedStack = stack.copy();
EnchantmentHelper.setEnchantments(enchMap, enchantedStack);
} else {
continue;
}
ItemStack damagedStack = enchantedStack.copy();
damagedStack.setItemDamage((damagedStack.getMaxDamage() * 3) / 4);
int damageMendable = Math.min(maxMendable, damagedStack.getItemDamage());
enchantedStack.setItemDamage(damagedStack.getItemDamage() - damageMendable);
if (damagedStack.getItemDamage() != enchantedStack.getItemDamage()) {
result.add(new TankRecipeWrapper(new FluidStack(Fluids.XP_JUICE.getFluid(), XpUtil.experienceToLiquid(TileTank.durabilityToXp(damageMendable))), null, damagedStack, enchantedStack));
}
}
}
long end = System.nanoTime();
registry.addRecipes(result, UID);
registry.getRecipeTransferRegistry().addRecipeTransferHandler(ContainerTank.class, TankRecipeCategory.UID, 0, 2, 3, 4 * 9);
Log.info(String.format("TankRecipeCategory: Added %d tank recipes to JEI in %.3f seconds.", result.size(), (end - start) / 1000000000d));
}
use of net.minecraft.enchantment.Enchantment in project BloodMagic by WayofTime.
the class ItemSentientArmour method setContainedArmourStack.
public void setContainedArmourStack(ItemStack newArmour, ItemStack previousArmour) {
if (newArmour == null || previousArmour == null) {
return;
}
NBTTagCompound tag = new NBTTagCompound();
previousArmour.writeToNBT(tag);
NBTTagCompound omegaTag = newArmour.getTagCompound();
if (omegaTag == null) {
omegaTag = new NBTTagCompound();
newArmour.setTagCompound(omegaTag);
}
omegaTag.setTag("armour", tag);
Map<Enchantment, Integer> enchantmentMap = EnchantmentHelper.getEnchantments(previousArmour);
EnchantmentHelper.setEnchantments(enchantmentMap, newArmour);
}
Aggregations