-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Potions: Extended, Enchantments: Extended
Yes, you read right. Potions and Enchantments are extended and both will be in the same update. Thank you zabi94 for helping me getting both of these extended, potions absolutely sucked extending and enchants had a single pain to deal with. So yeah, go for it damn it.
- Loading branch information
1 parent
3811159
commit d095e79
Showing
15 changed files
with
373 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/main/java/org/dimdev/jeid/mixin/core/MixinEnchantmentHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package org.dimdev.jeid.mixin.core; | ||
|
||
import com.google.common.collect.Maps; | ||
import net.minecraft.enchantment.Enchantment; | ||
import net.minecraft.enchantment.EnchantmentData; | ||
import net.minecraft.enchantment.EnchantmentHelper; | ||
import net.minecraft.init.Items; | ||
import net.minecraft.item.ItemEnchantedBook; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.nbt.NBTTagList; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
|
||
import java.util.Map; | ||
|
||
@Mixin(EnchantmentHelper.class) | ||
public class MixinEnchantmentHelper { | ||
|
||
/** @reason Mojang really likes modifying their original type into something else **/ | ||
@Overwrite | ||
public static int getEnchantmentLevel(Enchantment enchID, ItemStack stack) | ||
{ | ||
if (stack.isEmpty()) | ||
{ | ||
return 0; | ||
} | ||
else | ||
{ | ||
NBTTagList nbttaglist = stack.getEnchantmentTagList(); | ||
|
||
for (int i = 0; i < nbttaglist.tagCount(); ++i) | ||
{ | ||
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i); | ||
Enchantment enchantment = Enchantment.getEnchantmentByID(nbttagcompound.getInteger("id")); | ||
|
||
if (enchantment == enchID) | ||
{ | ||
return nbttagcompound.getShort("lvl"); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
} | ||
|
||
/** @reason Mojang really likes modifying their original type into something else **/ | ||
@Overwrite | ||
public static Map<Enchantment, Integer> getEnchantments(ItemStack stack) | ||
{ | ||
Map<Enchantment, Integer> map = Maps.<Enchantment, Integer>newLinkedHashMap(); | ||
NBTTagList nbttaglist = stack.getItem() == Items.ENCHANTED_BOOK ? ItemEnchantedBook.getEnchantments(stack) : stack.getEnchantmentTagList(); | ||
|
||
for (int i = 0; i < nbttaglist.tagCount(); ++i) | ||
{ | ||
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i); | ||
Enchantment enchantment = Enchantment.getEnchantmentByID(nbttagcompound.getInteger("id")); | ||
map.put(enchantment, Integer.valueOf(nbttagcompound.getShort("lvl"))); | ||
} | ||
|
||
return map; | ||
} | ||
|
||
@Overwrite | ||
public static void setEnchantments(Map<Enchantment, Integer> enchMap, ItemStack stack) | ||
{ | ||
NBTTagList nbttaglist = new NBTTagList(); | ||
|
||
for (Map.Entry<Enchantment, Integer> entry : enchMap.entrySet()) | ||
{ | ||
Enchantment enchantment = entry.getKey(); | ||
|
||
if (enchantment != null) | ||
{ | ||
NBTTagCompound nbttagcompound = new NBTTagCompound(); | ||
nbttagcompound.setInteger("id", Enchantment.getEnchantmentID(enchantment)); | ||
nbttagcompound.setShort("lvl", entry.getValue().shortValue()); | ||
nbttaglist.appendTag(nbttagcompound); | ||
|
||
if (stack.getItem() == Items.ENCHANTED_BOOK) { ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(enchantment, entry.getValue().shortValue())); } | ||
} | ||
} | ||
|
||
if (nbttaglist.isEmpty()) | ||
{ | ||
if (stack.hasTagCompound()) | ||
{ | ||
stack.getTagCompound().removeTag("ench"); | ||
} | ||
} | ||
else if (stack.getItem() != Items.ENCHANTED_BOOK) | ||
{ | ||
stack.setTagInfo("ench", nbttaglist); | ||
} | ||
} | ||
|
||
@Overwrite | ||
private static void applyEnchantmentModifier(EnchantmentHelper.IModifier modifier, ItemStack stack) | ||
{ | ||
if (!stack.isEmpty()) | ||
{ | ||
NBTTagList nbttaglist = stack.getEnchantmentTagList(); | ||
|
||
for (int i = 0; i < nbttaglist.tagCount(); ++i) | ||
{ | ||
if (Enchantment.getEnchantmentByID(nbttaglist.getCompoundTagAt(i).getInteger("id")) != null) | ||
{ | ||
modifier.calculateModifier(Enchantment.getEnchantmentByID(nbttaglist.getCompoundTagAt(i).getInteger("id")), nbttaglist.getCompoundTagAt(i).getShort("lvl")); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.