Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.02 KB | None | 0 0
  1. package p455w0rd.p455w0rdsthings.items;
  2.  
  3. import java.util.EnumMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.UUID;
  7.  
  8. import com.google.common.collect.Multimap;
  9. import com.mojang.realmsclient.gui.ChatFormatting;
  10.  
  11. import net.minecraft.client.model.ModelBiped;
  12. import net.minecraft.entity.Entity;
  13. import net.minecraft.entity.EntityLivingBase;
  14. import net.minecraft.entity.SharedMonsterAttributes;
  15. import net.minecraft.entity.ai.attributes.AttributeModifier;
  16. import net.minecraft.entity.player.EntityPlayer;
  17. import net.minecraft.init.MobEffects;
  18. import net.minecraft.inventory.EntityEquipmentSlot;
  19. import net.minecraft.item.ItemArmor;
  20. import net.minecraft.item.ItemStack;
  21. import net.minecraft.util.DamageSource;
  22. import net.minecraft.util.ResourceLocation;
  23. import net.minecraft.util.text.TextFormatting;
  24. import net.minecraft.world.World;
  25. import net.minecraftforge.fml.relauncher.Side;
  26. import net.minecraftforge.fml.relauncher.SideOnly;
  27. import p455w0rd.p455w0rdsthings.Globals;
  28. import p455w0rd.p455w0rdsthings.Globals.Upgrades;
  29. import p455w0rd.p455w0rdsthings.ModItems;
  30. import p455w0rd.p455w0rdsthings.client.model.ModelCarbonArmor;
  31. import p455w0rd.p455w0rdsthings.util.ItemUtils;
  32. import p455w0rd.p455w0rdsthings.util.PotionUtils;
  33.  
  34. public class ItemCarbonArmor extends ItemTeslaArmor {
  35.  
  36. protected Map<EntityEquipmentSlot, ModelBiped> models = null;
  37. private static final UUID[] ARMOR_MODIFIERS = new UUID[] {
  38. 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")
  39. };
  40.  
  41. public ItemCarbonArmor(ItemArmor.ArmorMaterial materialIn, EntityEquipmentSlot slot, String itemName) {
  42. super(materialIn, slot, 1000000, 10000, itemName);
  43. addPropertyOverride(new ResourceLocation("jetplate"), (stack, world, entity) -> slot == EntityEquipmentSlot.CHEST && ItemUtils.isUpgradeEnabled(stack, Upgrades.FLIGHT) ? 1F : 0F);
  44. addPropertyOverride(new ResourceLocation("chestplatev2"), (stack, world, entity) -> !ItemUtils.isUpgradeEnabled(stack, Upgrades.FLIGHT) && ItemUtils.isUpgradeEnabled(stack, Upgrades.NONE) ? 1F : 0F);
  45. addPropertyOverride(new ResourceLocation("helmetv2"), (stack, world, entity) -> slot == EntityEquipmentSlot.HEAD && ItemUtils.isUpgradeEnabled(stack, Upgrades.NONE) ? 1F : 0F);
  46. addPropertyOverride(new ResourceLocation("bootsv2"), (stack, world, entity) -> slot == EntityEquipmentSlot.FEET && ItemUtils.isUpgradeEnabled(stack, Upgrades.NONE) ? 1F : 0F);
  47. }
  48.  
  49. @Override
  50. public int getMaxDamage(ItemStack is) {
  51. return ItemUtils.isUpgraded(is, armorType) ? 0 : super.getMaxDamage(is);
  52. }
  53.  
  54. @SideOnly(Side.CLIENT)
  55. public boolean hasEffect(ItemStack stack) {
  56. return ItemUtils.isUpgraded(stack, this.armorType);
  57. }
  58.  
  59. @SideOnly(Side.CLIENT)
  60. @Override
  61. public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
  62. if (ItemUtils.isItemUpgradeActive(stack, armorType)) {
  63. tooltip.clear();
  64. String name = stack.getDisplayName();
  65. tooltip.add(TextFormatting.GREEN + "" + TextFormatting.ITALIC + "Emerald Infused " + name);
  66. }
  67. if (ItemUtils.isUpgraded(stack, this.armorType)) {
  68. List<Upgrades> upgradeList = ItemUtils.getActiveUpgrades(stack, armorType);
  69. tooltip.add("");
  70. tooltip.add(TextFormatting.WHITE + "Active Upgrade" + (upgradeList.size() == 1 ? "" : "s") + ": ");
  71.  
  72. for (int i = 0; i < upgradeList.size(); i++) {
  73. tooltip.add(TextFormatting.BLUE + "" + TextFormatting.ITALIC + "" + upgradeList.get(i).getDesc());
  74. }
  75.  
  76. if (playerIn.capabilities.isFlying) {
  77. if (this.armorType == EntityEquipmentSlot.CHEST && !playerIn.capabilities.isCreativeMode && !playerIn.isSpectator() && playerIn.getItemStackFromSlot(getEquipmentSlot()) == stack) {
  78. tooltip.add("");
  79. tooltip.add(TextFormatting.ITALIC + "Cannot remove chestplate while flying!");
  80. }
  81. }
  82. tooltip.add("");
  83. tooltip.add(ChatFormatting.DARK_AQUA + "" + ChatFormatting.ITALIC + "Tesla: " + this.getEnergyStored(stack) + "/" + this.getMaxEnergyStored(stack));
  84. }
  85. }
  86.  
  87. @SideOnly(Side.CLIENT)
  88. public ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack stack, EntityEquipmentSlot armorSlot, ModelBiped original) {
  89. if (ItemUtils.isUpgraded(stack, this.armorType)) {
  90. ModelBiped model = getArmorModelForSlot(entityLiving, stack, armorSlot);
  91. if (model == null) {
  92. model = provideArmorModelForSlot(stack, armorSlot);
  93. }
  94. if (model != null) {
  95. model.setModelAttributes(original);
  96. return model;
  97. }
  98. }
  99. return super.getArmorModel(entityLiving, stack, armorSlot, original);
  100. }
  101.  
  102. @SideOnly(Side.CLIENT)
  103. public ModelBiped getArmorModelForSlot(EntityLivingBase entity, ItemStack stack, EntityEquipmentSlot slot) {
  104. if (this.models == null) {
  105. this.models = new EnumMap<EntityEquipmentSlot, ModelBiped>(EntityEquipmentSlot.class);
  106. }
  107. return (ModelBiped) this.models.get(slot);
  108. }
  109.  
  110. @SideOnly(Side.CLIENT)
  111. public ModelBiped provideArmorModelForSlot(ItemStack stack, EntityEquipmentSlot slot) {
  112. this.models.put(slot, new ModelCarbonArmor(slot));
  113. return (ModelBiped) this.models.get(slot);
  114. }
  115.  
  116. @SideOnly(Side.CLIENT)
  117. public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String layer) {
  118. if (ItemUtils.isUpgraded(stack, this.armorType)) {
  119. return "p455w0rdsthings:textures/models/armor/model_carbon_armor.png";
  120. }
  121. if (slot == EntityEquipmentSlot.LEGS) {
  122. return "p455w0rdsthings:textures/models/armor/carbon_layer_2.png";
  123. }
  124. return "p455w0rdsthings:textures/models/armor/carbon_layer_1.png";
  125. }
  126.  
  127. @Override
  128. public ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage, int slot) {
  129. if (!ItemUtils.isUpgraded(armor, armorType)) {
  130. return new ArmorProperties(0, damageReduceAmount, armor.getItemDamage());
  131. }
  132. if (source.isUnblockable() || this.getEnergyStored(armor) <= 0) {
  133. return new ArmorProperties(0, 0, 1);
  134. }
  135. double damageRatio = damageReduceAmount + (this.getEnergyStored(armor) > 0 ? getDamageReduction(slot) : 0);
  136. damageRatio /= 25D;
  137. return new ArmorProperties(0, damageRatio, (int) (damageRatio * 100) / 2);
  138. }
  139.  
  140. @Override
  141. public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot equipmentSlot, ItemStack stack) {
  142. Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
  143.  
  144. if (!ItemUtils.isUpgraded(stack, equipmentSlot)) {
  145. return multimap;
  146. }
  147.  
  148. if (equipmentSlot == this.armorType) {
  149. boolean isPowered = this.getEnergyStored(stack) > 0;
  150. if (isPowered) {
  151. int toughnessBonus = 1;
  152. multimap.removeAll(SharedMonsterAttributes.ARMOR_TOUGHNESS.getAttributeUnlocalizedName());
  153. multimap.put(SharedMonsterAttributes.ARMOR_TOUGHNESS.getAttributeUnlocalizedName(), new AttributeModifier(ARMOR_MODIFIERS[equipmentSlot.getIndex()], "Armor toughness", toughness + toughnessBonus, 0));
  154. int powerBonus = getDamageReduction(equipmentSlot.getIndex());
  155. multimap.removeAll(SharedMonsterAttributes.ARMOR.getAttributeUnlocalizedName());
  156. multimap.put(SharedMonsterAttributes.ARMOR.getAttributeUnlocalizedName(), new AttributeModifier(ARMOR_MODIFIERS[equipmentSlot.getIndex()], "Armor modifier", damageReduceAmount + powerBonus, 0));
  157. }
  158. }
  159. return multimap;
  160. }
  161.  
  162. @Override
  163. protected int getDamageReduction(int slot) {
  164. int dmg = 0;
  165. switch (slot) {
  166. case 0:
  167. dmg = 3;
  168. break;
  169. case 1:
  170. dmg = 9;
  171. break;
  172. case 2:
  173. dmg = 6;
  174. break;
  175. case 3:
  176. dmg = 2;
  177. break;
  178. }
  179. return dmg;
  180. }
  181.  
  182. @Override
  183. public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
  184. ItemStack helmet = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
  185. ItemStack chest = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
  186. ItemStack leggings = player.getItemStackFromSlot(EntityEquipmentSlot.LEGS);
  187. ItemStack boots = player.getItemStackFromSlot(EntityEquipmentSlot.FEET);
  188. if (chest != null && chest.getItem() == ModItems.carbonChestplate && ItemUtils.isItemUpgradeActive(chest, EntityEquipmentSlot.CHEST)) {
  189. Globals.CARBONCHESTPLATE_ISEQUIPPED = true;
  190. player.capabilities.allowFlying = true;
  191. }
  192. if (helmet != null && helmet.getItem() == ModItems.carbonHelmet && ItemUtils.isItemUpgradeActive(helmet, EntityEquipmentSlot.HEAD)) {
  193. Globals.CARBONHELMET_ISEQUIPPED = true;
  194. PotionUtils.effectPlayer(player, MobEffects.NIGHT_VISION, 1);
  195. }
  196. if (leggings != null && leggings.getItem() == ModItems.carbonLeggings && ItemUtils.isItemUpgradeActive(leggings, EntityEquipmentSlot.LEGS)) {
  197. Globals.CARBONLEGGINGS_ISEQUIPPED = true;
  198. PotionUtils.effectPlayer(player, MobEffects.SPEED, 1);
  199. }
  200. if (boots != null && boots.getItem() == ModItems.carbonBoots && ItemUtils.isItemUpgradeActive(boots, EntityEquipmentSlot.FEET)) {
  201. Globals.CARBONBOOTS_ISEQUIPPED = true;
  202. if (player.worldObj.isRemote) {
  203. player.stepHeight = 1.0F;
  204. }
  205. }
  206. }
  207.  
  208. @Override
  209. public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
  210. EntityPlayer player = (EntityPlayer) entityIn;
  211. ItemStack helmet = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
  212. ItemStack chest = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
  213. ItemStack leggings = player.getItemStackFromSlot(EntityEquipmentSlot.LEGS);
  214. ItemStack boots = player.getItemStackFromSlot(EntityEquipmentSlot.FEET);
  215. if (player.capabilities.isCreativeMode || player.isSpectator()) {
  216. player.capabilities.allowFlying = true;
  217. }
  218.  
  219. if (helmet == null || helmet.getItem() != ModItems.carbonHelmet || !ItemUtils.isItemUpgradeActive(helmet, EntityEquipmentSlot.HEAD)) {
  220. if (Globals.CARBONHELMET_ISEQUIPPED) {
  221. Globals.CARBONHELMET_ISEQUIPPED = false;
  222. if (PotionUtils.isPotionActive(player, MobEffects.NIGHT_VISION)) {
  223. PotionUtils.clearPotionEffect(player, MobEffects.NIGHT_VISION, 1);
  224. }
  225. }
  226. }
  227.  
  228. if ((chest == null || chest.getItem() != ModItems.carbonChestplate || !ItemUtils.isItemUpgradeActive(chest, EntityEquipmentSlot.CHEST)) && !player.capabilities.isCreativeMode && !player.isSpectator()) {
  229. if (Globals.CARBONCHESTPLATE_ISEQUIPPED) {
  230. Globals.CARBONCHESTPLATE_ISEQUIPPED = false;
  231. player.capabilities.isFlying = false;
  232. player.capabilities.allowFlying = false;
  233. }
  234. }
  235.  
  236. if (leggings == null || leggings.getItem() != ModItems.carbonLeggings || !ItemUtils.isItemUpgradeActive(leggings, EntityEquipmentSlot.LEGS)) {
  237. if (Globals.CARBONLEGGINGS_ISEQUIPPED) {
  238. Globals.CARBONLEGGINGS_ISEQUIPPED = false;
  239. if (PotionUtils.isPotionActive(player, MobEffects.SPEED)) {
  240. PotionUtils.clearPotionEffect(player, MobEffects.SPEED, 0);
  241. }
  242. }
  243. }
  244.  
  245. if (boots == null || boots.getItem() != ModItems.carbonBoots || !ItemUtils.isItemUpgradeActive(boots, EntityEquipmentSlot.FEET)) {
  246. if (Globals.CARBONBOOTS_ISEQUIPPED) {
  247. Globals.CARBONBOOTS_ISEQUIPPED = false;
  248. if (player.stepHeight != 0.6F) {
  249. player.stepHeight = 0.6F;
  250. }
  251. }
  252. }
  253. }
  254. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement