-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started to implement an animation predicate system, added player mode…
…l and animation files
- Loading branch information
Goodbird
committed
Dec 31, 2024
1 parent
39cbc74
commit 22e4725
Showing
20 changed files
with
3,840 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/goodbird/playeranimlib/client/control/PredicateRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.goodbird.playeranimlib.client.control; | ||
|
||
import com.goodbird.playeranimlib.client.control.event.PredicateModifyEvent; | ||
import com.goodbird.playeranimlib.client.control.predicate.IPlayerAnimationPredicate; | ||
import com.goodbird.playeranimlib.client.control.event.PredicateRegisterEvent; | ||
import com.goodbird.playeranimlib.client.control.predicate.builtin.DefaultPredicate; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraftforge.common.MinecraftForge; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class PredicateRegistry { | ||
private static final Map<ResourceLocation, IPlayerAnimationPredicate> registry = new HashMap<>(); | ||
|
||
public static void register(ResourceLocation resourceLocation, IPlayerAnimationPredicate predicate){ | ||
registry.put(resourceLocation, predicate); | ||
} | ||
|
||
public static IPlayerAnimationPredicate getPredicate(ResourceLocation resourceLocation){ | ||
return registry.computeIfAbsent(resourceLocation, (resLoc)->registry.get(new ResourceLocation("playeranimlib", "default"))); | ||
} | ||
|
||
public static void init(){ | ||
register(new ResourceLocation("playeranimlib", "default"), new DefaultPredicate()); | ||
MinecraftForge.EVENT_BUS.post(new PredicateRegisterEvent()); | ||
MinecraftForge.EVENT_BUS.post(new PredicateModifyEvent()); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/goodbird/playeranimlib/client/control/event/PlayerAnimationEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.goodbird.playeranimlib.client.control.event; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
import software.bernie.geckolib3.core.controller.AnimationController; | ||
|
||
public class PlayerAnimationEvent { | ||
private final EntityPlayer animatable; | ||
public double animationTick; | ||
private final float limbSwing; | ||
private final float limbSwingAmount; | ||
private final float partialTick; | ||
protected AnimationController controller; | ||
|
||
public PlayerAnimationEvent(EntityPlayer animatable, float limbSwing, float limbSwingAmount, float partialTick) { | ||
this.animatable = animatable; | ||
this.limbSwing = limbSwing; | ||
this.limbSwingAmount = limbSwingAmount; | ||
this.partialTick = partialTick; | ||
} | ||
|
||
public double getAnimationTick() { | ||
return this.animationTick; | ||
} | ||
|
||
public EntityPlayer getAnimatable() { | ||
return this.animatable; | ||
} | ||
|
||
public float getLimbSwing() { | ||
return this.limbSwing; | ||
} | ||
|
||
public float getLimbSwingAmount() { | ||
return this.limbSwingAmount; | ||
} | ||
|
||
public float getPartialTick() { | ||
return this.partialTick; | ||
} | ||
|
||
public AnimationController getController() { | ||
return this.controller; | ||
} | ||
|
||
public void setController(AnimationController controller) { | ||
this.controller = controller; | ||
} | ||
} | ||
|
6 changes: 6 additions & 0 deletions
6
src/main/java/com/goodbird/playeranimlib/client/control/event/PredicateModifyEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.goodbird.playeranimlib.client.control.event; | ||
|
||
import cpw.mods.fml.common.eventhandler.Event; | ||
|
||
public class PredicateModifyEvent extends Event { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/goodbird/playeranimlib/client/control/event/PredicateRegisterEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.goodbird.playeranimlib.client.control.event; | ||
|
||
import cpw.mods.fml.common.eventhandler.Event; | ||
|
||
public class PredicateRegisterEvent extends Event { | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
.../java/com/goodbird/playeranimlib/client/control/predicate/BuilderControlledPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.goodbird.playeranimlib.client.control.predicate; | ||
|
||
import com.goodbird.playeranimlib.client.control.event.PlayerAnimationEvent; | ||
import com.goodbird.playeranimlib.mixin.IEntityPlayer; | ||
import software.bernie.geckolib3.core.AnimationState; | ||
import software.bernie.geckolib3.core.builder.AnimationBuilder; | ||
|
||
public class BuilderControlledPredicate implements IPlayerAnimationPredicate { | ||
|
||
private String name; | ||
|
||
public BuilderControlledPredicate(String name){ | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public AnimationBuilder getAnimation(PlayerAnimationEvent animationEvent) { | ||
AnimationBuilder builder = ((IEntityPlayer)animationEvent.getAnimatable()).getBuilderByName(name); | ||
if(builder==null) return null; | ||
if(animationEvent.getController().currentAnimationBuilder==builder && animationEvent.getController().getAnimationState() == AnimationState.Stopped){ | ||
((IEntityPlayer)animationEvent.getAnimatable()).setBuilderByName(name, null); | ||
return null; | ||
} | ||
return builder; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...n/java/com/goodbird/playeranimlib/client/control/predicate/IPlayerAnimationPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.goodbird.playeranimlib.client.control.predicate; | ||
|
||
import com.goodbird.playeranimlib.client.control.event.PlayerAnimationEvent; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import software.bernie.geckolib3.core.PlayState; | ||
import software.bernie.geckolib3.core.builder.AnimationBuilder; | ||
import software.bernie.geckolib3.core.controller.AnimationController; | ||
import software.bernie.geckolib3.core.event.predicate.AnimationEvent; | ||
|
||
public interface IPlayerAnimationPredicate extends AnimationController.IAnimationPredicate { | ||
|
||
default PlayState test(AnimationEvent animationEvent){ | ||
PlayerAnimationEvent event = new PlayerAnimationEvent( | ||
(EntityPlayer) animationEvent.getAnimatable(), | ||
animationEvent.getLimbSwing(), | ||
animationEvent.getLimbSwingAmount(), | ||
animationEvent.getPartialTick() | ||
); | ||
|
||
animationEvent.getController().setAnimation(getAnimation(event)); | ||
return PlayState.CONTINUE; | ||
} | ||
|
||
AnimationBuilder getAnimation(PlayerAnimationEvent animationEvent); | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/goodbird/playeranimlib/client/control/predicate/LayeredPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.goodbird.playeranimlib.client.control.predicate; | ||
|
||
import com.goodbird.playeranimlib.client.control.event.PlayerAnimationEvent; | ||
import com.google.common.collect.Lists; | ||
import software.bernie.geckolib3.core.builder.AnimationBuilder; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class LayeredPredicate implements IPlayerAnimationPredicate{ | ||
private final ArrayList<IPlayerAnimationPredicate> layers = new ArrayList<>(); | ||
private String name = ""; | ||
private AnimationBuilder defaultAnim; | ||
|
||
public LayeredPredicate(String name){ | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public AnimationBuilder getAnimation(PlayerAnimationEvent animationEvent) { | ||
for(IPlayerAnimationPredicate predicate : Lists.reverse(layers)){ | ||
AnimationBuilder anim = predicate.getAnimation(animationEvent); | ||
if(anim!=null){ | ||
return anim; | ||
} | ||
} | ||
return defaultAnim; | ||
} | ||
|
||
public LayeredPredicate addLayer(IPlayerAnimationPredicate predicate){ | ||
layers.add(predicate); | ||
return this; | ||
} | ||
|
||
public ArrayList<IPlayerAnimationPredicate> getLayers(){ | ||
return layers; | ||
} | ||
|
||
public String getName(){ | ||
return name; | ||
} | ||
|
||
public AnimationBuilder getDefaultAnim() { | ||
return defaultAnim; | ||
} | ||
|
||
public void setDefaultAnim(AnimationBuilder defaultAnim) { | ||
this.defaultAnim = defaultAnim; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...in/java/com/goodbird/playeranimlib/client/control/predicate/builtin/DefaultPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.goodbird.playeranimlib.client.control.predicate.builtin; | ||
|
||
import com.goodbird.playeranimlib.client.control.predicate.BuilderControlledPredicate; | ||
import com.goodbird.playeranimlib.client.control.predicate.LayeredPredicate; | ||
import com.goodbird.playeranimlib.client.control.predicate.builtin.parts.IdlePosePredicate; | ||
import com.goodbird.playeranimlib.client.control.predicate.builtin.parts.WalkPredicate; | ||
import software.bernie.geckolib3.core.builder.AnimationBuilder; | ||
|
||
public class DefaultPredicate extends LayeredPredicate { | ||
public DefaultPredicate() { | ||
super("default"); | ||
setDefaultAnim(new AnimationBuilder().loop("idle")); | ||
addLayer(new LayeredPredicate("idle_random").addLayer(new BuilderControlledPredicate("item_random"))); | ||
addLayer(new IdlePosePredicate()); | ||
addLayer(new WalkPredicate()); | ||
addLayer(new LayeredPredicate("item_use").addLayer(new BuilderControlledPredicate("item_use"))); | ||
addLayer(new LayeredPredicate("manual").addLayer(new BuilderControlledPredicate("manual"))); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
.../com/goodbird/playeranimlib/client/control/predicate/builtin/parts/IdlePosePredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.goodbird.playeranimlib.client.control.predicate.builtin.parts; | ||
|
||
import com.goodbird.playeranimlib.client.control.event.PlayerAnimationEvent; | ||
import com.goodbird.playeranimlib.client.control.predicate.LayeredPredicate; | ||
import net.minecraft.item.ItemBlock; | ||
import software.bernie.geckolib3.core.builder.AnimationBuilder; | ||
|
||
public class IdlePosePredicate extends LayeredPredicate { | ||
public IdlePosePredicate() { | ||
super("idle_pose"); | ||
addLayer(this::holdBlockAnimation); | ||
addLayer(this::swimAnimation); | ||
addLayer(this::sleepAnimation); | ||
} | ||
|
||
public AnimationBuilder holdBlockAnimation(PlayerAnimationEvent animationEvent) { | ||
if(animationEvent.getAnimatable().getHeldItem()!=null && animationEvent.getAnimatable().getHeldItem().getItem() instanceof ItemBlock){ | ||
return new AnimationBuilder().loop("hold_block"); | ||
} | ||
return null; | ||
} | ||
|
||
public AnimationBuilder swimAnimation(PlayerAnimationEvent animationEvent) { | ||
if(animationEvent.getAnimatable().isInWater()){ | ||
return new AnimationBuilder().loop("idle_swim"); | ||
} | ||
return null; | ||
} | ||
|
||
public AnimationBuilder sleepAnimation(PlayerAnimationEvent animationEvent) { | ||
if(animationEvent.getAnimatable().isPlayerSleeping()){ | ||
return new AnimationBuilder().loop("sleep"); | ||
} | ||
return null; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...java/com/goodbird/playeranimlib/client/control/predicate/builtin/parts/WalkPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.goodbird.playeranimlib.client.control.predicate.builtin.parts; | ||
|
||
import com.goodbird.playeranimlib.client.control.event.PlayerAnimationEvent; | ||
import com.goodbird.playeranimlib.client.control.predicate.LayeredPredicate; | ||
import software.bernie.geckolib3.core.builder.AnimationBuilder; | ||
|
||
public class WalkPredicate extends LayeredPredicate { | ||
public WalkPredicate() { | ||
super("walk"); | ||
addLayer(this::defaultWalkAnimation); | ||
} | ||
|
||
public AnimationBuilder defaultWalkAnimation(PlayerAnimationEvent animationEvent) { | ||
if(Math.abs(animationEvent.getLimbSwingAmount())>0.15){ | ||
return new AnimationBuilder().loop("walk"); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.