修改实体动画实现
This commit is contained in:
parent
457e5b4345
commit
6d5f8b2bfd
7 changed files with 79 additions and 71 deletions
|
@ -0,0 +1,9 @@
|
|||
package net.mcreator.target.entity;
|
||||
|
||||
public interface AnimatedEntity {
|
||||
String getSyncedAnimation();
|
||||
|
||||
void setAnimation(String animation);
|
||||
|
||||
void setAnimationProcedure(String procedure);
|
||||
}
|
|
@ -36,7 +36,7 @@ import software.bernie.geckolib.core.object.PlayState;
|
|||
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||
|
||||
// TODO 重写阔剑地雷
|
||||
public class ClaymoreEntity extends TamableAnimal implements GeoEntity {
|
||||
public class ClaymoreEntity extends TamableAnimal implements GeoEntity, AnimatedEntity {
|
||||
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(ClaymoreEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(ClaymoreEntity.class, EntityDataSerializers.STRING);
|
||||
public static final EntityDataAccessor<String> TEXTURE = SynchedEntityData.defineId(ClaymoreEntity.class, EntityDataSerializers.STRING);
|
||||
|
@ -44,7 +44,7 @@ public class ClaymoreEntity extends TamableAnimal implements GeoEntity {
|
|||
private boolean swinging;
|
||||
private boolean lastloop;
|
||||
private long lastSwing;
|
||||
public String animationprocedure = "empty";
|
||||
public String animationProcedure = "empty";
|
||||
|
||||
public ClaymoreEntity(PlayMessages.SpawnEntity packet, Level world) {
|
||||
this(TargetModEntities.CLAYMORE.get(), world);
|
||||
|
@ -244,20 +244,20 @@ public class ClaymoreEntity extends TamableAnimal implements GeoEntity {
|
|||
}
|
||||
|
||||
private PlayState movementPredicate(AnimationState event) {
|
||||
if (this.animationprocedure.equals("empty")) {
|
||||
if (this.animationProcedure.equals("empty")) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.claymore.idle"));
|
||||
}
|
||||
return PlayState.STOP;
|
||||
}
|
||||
|
||||
private PlayState procedurePredicate(AnimationState event) {
|
||||
if (!animationprocedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationprocedure));
|
||||
if (!animationProcedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationProcedure));
|
||||
if (event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
this.animationprocedure = "empty";
|
||||
this.animationProcedure = "empty";
|
||||
event.getController().forceAnimationReset();
|
||||
}
|
||||
} else if (animationprocedure.equals("empty")) {
|
||||
} else if (animationProcedure.equals("empty")) {
|
||||
return PlayState.STOP;
|
||||
}
|
||||
return PlayState.CONTINUE;
|
||||
|
@ -280,6 +280,11 @@ public class ClaymoreEntity extends TamableAnimal implements GeoEntity {
|
|||
this.entityData.set(ANIMATION, animation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnimationProcedure(String procedure) {
|
||||
this.animationProcedure = procedure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
|
||||
data.add(new AnimationController<>(this, "movement", 4, this::movementPredicate));
|
||||
|
|
|
@ -39,7 +39,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class MortarEntity extends PathfinderMob implements GeoEntity {
|
||||
public class MortarEntity extends PathfinderMob implements GeoEntity, AnimatedEntity {
|
||||
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.STRING);
|
||||
public static final EntityDataAccessor<String> TEXTURE = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.STRING);
|
||||
|
@ -47,7 +47,7 @@ public class MortarEntity extends PathfinderMob implements GeoEntity {
|
|||
private boolean swinging;
|
||||
private boolean lastloop;
|
||||
private long lastSwing;
|
||||
public String animationprocedure = "empty";
|
||||
public String animationProcedure = "empty";
|
||||
|
||||
public MortarEntity(PlayMessages.SpawnEntity packet, Level world) {
|
||||
this(TargetModEntities.MORTAR.get(), world);
|
||||
|
@ -211,7 +211,7 @@ public class MortarEntity extends PathfinderMob implements GeoEntity {
|
|||
}
|
||||
|
||||
private PlayState movementPredicate(AnimationState event) {
|
||||
if (this.animationprocedure.equals("empty")) {
|
||||
if (this.animationProcedure.equals("empty")) {
|
||||
if (this.isShiftKeyDown()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mortar.fire"));
|
||||
}
|
||||
|
@ -221,13 +221,13 @@ public class MortarEntity extends PathfinderMob implements GeoEntity {
|
|||
}
|
||||
|
||||
private PlayState procedurePredicate(AnimationState event) {
|
||||
if (!animationprocedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationprocedure));
|
||||
if (!animationProcedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationProcedure));
|
||||
if (event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
this.animationprocedure = "empty";
|
||||
this.animationProcedure = "empty";
|
||||
event.getController().forceAnimationReset();
|
||||
}
|
||||
} else if (animationprocedure.equals("empty")) {
|
||||
} else if (animationProcedure.equals("empty")) {
|
||||
return PlayState.STOP;
|
||||
}
|
||||
return PlayState.CONTINUE;
|
||||
|
@ -251,6 +251,11 @@ public class MortarEntity extends PathfinderMob implements GeoEntity {
|
|||
this.entityData.set(ANIMATION, animation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnimationProcedure(String procedure) {
|
||||
this.animationProcedure = procedure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
|
||||
data.add(new AnimationController<>(this, "movement", 0, this::movementPredicate));
|
||||
|
|
|
@ -43,7 +43,7 @@ import software.bernie.geckolib.core.animation.RawAnimation;
|
|||
import software.bernie.geckolib.core.object.PlayState;
|
||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||
|
||||
public class SenpaiEntity extends Spider implements GeoEntity {
|
||||
public class SenpaiEntity extends Spider implements GeoEntity, AnimatedEntity {
|
||||
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(SenpaiEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(SenpaiEntity.class, EntityDataSerializers.STRING);
|
||||
public static final EntityDataAccessor<String> TEXTURE = SynchedEntityData.defineId(SenpaiEntity.class, EntityDataSerializers.STRING);
|
||||
|
@ -51,7 +51,7 @@ public class SenpaiEntity extends Spider implements GeoEntity {
|
|||
private boolean swinging;
|
||||
private boolean lastloop;
|
||||
private long lastSwing;
|
||||
public String animationprocedure = "empty";
|
||||
public String animationProcedure = "empty";
|
||||
|
||||
public SenpaiEntity(PlayMessages.SpawnEntity packet, Level world) {
|
||||
this(TargetModEntities.SENPAI.get(), world);
|
||||
|
@ -179,7 +179,7 @@ public class SenpaiEntity extends Spider implements GeoEntity {
|
|||
}
|
||||
|
||||
private PlayState movementPredicate(AnimationState event) {
|
||||
if (this.animationprocedure.equals("empty")) {
|
||||
if (this.animationProcedure.equals("empty")) {
|
||||
if ((event.isMoving() || !(event.getLimbSwingAmount() > -0.15F && event.getLimbSwingAmount() < 0.15F))
|
||||
|
||||
&& !this.isAggressive()) {
|
||||
|
@ -197,13 +197,13 @@ public class SenpaiEntity extends Spider implements GeoEntity {
|
|||
}
|
||||
|
||||
private PlayState procedurePredicate(AnimationState event) {
|
||||
if (!animationprocedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationprocedure));
|
||||
if (!animationProcedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationProcedure));
|
||||
if (event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
this.animationprocedure = "empty";
|
||||
this.animationProcedure = "empty";
|
||||
event.getController().forceAnimationReset();
|
||||
}
|
||||
} else if (animationprocedure.equals("empty")) {
|
||||
} else if (animationProcedure.equals("empty")) {
|
||||
return PlayState.STOP;
|
||||
}
|
||||
return PlayState.CONTINUE;
|
||||
|
@ -226,6 +226,11 @@ public class SenpaiEntity extends Spider implements GeoEntity {
|
|||
this.entityData.set(ANIMATION, animation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnimationProcedure(String procedure) {
|
||||
this.animationProcedure = procedure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
|
||||
data.add(new AnimationController<>(this, "movement", 4, this::movementPredicate));
|
||||
|
|
|
@ -45,13 +45,13 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class Target1Entity extends PathfinderMob implements GeoEntity {
|
||||
public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedEntity {
|
||||
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(Target1Entity.class, EntityDataSerializers.BOOLEAN);
|
||||
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(Target1Entity.class, EntityDataSerializers.STRING);
|
||||
public static final EntityDataAccessor<String> TEXTURE = SynchedEntityData.defineId(Target1Entity.class, EntityDataSerializers.STRING);
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
||||
public String animationprocedure = "empty";
|
||||
public String animationProcedure = "empty";
|
||||
|
||||
public Target1Entity(PlayMessages.SpawnEntity packet, Level world) {
|
||||
this(TargetModEntities.TARGET_1.get(), world);
|
||||
|
@ -258,20 +258,20 @@ public class Target1Entity extends PathfinderMob implements GeoEntity {
|
|||
}
|
||||
|
||||
private PlayState movementPredicate(AnimationState<Target1Entity> event) {
|
||||
if (this.animationprocedure.equals("empty")) {
|
||||
if (this.animationProcedure.equals("empty")) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.target.idle"));
|
||||
}
|
||||
return PlayState.STOP;
|
||||
}
|
||||
|
||||
private PlayState procedurePredicate(AnimationState<Target1Entity> event) {
|
||||
if (!animationprocedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationprocedure));
|
||||
if (!animationProcedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationProcedure));
|
||||
if (event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
this.animationprocedure = "empty";
|
||||
this.animationProcedure = "empty";
|
||||
event.getController().forceAnimationReset();
|
||||
}
|
||||
} else if (animationprocedure.equals("empty")) {
|
||||
} else if (animationProcedure.equals("empty")) {
|
||||
return PlayState.STOP;
|
||||
}
|
||||
return PlayState.CONTINUE;
|
||||
|
@ -294,6 +294,11 @@ public class Target1Entity extends PathfinderMob implements GeoEntity {
|
|||
this.entityData.set(ANIMATION, animation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnimationProcedure(String procedure) {
|
||||
this.animationProcedure = procedure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
|
||||
data.add(new AnimationController<>(this, "movement", 0, this::movementPredicate));
|
||||
|
|
|
@ -33,7 +33,7 @@ import software.bernie.geckolib.core.animation.RawAnimation;
|
|||
import software.bernie.geckolib.core.object.PlayState;
|
||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||
|
||||
public class TargetEntity extends PathfinderMob implements GeoEntity {
|
||||
public class TargetEntity extends PathfinderMob implements GeoEntity, AnimatedEntity {
|
||||
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(TargetEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(TargetEntity.class, EntityDataSerializers.STRING);
|
||||
public static final EntityDataAccessor<String> TEXTURE = SynchedEntityData.defineId(TargetEntity.class, EntityDataSerializers.STRING);
|
||||
|
@ -41,7 +41,7 @@ public class TargetEntity extends PathfinderMob implements GeoEntity {
|
|||
private boolean swinging;
|
||||
private boolean lastloop;
|
||||
private long lastSwing;
|
||||
public String animationprocedure = "empty";
|
||||
public String animationProcedure = "empty";
|
||||
|
||||
public TargetEntity(PlayMessages.SpawnEntity packet, Level world) {
|
||||
this(TargetModEntities.TARGET.get(), world);
|
||||
|
@ -202,7 +202,7 @@ public class TargetEntity extends PathfinderMob implements GeoEntity {
|
|||
}
|
||||
|
||||
private PlayState movementPredicate(AnimationState event) {
|
||||
if (this.animationprocedure.equals("empty")) {
|
||||
if (this.animationProcedure.equals("empty")) {
|
||||
if (this.isDeadOrDying()) {
|
||||
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.target2.down"));
|
||||
}
|
||||
|
@ -212,13 +212,13 @@ public class TargetEntity extends PathfinderMob implements GeoEntity {
|
|||
}
|
||||
|
||||
private PlayState procedurePredicate(AnimationState event) {
|
||||
if (!animationprocedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationprocedure));
|
||||
if (!animationProcedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationProcedure));
|
||||
if (event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
this.animationprocedure = "empty";
|
||||
this.animationProcedure = "empty";
|
||||
event.getController().forceAnimationReset();
|
||||
}
|
||||
} else if (animationprocedure.equals("empty")) {
|
||||
} else if (animationProcedure.equals("empty")) {
|
||||
return PlayState.STOP;
|
||||
}
|
||||
return PlayState.CONTINUE;
|
||||
|
@ -233,14 +233,21 @@ public class TargetEntity extends PathfinderMob implements GeoEntity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyncedAnimation() {
|
||||
return this.entityData.get(ANIMATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnimation(String animation) {
|
||||
this.entityData.set(ANIMATION, animation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnimationProcedure(String procedure) {
|
||||
this.animationProcedure = procedure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
|
||||
data.add(new AnimationController<>(this, "movement", 0, this::movementPredicate));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.mcreator.target.init;
|
||||
|
||||
import net.mcreator.target.entity.*;
|
||||
import net.mcreator.target.entity.AnimatedEntity;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
@ -9,41 +9,13 @@ import net.minecraftforge.fml.common.Mod;
|
|||
public class EntityAnimationFactory {
|
||||
@SubscribeEvent
|
||||
public static void onEntityTick(LivingEvent.LivingTickEvent event) {
|
||||
if (event != null && event.getEntity() != null) {
|
||||
if (event.getEntity() instanceof Target1Entity syncable) {
|
||||
String animation = syncable.getSyncedAnimation();
|
||||
if (event == null || event.getEntity() == null) return;
|
||||
|
||||
if (event.getEntity() instanceof AnimatedEntity entity) {
|
||||
String animation = entity.getSyncedAnimation();
|
||||
if (!animation.equals("undefined")) {
|
||||
syncable.setAnimation("undefined");
|
||||
syncable.animationprocedure = animation;
|
||||
}
|
||||
}
|
||||
if (event.getEntity() instanceof MortarEntity syncable) {
|
||||
String animation = syncable.getSyncedAnimation();
|
||||
if (!animation.equals("undefined")) {
|
||||
syncable.setAnimation("undefined");
|
||||
syncable.animationprocedure = animation;
|
||||
}
|
||||
}
|
||||
if (event.getEntity() instanceof SenpaiEntity syncable) {
|
||||
String animation = syncable.getSyncedAnimation();
|
||||
if (!animation.equals("undefined")) {
|
||||
syncable.setAnimation("undefined");
|
||||
syncable.animationprocedure = animation;
|
||||
}
|
||||
}
|
||||
if (event.getEntity() instanceof ClaymoreEntity syncable) {
|
||||
String animation = syncable.getSyncedAnimation();
|
||||
if (!animation.equals("undefined")) {
|
||||
syncable.setAnimation("undefined");
|
||||
syncable.animationprocedure = animation;
|
||||
}
|
||||
}
|
||||
if (event.getEntity() instanceof TargetEntity syncable) {
|
||||
String animation = syncable.getSyncedAnimation();
|
||||
if (!animation.equals("undefined")) {
|
||||
syncable.setAnimation("undefined");
|
||||
syncable.animationprocedure = animation;
|
||||
}
|
||||
entity.setAnimation("undefined");
|
||||
entity.setAnimationProcedure(animation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue