Skip to content

Commit

Permalink
Animated effects are back!
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Oct 9, 2014
1 parent 3427ed6 commit ca786eb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 43 deletions.
40 changes: 4 additions & 36 deletions src/main/java/tconstruct/library/tools/ToolCore.java
Expand Up @@ -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;
}
Expand Down
62 changes: 55 additions & 7 deletions src/main/java/tconstruct/library/weaponry/ProjectileWeapon.java
Expand Up @@ -209,6 +209,7 @@ public void onPlayerStoppedUsing (ItemStack weapon, World world, EntityPlayer pl
public HashMap<Integer, IIcon[]> animationHandleIcons = new HashMap<Integer, IIcon[]>();
public HashMap<Integer, IIcon[]> animationAccessoryIcons = new HashMap<Integer, IIcon[]>();
public HashMap<Integer, IIcon[]> animationExtraIcons = new HashMap<Integer, IIcon[]>();
public HashMap<Integer, IIcon[]> animationEffectIcons = new HashMap<Integer, IIcon[]>();

// todo: animated effects

Expand All @@ -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);
Expand Down Expand Up @@ -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<Integer, String> 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<Integer, String> textures, HashMap<Integer, IIcon[]> icons, IIconRegister iconRegister, String standard)
Expand Down

0 comments on commit ca786eb

Please sign in to comment.