Created
February 27, 2016 01:18
-
-
Save Vazkii/d88a3e7b871f030d1c99 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package vazkii.ikwila; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Iterator; | |
import java.util.List; | |
import java.util.Map.Entry; | |
import java.util.UUID; | |
import com.google.common.collect.Multimap; | |
import cpw.mods.fml.common.Mod; | |
import cpw.mods.fml.common.Mod.EventHandler; | |
import cpw.mods.fml.common.event.FMLPreInitializationEvent; | |
import cpw.mods.fml.common.eventhandler.EventPriority; | |
import cpw.mods.fml.common.eventhandler.SubscribeEvent; | |
import cpw.mods.fml.relauncher.Side; | |
import cpw.mods.fml.relauncher.SideOnly; | |
import net.minecraft.enchantment.Enchantment; | |
import net.minecraft.enchantment.EnchantmentHelper; | |
import net.minecraft.entity.EnumCreatureAttribute; | |
import net.minecraft.entity.ai.attributes.AttributeModifier; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.init.Items; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.nbt.NBTTagList; | |
import net.minecraft.util.EnumChatFormatting; | |
import net.minecraft.util.StatCollector; | |
import net.minecraftforge.common.MinecraftForge; | |
import net.minecraftforge.common.config.Configuration; | |
import net.minecraftforge.event.entity.player.ItemTooltipEvent; | |
@Mod(modid="ikwila", name="IKWILA", version="1.0") | |
public class IKWILA { | |
List<String> ignores; | |
@EventHandler | |
public void preInit(FMLPreInitializationEvent event) { | |
Configuration config = new Configuration(event.getSuggestedConfigurationFile()); | |
config.load(); | |
ignores = Arrays.asList(config.getStringList("Items/Mods to block", Configuration.CATEGORY_GENERAL, new String[0], "")); | |
if(!config.hasChanged()) | |
config.save(); | |
MinecraftForge.EVENT_BUS.register(this); | |
} | |
@SubscribeEvent(priority = EventPriority.LOWEST) | |
public void onTooltip(ItemTooltipEvent event) { | |
String id = Item.itemRegistry.getNameForObject(event.itemStack.getItem()); | |
String[] tokens = id.split(":"); | |
if(ignores.contains(tokens[0]) || ignores.contains(id)) { | |
event.toolTip.clear(); | |
event.toolTip.addAll(getBareTooltip(event.itemStack, event.entityPlayer, event.showAdvancedItemTooltips)); | |
} | |
} | |
// Vanilla copypasta | |
protected static final UUID field_111210_e = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF"); | |
@SideOnly(Side.CLIENT) | |
public List getBareTooltip(ItemStack stack, EntityPlayer p_82840_1_, boolean p_82840_2_) | |
{ | |
ArrayList arraylist = new ArrayList(); | |
String s = stack.getDisplayName(); | |
if (stack.hasDisplayName()) | |
{ | |
s = EnumChatFormatting.ITALIC + s + EnumChatFormatting.RESET; | |
} | |
int i; | |
if (p_82840_2_) | |
{ | |
String s1 = ""; | |
if (s.length() > 0) | |
{ | |
s = s + " ("; | |
s1 = ")"; | |
} | |
i = Item.getIdFromItem(stack.getItem()); | |
if (stack.getHasSubtypes()) | |
{ | |
s = s + String.format("#%04d/%d%s", new Object[] {Integer.valueOf(i), Integer.valueOf(stack.getItemDamage()), s1}); | |
} | |
else | |
{ | |
s = s + String.format("#%04d%s", new Object[] {Integer.valueOf(i), s1}); | |
} | |
} | |
else if (!stack.hasDisplayName() && stack.getItem() == Items.filled_map) | |
{ | |
s = s + " #" + stack.getItemDamage(); | |
} | |
arraylist.add(s); | |
// stack.getItem().addInformation(stack, p_82840_1_, arraylist, p_82840_2_); This would be the info added by the item, we don't want it | |
if (stack.hasTagCompound()) | |
{ | |
NBTTagList nbttaglist = stack.getEnchantmentTagList(); | |
if (nbttaglist != null) | |
{ | |
for (i = 0; i < nbttaglist.tagCount(); ++i) | |
{ | |
short short1 = nbttaglist.getCompoundTagAt(i).getShort("id"); | |
short short2 = nbttaglist.getCompoundTagAt(i).getShort("lvl"); | |
if (Enchantment.enchantmentsList[short1] != null) | |
{ | |
arraylist.add(Enchantment.enchantmentsList[short1].getTranslatedName(short2)); | |
} | |
} | |
} | |
if (stack.stackTagCompound.hasKey("display", 10)) | |
{ | |
NBTTagCompound nbttagcompound = stack.stackTagCompound.getCompoundTag("display"); | |
if (nbttagcompound.hasKey("color", 3)) | |
{ | |
if (p_82840_2_) | |
{ | |
arraylist.add("Color: #" + Integer.toHexString(nbttagcompound.getInteger("color")).toUpperCase()); | |
} | |
else | |
{ | |
arraylist.add(EnumChatFormatting.ITALIC + StatCollector.translateToLocal("item.dyed")); | |
} | |
} | |
if (nbttagcompound.func_150299_b("Lore") == 9) | |
{ | |
NBTTagList nbttaglist1 = nbttagcompound.getTagList("Lore", 8); | |
if (nbttaglist1.tagCount() > 0) | |
{ | |
for (int j = 0; j < nbttaglist1.tagCount(); ++j) | |
{ | |
arraylist.add(EnumChatFormatting.DARK_PURPLE + "" + EnumChatFormatting.ITALIC + nbttaglist1.getStringTagAt(j)); | |
} | |
} | |
} | |
} | |
} | |
Multimap multimap = stack.getAttributeModifiers(); | |
if (!multimap.isEmpty()) | |
{ | |
arraylist.add(""); | |
Iterator iterator = multimap.entries().iterator(); | |
while (iterator.hasNext()) | |
{ | |
Entry entry = (Entry)iterator.next(); | |
AttributeModifier attributemodifier = (AttributeModifier)entry.getValue(); | |
double d0 = attributemodifier.getAmount(); | |
if (attributemodifier.getID() == field_111210_e) | |
{ | |
d0 += (double)EnchantmentHelper.func_152377_a(stack, EnumCreatureAttribute.UNDEFINED); | |
} | |
double d1; | |
if (attributemodifier.getOperation() != 1 && attributemodifier.getOperation() != 2) | |
{ | |
d1 = d0; | |
} | |
else | |
{ | |
d1 = d0 * 100.0D; | |
} | |
if (d0 > 0.0D) | |
{ | |
arraylist.add(EnumChatFormatting.BLUE + StatCollector.translateToLocalFormatted("attribute.modifier.plus." + attributemodifier.getOperation(), new Object[] {stack.field_111284_a.format(d1), StatCollector.translateToLocal("attribute.name." + (String)entry.getKey())})); | |
} | |
else if (d0 < 0.0D) | |
{ | |
d1 *= -1.0D; | |
arraylist.add(EnumChatFormatting.RED + StatCollector.translateToLocalFormatted("attribute.modifier.take." + attributemodifier.getOperation(), new Object[] {stack.field_111284_a.format(d1), StatCollector.translateToLocal("attribute.name." + (String)entry.getKey())})); | |
} | |
} | |
} | |
if (stack.hasTagCompound() && stack.getTagCompound().getBoolean("Unbreakable")) | |
{ | |
arraylist.add(EnumChatFormatting.BLUE + StatCollector.translateToLocal("item.unbreakable")); | |
} | |
if (p_82840_2_ && stack.isItemDamaged()) | |
{ | |
arraylist.add("Durability: " + (stack.getMaxDamage() - stack.getItemDamageForDisplay()) + " / " + stack.getMaxDamage()); | |
} | |
return arraylist; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment