Created
September 25, 2019 14:19
-
-
Save matyklug18/9932ba976dffb730323da7fc2973ee1e 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 matyk.aqarium2.armor; | |
import java.util.Collection; | |
import java.util.Optional; | |
import java.util.UUID; | |
import com.google.common.collect.Multimap; | |
import matyk.aqarium2.eventHandler.EventHandler; | |
import matyk.aqarium2.main.Main; | |
import net.minecraft.client.renderer.entity.layers.LayerArmorBase; | |
import net.minecraft.entity.SharedMonsterAttributes; | |
import net.minecraft.entity.ai.attributes.AttributeModifier; | |
import net.minecraft.entity.ai.attributes.IAttribute; | |
import net.minecraft.init.SoundEvents; | |
import net.minecraft.inventory.EntityEquipmentSlot; | |
import net.minecraft.item.ItemArmor; | |
import net.minecraft.item.ItemStack; | |
import net.minecraftforge.common.util.EnumHelper; | |
public class RandomHelmet extends ItemArmor { | |
public RandomHelmet() { | |
super(EnumHelper.addArmorMaterial(Main.MODID + ":" + "random", Main.MODID + ":" + "random", 1, new int[] {1, 1, 1, 1}, 1, SoundEvents.ITEM_ARMOR_EQUIP_GENERIC, 1), 0, EntityEquipmentSlot.HEAD); | |
} | |
@Override | |
public ArmorMaterial getArmorMaterial() { | |
return super.getArmorMaterial(); | |
} | |
@Override | |
public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) { | |
final Multimap<String, AttributeModifier> modifiers = super.getAttributeModifiers(slot, stack); | |
if (slot == EntityEquipmentSlot.HEAD) { | |
if(EventHandler.list != null && stack.getTagCompound() != null) { | |
final UUID[] ARMOR_MODIFIERS = new UUID[] {UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"), UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D"), UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E"), UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150")}; | |
replaceModifier(modifiers, SharedMonsterAttributes.ARMOR, ARMOR_MODIFIERS[slot.getIndex()], EventHandler.list.get(stack.getTagCompound().getInteger("idOfOre")).armor); | |
} | |
} | |
return modifiers; | |
} | |
private void replaceModifier(Multimap<String, AttributeModifier> modifierMultimap, IAttribute attribute, UUID id, double multiplier) { | |
// Get the modifiers for the specified attribute | |
final Collection<AttributeModifier> modifiers = modifierMultimap.get(attribute.getName()); | |
// Find the modifier with the specified ID, if any | |
final Optional<AttributeModifier> modifierOptional = modifiers.stream().filter(attributeModifier -> attributeModifier.getID().equals(id)).findFirst(); | |
if (modifierOptional.isPresent()) { // If it exists, | |
final AttributeModifier modifier = modifierOptional.get(); | |
modifiers.remove(modifier); // Remove it | |
modifiers.add(new AttributeModifier(modifier.getID(), modifier.getName(), modifier.getAmount() * multiplier, modifier.getOperation())); // Add the new modifier | |
} | |
} | |
@Override | |
public int getColor(ItemStack stack) { | |
/*if(stack.getTagCompound() != null) | |
if(stack.getTagCompound().hasKey("idOfOre")) { | |
int rgb = EventHandler.list.get(stack.getTagCompound().getInteger("idOfOre")).red; | |
rgb = (rgb << 8) + EventHandler.list.get(stack.getTagCompound().getInteger("idOfOre")).green; | |
rgb = (rgb << 8) + EventHandler.list.get(stack.getTagCompound().getInteger("idOfOre")).blue; | |
return rgb; | |
}*/ | |
int rgb = 1; | |
rgb = (rgb << 8) + 255; | |
rgb = (rgb << 8) + 255; | |
return rgb; | |
} | |
@Override | |
public boolean hasOverlay(ItemStack stack) { | |
return true; | |
} | |
@Override | |
public boolean hasColor(ItemStack stack) { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment