Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package p455w0rd.p455w0rdsthings.items;
- import java.util.EnumMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import com.google.common.collect.Multimap;
- import com.mojang.realmsclient.gui.ChatFormatting;
- import net.minecraft.client.model.ModelBiped;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.SharedMonsterAttributes;
- import net.minecraft.entity.ai.attributes.AttributeModifier;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.MobEffects;
- import net.minecraft.inventory.EntityEquipmentSlot;
- import net.minecraft.item.ItemArmor;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.DamageSource;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.text.TextFormatting;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- import p455w0rd.p455w0rdsthings.Globals;
- import p455w0rd.p455w0rdsthings.Globals.Upgrades;
- import p455w0rd.p455w0rdsthings.ModItems;
- import p455w0rd.p455w0rdsthings.client.model.ModelCarbonArmor;
- import p455w0rd.p455w0rdsthings.util.ItemUtils;
- import p455w0rd.p455w0rdsthings.util.PotionUtils;
- public class ItemCarbonArmor extends ItemTeslaArmor {
- protected Map<EntityEquipmentSlot, ModelBiped> models = null;
- private static 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")
- };
- public ItemCarbonArmor(ItemArmor.ArmorMaterial materialIn, EntityEquipmentSlot slot, String itemName) {
- super(materialIn, slot, 1000000, 10000, itemName);
- addPropertyOverride(new ResourceLocation("jetplate"), (stack, world, entity) -> slot == EntityEquipmentSlot.CHEST && ItemUtils.isUpgradeEnabled(stack, Upgrades.FLIGHT) ? 1F : 0F);
- addPropertyOverride(new ResourceLocation("chestplatev2"), (stack, world, entity) -> !ItemUtils.isUpgradeEnabled(stack, Upgrades.FLIGHT) && ItemUtils.isUpgradeEnabled(stack, Upgrades.NONE) ? 1F : 0F);
- addPropertyOverride(new ResourceLocation("helmetv2"), (stack, world, entity) -> slot == EntityEquipmentSlot.HEAD && ItemUtils.isUpgradeEnabled(stack, Upgrades.NONE) ? 1F : 0F);
- addPropertyOverride(new ResourceLocation("bootsv2"), (stack, world, entity) -> slot == EntityEquipmentSlot.FEET && ItemUtils.isUpgradeEnabled(stack, Upgrades.NONE) ? 1F : 0F);
- }
- @Override
- public int getMaxDamage(ItemStack is) {
- return ItemUtils.isUpgraded(is, armorType) ? 0 : super.getMaxDamage(is);
- }
- @SideOnly(Side.CLIENT)
- public boolean hasEffect(ItemStack stack) {
- return ItemUtils.isUpgraded(stack, this.armorType);
- }
- @SideOnly(Side.CLIENT)
- @Override
- public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
- if (ItemUtils.isItemUpgradeActive(stack, armorType)) {
- tooltip.clear();
- String name = stack.getDisplayName();
- tooltip.add(TextFormatting.GREEN + "" + TextFormatting.ITALIC + "Emerald Infused " + name);
- }
- if (ItemUtils.isUpgraded(stack, this.armorType)) {
- List<Upgrades> upgradeList = ItemUtils.getActiveUpgrades(stack, armorType);
- tooltip.add("");
- tooltip.add(TextFormatting.WHITE + "Active Upgrade" + (upgradeList.size() == 1 ? "" : "s") + ": ");
- for (int i = 0; i < upgradeList.size(); i++) {
- tooltip.add(TextFormatting.BLUE + "" + TextFormatting.ITALIC + "" + upgradeList.get(i).getDesc());
- }
- if (playerIn.capabilities.isFlying) {
- if (this.armorType == EntityEquipmentSlot.CHEST && !playerIn.capabilities.isCreativeMode && !playerIn.isSpectator() && playerIn.getItemStackFromSlot(getEquipmentSlot()) == stack) {
- tooltip.add("");
- tooltip.add(TextFormatting.ITALIC + "Cannot remove chestplate while flying!");
- }
- }
- tooltip.add("");
- tooltip.add(ChatFormatting.DARK_AQUA + "" + ChatFormatting.ITALIC + "Tesla: " + this.getEnergyStored(stack) + "/" + this.getMaxEnergyStored(stack));
- }
- }
- @SideOnly(Side.CLIENT)
- public ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack stack, EntityEquipmentSlot armorSlot, ModelBiped original) {
- if (ItemUtils.isUpgraded(stack, this.armorType)) {
- ModelBiped model = getArmorModelForSlot(entityLiving, stack, armorSlot);
- if (model == null) {
- model = provideArmorModelForSlot(stack, armorSlot);
- }
- if (model != null) {
- model.setModelAttributes(original);
- return model;
- }
- }
- return super.getArmorModel(entityLiving, stack, armorSlot, original);
- }
- @SideOnly(Side.CLIENT)
- public ModelBiped getArmorModelForSlot(EntityLivingBase entity, ItemStack stack, EntityEquipmentSlot slot) {
- if (this.models == null) {
- this.models = new EnumMap<EntityEquipmentSlot, ModelBiped>(EntityEquipmentSlot.class);
- }
- return (ModelBiped) this.models.get(slot);
- }
- @SideOnly(Side.CLIENT)
- public ModelBiped provideArmorModelForSlot(ItemStack stack, EntityEquipmentSlot slot) {
- this.models.put(slot, new ModelCarbonArmor(slot));
- return (ModelBiped) this.models.get(slot);
- }
- @SideOnly(Side.CLIENT)
- public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String layer) {
- if (ItemUtils.isUpgraded(stack, this.armorType)) {
- return "p455w0rdsthings:textures/models/armor/model_carbon_armor.png";
- }
- if (slot == EntityEquipmentSlot.LEGS) {
- return "p455w0rdsthings:textures/models/armor/carbon_layer_2.png";
- }
- return "p455w0rdsthings:textures/models/armor/carbon_layer_1.png";
- }
- @Override
- public ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage, int slot) {
- if (!ItemUtils.isUpgraded(armor, armorType)) {
- return new ArmorProperties(0, damageReduceAmount, armor.getItemDamage());
- }
- if (source.isUnblockable() || this.getEnergyStored(armor) <= 0) {
- return new ArmorProperties(0, 0, 1);
- }
- double damageRatio = damageReduceAmount + (this.getEnergyStored(armor) > 0 ? getDamageReduction(slot) : 0);
- damageRatio /= 25D;
- return new ArmorProperties(0, damageRatio, (int) (damageRatio * 100) / 2);
- }
- @Override
- public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot equipmentSlot, ItemStack stack) {
- Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
- if (!ItemUtils.isUpgraded(stack, equipmentSlot)) {
- return multimap;
- }
- if (equipmentSlot == this.armorType) {
- boolean isPowered = this.getEnergyStored(stack) > 0;
- if (isPowered) {
- int toughnessBonus = 1;
- multimap.removeAll(SharedMonsterAttributes.ARMOR_TOUGHNESS.getAttributeUnlocalizedName());
- multimap.put(SharedMonsterAttributes.ARMOR_TOUGHNESS.getAttributeUnlocalizedName(), new AttributeModifier(ARMOR_MODIFIERS[equipmentSlot.getIndex()], "Armor toughness", toughness + toughnessBonus, 0));
- int powerBonus = getDamageReduction(equipmentSlot.getIndex());
- multimap.removeAll(SharedMonsterAttributes.ARMOR.getAttributeUnlocalizedName());
- multimap.put(SharedMonsterAttributes.ARMOR.getAttributeUnlocalizedName(), new AttributeModifier(ARMOR_MODIFIERS[equipmentSlot.getIndex()], "Armor modifier", damageReduceAmount + powerBonus, 0));
- }
- }
- return multimap;
- }
- @Override
- protected int getDamageReduction(int slot) {
- int dmg = 0;
- switch (slot) {
- case 0:
- dmg = 3;
- break;
- case 1:
- dmg = 9;
- break;
- case 2:
- dmg = 6;
- break;
- case 3:
- dmg = 2;
- break;
- }
- return dmg;
- }
- @Override
- public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
- ItemStack helmet = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
- ItemStack chest = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
- ItemStack leggings = player.getItemStackFromSlot(EntityEquipmentSlot.LEGS);
- ItemStack boots = player.getItemStackFromSlot(EntityEquipmentSlot.FEET);
- if (chest != null && chest.getItem() == ModItems.carbonChestplate && ItemUtils.isItemUpgradeActive(chest, EntityEquipmentSlot.CHEST)) {
- Globals.CARBONCHESTPLATE_ISEQUIPPED = true;
- player.capabilities.allowFlying = true;
- }
- if (helmet != null && helmet.getItem() == ModItems.carbonHelmet && ItemUtils.isItemUpgradeActive(helmet, EntityEquipmentSlot.HEAD)) {
- Globals.CARBONHELMET_ISEQUIPPED = true;
- PotionUtils.effectPlayer(player, MobEffects.NIGHT_VISION, 1);
- }
- if (leggings != null && leggings.getItem() == ModItems.carbonLeggings && ItemUtils.isItemUpgradeActive(leggings, EntityEquipmentSlot.LEGS)) {
- Globals.CARBONLEGGINGS_ISEQUIPPED = true;
- PotionUtils.effectPlayer(player, MobEffects.SPEED, 1);
- }
- if (boots != null && boots.getItem() == ModItems.carbonBoots && ItemUtils.isItemUpgradeActive(boots, EntityEquipmentSlot.FEET)) {
- Globals.CARBONBOOTS_ISEQUIPPED = true;
- if (player.worldObj.isRemote) {
- player.stepHeight = 1.0F;
- }
- }
- }
- @Override
- public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
- EntityPlayer player = (EntityPlayer) entityIn;
- ItemStack helmet = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
- ItemStack chest = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
- ItemStack leggings = player.getItemStackFromSlot(EntityEquipmentSlot.LEGS);
- ItemStack boots = player.getItemStackFromSlot(EntityEquipmentSlot.FEET);
- if (player.capabilities.isCreativeMode || player.isSpectator()) {
- player.capabilities.allowFlying = true;
- }
- if (helmet == null || helmet.getItem() != ModItems.carbonHelmet || !ItemUtils.isItemUpgradeActive(helmet, EntityEquipmentSlot.HEAD)) {
- if (Globals.CARBONHELMET_ISEQUIPPED) {
- Globals.CARBONHELMET_ISEQUIPPED = false;
- if (PotionUtils.isPotionActive(player, MobEffects.NIGHT_VISION)) {
- PotionUtils.clearPotionEffect(player, MobEffects.NIGHT_VISION, 1);
- }
- }
- }
- if ((chest == null || chest.getItem() != ModItems.carbonChestplate || !ItemUtils.isItemUpgradeActive(chest, EntityEquipmentSlot.CHEST)) && !player.capabilities.isCreativeMode && !player.isSpectator()) {
- if (Globals.CARBONCHESTPLATE_ISEQUIPPED) {
- Globals.CARBONCHESTPLATE_ISEQUIPPED = false;
- player.capabilities.isFlying = false;
- player.capabilities.allowFlying = false;
- }
- }
- if (leggings == null || leggings.getItem() != ModItems.carbonLeggings || !ItemUtils.isItemUpgradeActive(leggings, EntityEquipmentSlot.LEGS)) {
- if (Globals.CARBONLEGGINGS_ISEQUIPPED) {
- Globals.CARBONLEGGINGS_ISEQUIPPED = false;
- if (PotionUtils.isPotionActive(player, MobEffects.SPEED)) {
- PotionUtils.clearPotionEffect(player, MobEffects.SPEED, 0);
- }
- }
- }
- if (boots == null || boots.getItem() != ModItems.carbonBoots || !ItemUtils.isItemUpgradeActive(boots, EntityEquipmentSlot.FEET)) {
- if (Globals.CARBONBOOTS_ISEQUIPPED) {
- Globals.CARBONBOOTS_ISEQUIPPED = false;
- if (player.stepHeight != 0.6F) {
- player.stepHeight = 0.6F;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement