Add player animation system!

- Hooks into ModelRenderer by wrapping it in an extended version that allows modification of angles after the model has set them
- Is compatible with pretty much everything, yay (even modded armour!)
- Adds property overrides to ItemWand so that gets animated too
- Adds a system for generating override models from a template at runtime so I don't have to duplicate all the wand models
- Tweaks particles and ray spells so they line up with the end of the newly-animated wand
- Fixes a long-standing bug where wand usage actions would stop immediately for all non-continuous spells
This commit is contained in:
Electroblob77
2020-05-09 20:17:15 +01:00
parent cf38a16f49
commit be250e218e
146 changed files with 1531 additions and 262 deletions
@@ -28,10 +28,7 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
@@ -91,6 +88,14 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem,
this.element = element;
setMaxDamage(this.tier.maxCharge);
WizardryRecipes.addToManaFlaskCharging(this);
// TODO: Hook to allow addon devs to have this override apply to their own animations
addPropertyOverride(new ResourceLocation("pointing"),
(s, w, e) -> e != null && e.getActiveItemStack() == s
&& (s.getItemUseAction() == SpellActions.POINT
|| s.getItemUseAction() == SpellActions.POINT_UP
|| s.getItemUseAction() == SpellActions.POINT_DOWN
|| s.getItemUseAction() == SpellActions.GRAPPLE
|| s.getItemUseAction() == SpellActions.SUMMON) ? 1 : 0);
}
@Override
@@ -381,6 +386,8 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem,
Spell spell = WandHelper.getCurrentSpell(stack);
if(!spell.isContinuous) return;
SpellModifiers modifiers;
if(WizardData.get(player) != null){
@@ -393,7 +400,7 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem,
// Continuous spells (these must check if they can be cast each tick since the mana changes)
// Don't call canCast when castingTick == 0 because we already did it in onItemRightClick
if(spell.isContinuous && (castingTick == 0 || canCast(stack, spell, player, player.getActiveHand(), castingTick, modifiers))){
if(castingTick == 0 || canCast(stack, spell, player, player.getActiveHand(), castingTick, modifiers)){
cast(stack, spell, player, player.getActiveHand(), castingTick, modifiers);
}else{
// Stops the casting if it was interrupted, either by events or because the wand ran out of mana
@@ -0,0 +1,63 @@
package electroblob.wizardry.item;
import electroblob.wizardry.Wizardry;
import net.minecraft.item.EnumAction;
import net.minecraftforge.common.util.EnumHelper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Defines and stores wizardry's custom {@link EnumAction}s.
* @author Electroblob
* @since Wizardry 4.3
*/
public final class SpellActions {
private static final List<EnumAction> spellActions = new ArrayList<>();
/** An {@link EnumAction} that causes the player to point in the direction they are looking. */
public static final EnumAction POINT = createAction("point");
/** An {@link EnumAction} that causes the player to point directly upwards. */
public static final EnumAction POINT_UP = createAction("point_up");
/** An {@link EnumAction} that causes the player to point down towards the ground. */
public static final EnumAction POINT_DOWN = createAction("point_down");
/** An {@link EnumAction} that causes the player to stretch both arms out and up slightly, as if summoning. */
public static final EnumAction SUMMON = createAction("summon");
/** An {@link EnumAction} that causes the player to hold their item vertically in front of them. */
public static final EnumAction THRUST = createAction("thrust");
/** An {@link EnumAction} that causes the player to point the item in use towards their other hand. */
public static final EnumAction IMBUE = createAction("imbue");
/** An {@link EnumAction} that causes the player to point towards their grappling target (see
* {@link electroblob.wizardry.spell.Grapple Grapple}). */
public static final EnumAction GRAPPLE = createAction("grapple");
private SpellActions(){} // No instances!
private static EnumAction createAction(String name){
return createAction(Wizardry.MODID, name);
}
/**
* Creates a new {@link EnumAction} with the given mod ID and name and adds it to the internal spell action list.
* Use this method to add extra spell actions for use with wizardry's player animator.
*
* @param modID The ID of the mod adding this action (avoids naming conflicts)
* @param name The name of the action (for Forge to use as the in-code name; should only contain characters that
* can be used in Java identifiers)
* @return The resulting {@code EnumAction}
*/
public static EnumAction createAction(String modID, String name){
// Using $ because this name will be used as the in-code name of the enum constant, and : wouldn't compile
EnumAction action = EnumHelper.addAction(modID + "$" + name);
spellActions.add(action);
return action;
}
/** Returns an unmodifiable list of all spell actions. */
public static List<EnumAction> getSpellActions(){
return Collections.unmodifiableList(spellActions);
}
}