diff --git a/src/main/java/tconstruct/library/tools/ToolCore.java b/src/main/java/tconstruct/library/tools/ToolCore.java index 996d1106cec..61c824f965d 100644 --- a/src/main/java/tconstruct/library/tools/ToolCore.java +++ b/src/main/java/tconstruct/library/tools/ToolCore.java @@ -269,43 +269,11 @@ else if (renderPass == 3) return getCorrectIcon(extraIcons, tags.getInteger("RenderExtra")); } // Effects - else + else if (renderPass <= 10) { - if (renderPass == getPartAmount()) - { - if (tags.hasKey("Effect1")) - return (effectIcons.get(tags.getInteger("Effect1"))); - } - - else if (renderPass == getPartAmount() + 1) - { - if (tags.hasKey("Effect2")) - return (effectIcons.get(tags.getInteger("Effect2"))); - } - - else if (renderPass == getPartAmount() + 2) - { - if (tags.hasKey("Effect3")) - return (effectIcons.get(tags.getInteger("Effect3"))); - } - - else if (renderPass == getPartAmount() + 3) - { - if (tags.hasKey("Effect4")) - return (effectIcons.get(tags.getInteger("Effect4"))); - } - - else if (renderPass == getPartAmount() + 4) - { - if (tags.hasKey("Effect5")) - return (effectIcons.get(tags.getInteger("Effect5"))); - } - - else if (renderPass == getPartAmount() + 5) - { - if (tags.hasKey("Effect6")) - return (effectIcons.get(tags.getInteger("Effect6"))); - } + String effect = "Effect" + (1 + renderPass - getPartAmount()); + if(tags.hasKey(effect)) + return effectIcons.get(tags.getInteger(effect)); } return blankSprite; } diff --git a/src/main/java/tconstruct/library/weaponry/ProjectileWeapon.java b/src/main/java/tconstruct/library/weaponry/ProjectileWeapon.java index d4a8e27ce14..39a81a67607 100644 --- a/src/main/java/tconstruct/library/weaponry/ProjectileWeapon.java +++ b/src/main/java/tconstruct/library/weaponry/ProjectileWeapon.java @@ -209,6 +209,7 @@ public void onPlayerStoppedUsing (ItemStack weapon, World world, EntityPlayer pl public HashMap animationHandleIcons = new HashMap(); public HashMap animationAccessoryIcons = new HashMap(); public HashMap animationExtraIcons = new HashMap(); + public HashMap animationEffectIcons = new HashMap(); // todo: animated effects @@ -226,18 +227,31 @@ protected boolean animateLayer(int renderPass) @Override public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) { - // animate? - if(!animateLayer(renderPass)) + NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); + + if(tags == null || renderPass > 10) return super.getIcon(stack, renderPass, player, usingItem, useRemaining); - if(usingItem == null || stack != usingItem || !stack.hasTagCompound()) + // are we drawing an effect? + if(renderPass >= getPartAmount()) { + // is the effect animated? + String effect = "Effect" + (1 + renderPass - getPartAmount()); + if(tags.hasKey(effect)) { + int index = tags.getInteger(effect); + if(animationEffectIcons.get(index) != null) + return getCorrectAnimationIcon(animationEffectIcons, index, getWindupProgress(usingItem, getMaxItemUseDuration(usingItem) - useRemaining)); + else + // non-animated + return effectIcons.get(index); + } return super.getIcon(stack, renderPass, player, usingItem, useRemaining); + } - NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); + // animate? + if(!animateLayer(renderPass)) + return super.getIcon(stack, renderPass, player, usingItem, useRemaining); - // effects aren't animated - // todo: make effects animated - if(renderPass >= getPartAmount() || tags == null) + if(usingItem == null || stack != usingItem || !stack.hasTagCompound()) return super.getIcon(stack, renderPass, player, usingItem, useRemaining); float progress = getWindupProgress(usingItem, getMaxItemUseDuration(usingItem) - useRemaining); @@ -274,6 +288,40 @@ public void registerIcons(IIconRegister iconRegister) { addAnimationIcons(handleStrings, animationHandleIcons, iconRegister, getIconSuffix(2)); addAnimationIcons(accessoryStrings, animationAccessoryIcons, iconRegister, getIconSuffix(3)); addAnimationIcons(extraStrings, animationExtraIcons, iconRegister, getIconSuffix(4)); + + // animated effects... + // find out the longest animation + int count = 0; + if(animationHeadIcons.get(-1) != null) + count = Math.max(count, animationHeadIcons.get(-1).length); + if(animationHandleIcons.get(-1) != null) + count = Math.max(count, animationHandleIcons.get(-1).length); + if(animationAccessoryIcons.get(-1) != null) + count = Math.max(count, animationAccessoryIcons.get(-1).length); + if(animationExtraIcons.get(-1) != null) + count = Math.max(count, animationExtraIcons.get(-1).length); + + + for(Map.Entry entry : effectStrings.entrySet()) + { + IIcon[] anims = new IIcon[count]; + boolean empty = true; + for(int i = 0; i < count; i++) { + String tex = entry.getValue() + "_" + (i+1); + if (TextureHelper.itemTextureExists(tex)) { + anims[i] = iconRegister.registerIcon(tex); + empty = false; + } + } + if(!empty) + animationEffectIcons.put(entry.getKey(), anims); + } + + // default for effects is blank + IIcon[] anims = new IIcon[count]; + for(int i = 0; i < count; i++) + anims[i] = blankSprite; + animationEffectIcons.put(-1, anims); } private void addAnimationIcons(HashMap textures, HashMap icons, IIconRegister iconRegister, String standard)