/newcode/src/com/prupe/mcpatcher/cit/CITUtils18.java

https://bitbucket.org/prupe/mcpatcher · Java · 115 lines · 104 code · 10 blank · 1 comment · 30 complexity · 92ce33b91316f6131e484bfb68088a2d MD5 · raw file

  1. package com.prupe.mcpatcher.cit;
  2. import com.prupe.mcpatcher.MCLogger;
  3. import com.prupe.mcpatcher.MCPatcherUtils;
  4. import com.prupe.mcpatcher.ctm.CTMUtils;
  5. import com.prupe.mcpatcher.ctm.CTMUtils18;
  6. import com.prupe.mcpatcher.mal.item.ItemAPI;
  7. import com.prupe.mcpatcher.mal.resource.TexturePackAPI;
  8. import com.prupe.mcpatcher.mal.tile.FaceInfo;
  9. import net.minecraft.src.*;
  10. public class CITUtils18 {
  11. private static final MCLogger logger = MCLogger.getLogger(MCPatcherUtils.CUSTOM_ITEM_TEXTURES, "CIT");
  12. private static ItemStack currentItem;
  13. private static CTMUtils18 ctm;
  14. private static ItemOverride itemOverride;
  15. private static boolean renderingEnchantment;
  16. public static void preRender(ItemStack itemStack) {
  17. if (renderingEnchantment) {
  18. // rendering custom enchantment -- keep current state
  19. } else if (itemStack == null) {
  20. clear();
  21. } else if (itemStack.getItem() instanceof ItemBlock) {
  22. clear();
  23. ctm = CTMUtils18.getInstance();
  24. ctm.preRenderHeld(null, ((ItemBlock) itemStack.getItem()).getBlock(), itemStack.getItemDamage());
  25. } else {
  26. ctm = null;
  27. currentItem = itemStack;
  28. itemOverride = CITUtils.findItemOverride(itemStack);
  29. }
  30. }
  31. public static void postRender() {
  32. if (ctm != null) {
  33. ctm.clear();
  34. }
  35. clear();
  36. }
  37. public static ModelFace getModelFace(ModelFace origFace) {
  38. if (renderingEnchantment) {
  39. return FaceInfo.getFaceInfo(origFace).getNonAtlasFace();
  40. } else if (ctm != null) {
  41. int face = FaceInfo.getFaceInfo(origFace).getEffectiveFace();
  42. ctm.setDirection(face < 0 ? null : Direction.values()[face]);
  43. return ctm.getModelFace(origFace);
  44. } else if (itemOverride == null) {
  45. return origFace;
  46. } else {
  47. FaceInfo faceInfo = FaceInfo.getFaceInfo(origFace);
  48. TextureAtlasSprite newIcon = (TextureAtlasSprite) itemOverride.getReplacementIcon(faceInfo.getSprite());
  49. return faceInfo.getAltFace(newIcon);
  50. }
  51. }
  52. public static boolean renderEnchantments3D(RenderItemCustom renderItem, IModel model) {
  53. if (currentItem != null) {
  54. EnchantmentList enchantments = CITUtils.findEnchantments(currentItem);
  55. if (!enchantments.isEmpty()) {
  56. renderingEnchantment = true;
  57. Enchantment.beginOuter3D();
  58. for (int i = 0; i < enchantments.size(); i++) {
  59. Enchantment enchantment = enchantments.getEnchantment(i);
  60. float intensity = enchantments.getIntensity(i);
  61. if (intensity > 0.0f && enchantment.bindTexture(null)) {
  62. enchantment.begin(intensity);
  63. renderItem.renderItem1(model, -1, null);
  64. enchantment.end();
  65. }
  66. }
  67. Enchantment.endOuter3D();
  68. TexturePackAPI.bindTexture(TexturePackAPI.ITEMS_PNG);
  69. renderingEnchantment = false;
  70. }
  71. }
  72. return !CITUtils.useGlint;
  73. }
  74. public static ResourceLocation getArmorTexture(ResourceLocation origTexture, ItemStack itemStack, int slot) {
  75. ArmorOverride override = CITUtils.findArmorOverride(itemStack);
  76. if (override == null) {
  77. return origTexture;
  78. } else {
  79. return override.getReplacementTexture(origTexture);
  80. }
  81. }
  82. public static boolean renderArmorEnchantments(EntityLivingBase entity, ModelBase model, ItemStack itemStack, int slot, float f1, float f2, float f3, float f4, float f5, float f6) {
  83. EnchantmentList enchantments = CITUtils.findEnchantments(itemStack);
  84. if (!enchantments.isEmpty()) {
  85. Enchantment.beginOuter3D();
  86. for (int i = 0; i < enchantments.size(); i++) {
  87. Enchantment enchantment = enchantments.getEnchantment(i);
  88. float intensity = enchantments.getIntensity(i);
  89. if (intensity > 0.0f && enchantment.bindTexture(null)) {
  90. enchantment.begin(intensity);
  91. model.render(entity, f1, f2, f3, f4, f5, f6);
  92. enchantment.end();
  93. }
  94. }
  95. Enchantment.endOuter3D();
  96. }
  97. return !CITUtils.useGlint;
  98. }
  99. static void clear() {
  100. currentItem = null;
  101. ctm = null;
  102. itemOverride = null;
  103. renderingEnchantment = false;
  104. }
  105. }