mirror of
https://github.com/KAMKEEL/CustomNPC-Gecko-Addon.git
synced 2026-11-13 06:37:35 +00:00
Added the base for hurt and attack animations
This commit is contained in:
1 parent
5dd7adbcc5
commit
56e12c4730
4 files changed
+91
-30
No files matched your search
@@ -22,8 +22,9 @@ public class SubGuiModelAnimation extends SubGuiInterface implements ITextfieldL
|
||||
addSelectionBlock(1,y,"Animation File:",getModelData(npc).getAnimFile());
|
||||
addSelectionBlock(2,y+=23,"Idle:",getModelData(npc).getIdleAnim());
|
||||
addSelectionBlock(3,y+=23,"Walk:",getModelData(npc).getWalkAnim());
|
||||
addSelectionBlock(4,y+=23,"Attack:",getModelData(npc).getAttackAnim());
|
||||
addSelectionBlock(5,y+23,"Hurt:",getModelData(npc).getHurtAnim());
|
||||
addSelectionBlock(4,y+=23,"Melee Attack:",getModelData(npc).getMeleeAttackAnim());
|
||||
addSelectionBlock(5,y+=23,"Ranged Attack:",getModelData(npc).getRangedAttackAnim());
|
||||
addSelectionBlock(6,y+23,"Hurt:",getModelData(npc).getHurtAnim());
|
||||
addButton(new GuiNpcButton(670, width - 22, 2, 20, 20, "X"));
|
||||
}
|
||||
|
||||
@@ -59,11 +60,16 @@ public class SubGuiModelAnimation extends SubGuiInterface implements ITextfieldL
|
||||
(name)-> getModelData(npc).setWalkAnim(name)));
|
||||
}
|
||||
if(button.id==4){
|
||||
setSubGui(new GuiStringSelection(this,"Selecting geckolib attack animation:",
|
||||
setSubGui(new GuiStringSelection(this,"Selecting geckolib melee attack animation:",
|
||||
AnimationFileUtil.getAnimationList(getModelData(npc).getAnimFile()),
|
||||
(name)-> getModelData(npc).setAttackAnim(name)));
|
||||
(name)-> getModelData(npc).setMeleeAttackAnim(name)));
|
||||
}
|
||||
if(button.id==5){
|
||||
setSubGui(new GuiStringSelection(this,"Selecting geckolib ranged attack animation:",
|
||||
AnimationFileUtil.getAnimationList(getModelData(npc).getAnimFile()),
|
||||
(name)-> getModelData(npc).setRangedAttackAnim(name)));
|
||||
}
|
||||
if(button.id==6){
|
||||
setSubGui(new GuiStringSelection(this,"Selecting geckolib hurt animation:",
|
||||
AnimationFileUtil.getAnimationList(getModelData(npc).getAnimFile()),
|
||||
(name)-> getModelData(npc).setHurtAnim(name)));
|
||||
@@ -100,11 +106,17 @@ public class SubGuiModelAnimation extends SubGuiInterface implements ITextfieldL
|
||||
}
|
||||
if(textfield.id == 4 && isValidAnimation(textfield.getText())){
|
||||
if(!textfield.isEmpty())
|
||||
getModelData(npc).setAttackAnim(textfield.getText());
|
||||
getModelData(npc).setMeleeAttackAnim(textfield.getText());
|
||||
else
|
||||
textfield.setText(getModelData(npc).getAttackAnim());
|
||||
textfield.setText(getModelData(npc).getMeleeAttackAnim());
|
||||
}
|
||||
if(textfield.id == 5 && isValidAnimation(textfield.getText())){
|
||||
if(!textfield.isEmpty())
|
||||
getModelData(npc).setRangedAttackAnim(textfield.getText());
|
||||
else
|
||||
textfield.setText(getModelData(npc).getRangedAttackAnim());
|
||||
}
|
||||
if(textfield.id == 6 && isValidAnimation(textfield.getText())){
|
||||
if(!textfield.isEmpty())
|
||||
getModelData(npc).setHurtAnim(textfield.getText());
|
||||
else
|
||||
|
||||
@@ -7,15 +7,17 @@ public class CustomModelData {
|
||||
private String animFile = "custom:geo_npc.animation.json";
|
||||
private String idleAnim = "";
|
||||
private String walkAnim = "";
|
||||
private String attackAnim = "";
|
||||
private String meleeAttackAnim = "";
|
||||
private String hurtAnim = "";
|
||||
private String rangedAttackAnim = "";
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setString("Model", model);
|
||||
nbttagcompound.setString("AnimFile", animFile);
|
||||
nbttagcompound.setString("IdleAnim", idleAnim);
|
||||
nbttagcompound.setString("WalkAnim", walkAnim);
|
||||
nbttagcompound.setString("AttackAnim", attackAnim);
|
||||
nbttagcompound.setString("MeleeAttackAnim", meleeAttackAnim);
|
||||
nbttagcompound.setString("RangedAttackAnim", rangedAttackAnim);
|
||||
nbttagcompound.setString("HurtAnim", hurtAnim);
|
||||
return nbttagcompound;
|
||||
}
|
||||
@@ -27,7 +29,8 @@ public class CustomModelData {
|
||||
idleAnim = nbttagcompound.getString("IdleAnim");
|
||||
walkAnim = nbttagcompound.getString("WalkAnim");
|
||||
hurtAnim = nbttagcompound.getString("HurtAnim");
|
||||
attackAnim = nbttagcompound.getString("AttackAnim");
|
||||
meleeAttackAnim = nbttagcompound.getString("MeleeAttackAnim");
|
||||
rangedAttackAnim = nbttagcompound.getString("RangedAttackAnim");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,12 +66,12 @@ public class CustomModelData {
|
||||
this.walkAnim = walkAnim;
|
||||
}
|
||||
|
||||
public String getAttackAnim() {
|
||||
return attackAnim;
|
||||
public String getMeleeAttackAnim() {
|
||||
return meleeAttackAnim;
|
||||
}
|
||||
|
||||
public void setAttackAnim(String attackAnim) {
|
||||
this.attackAnim = attackAnim;
|
||||
public void setMeleeAttackAnim(String meleeAttackAnim) {
|
||||
this.meleeAttackAnim = meleeAttackAnim;
|
||||
}
|
||||
|
||||
public String getHurtAnim() {
|
||||
@@ -78,4 +81,12 @@ public class CustomModelData {
|
||||
public void setHurtAnim(String hurtAnim) {
|
||||
this.hurtAnim = hurtAnim;
|
||||
}
|
||||
|
||||
public String getRangedAttackAnim() {
|
||||
return rangedAttackAnim;
|
||||
}
|
||||
|
||||
public void setRangedAttackAnim(String rangedAttackAnim) {
|
||||
this.rangedAttackAnim = rangedAttackAnim;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.goodbird.npcgecko.entity;
|
||||
|
||||
import com.goodbird.npcgecko.constants.EnumSyncAutoAnim;
|
||||
import net.minecraft.entity.EntityCreature;
|
||||
import net.minecraft.entity.ai.EntityAIWatchClosest;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -21,12 +22,15 @@ public class EntityCustomModel extends EntityCreature implements IAnimatable, IA
|
||||
public ResourceLocation modelResLoc = new ResourceLocation("geckolib3", "geo/npc.geo.json");
|
||||
public ResourceLocation animResLoc = new ResourceLocation("custom", "geo_npc.animation.json");
|
||||
public ResourceLocation textureResLoc = new ResourceLocation("geckolib3", "textures/model/entity/geo_npc.png");
|
||||
public String idleAnim = "";
|
||||
public String walkAnim = "";
|
||||
public String hurtAnim = "";
|
||||
public String attackAnim = "";
|
||||
public String idleAnimName = "";
|
||||
public String walkAnimName = "";
|
||||
public String hurtAnimName = "";
|
||||
public String meleeAttackAnimName = "";
|
||||
public String rangedAttackAnimName = "";
|
||||
public AnimationBuilder dialogAnim = null;
|
||||
public AnimationBuilder manualAnim = null;
|
||||
public AnimationBuilder attackAnim = null;
|
||||
public AnimationBuilder hurtAnim = null;
|
||||
public ItemStack leftHeldItem;
|
||||
|
||||
private <E extends IAnimatable> PlayState predicateMovement(AnimationEvent<E> event) {
|
||||
@@ -52,25 +56,59 @@ public class EntityCustomModel extends EntityCreature implements IAnimatable, IA
|
||||
return PlayState.CONTINUE;
|
||||
}
|
||||
}
|
||||
if (!event.isMoving() || walkAnim.isEmpty()) {
|
||||
if (!idleAnim.isEmpty()) {
|
||||
event.getController().setAnimation(new AnimationBuilder().loop(idleAnim));
|
||||
if (attackAnim != null) {
|
||||
if (event.getController().getAnimationState() == AnimationState.Stopped) {
|
||||
attackAnim = null;
|
||||
} else {
|
||||
if (event.getController().currentAnimationBuilder != attackAnim) {
|
||||
event.getController().markNeedsReload();
|
||||
}
|
||||
event.getController().setAnimation(attackAnim);
|
||||
return PlayState.CONTINUE;
|
||||
}
|
||||
}
|
||||
if (hurtAnim != null) {
|
||||
if (event.getController().getAnimationState() == AnimationState.Stopped) {
|
||||
hurtAnim = null;
|
||||
} else {
|
||||
if (event.getController().currentAnimationBuilder != hurtAnim) {
|
||||
event.getController().markNeedsReload();
|
||||
}
|
||||
event.getController().setAnimation(hurtAnim);
|
||||
return PlayState.CONTINUE;
|
||||
}
|
||||
}
|
||||
if (!event.isMoving() || walkAnimName.isEmpty()) {
|
||||
if (!idleAnimName.isEmpty()) {
|
||||
event.getController().setAnimation(new AnimationBuilder().loop(idleAnimName));
|
||||
} else {
|
||||
return PlayState.STOP;
|
||||
}
|
||||
} else {
|
||||
event.getController().setAnimation(new AnimationBuilder().loop(walkAnim));
|
||||
event.getController().setAnimation(new AnimationBuilder().loop(walkAnimName));
|
||||
}
|
||||
return PlayState.CONTINUE;
|
||||
}
|
||||
|
||||
private <E extends IAnimatable> PlayState predicateAttack(AnimationEvent<E> event) {
|
||||
return PlayState.CONTINUE;
|
||||
}
|
||||
|
||||
public void setDialogAnim(String name) {
|
||||
dialogAnim = new AnimationBuilder().playOnce(name);
|
||||
}
|
||||
public void activateReceivedAnim(EnumSyncAutoAnim type) {
|
||||
switch (type) {
|
||||
case HURT -> {
|
||||
if(!hurtAnimName.isEmpty())
|
||||
hurtAnim = new AnimationBuilder().playOnce(hurtAnimName);
|
||||
}
|
||||
case MELEE_ATTACK -> {
|
||||
if(!meleeAttackAnimName.isEmpty())
|
||||
attackAnim = new AnimationBuilder().playOnce(meleeAttackAnimName);
|
||||
}
|
||||
case RANGED_ATTACK -> {
|
||||
if(!rangedAttackAnimName.isEmpty())
|
||||
attackAnim = new AnimationBuilder().playOnce(rangedAttackAnimName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public EntityCustomModel(World worldIn) {
|
||||
super(worldIn);
|
||||
@@ -82,7 +120,6 @@ public class EntityCustomModel extends EntityCreature implements IAnimatable, IA
|
||||
@Override
|
||||
public void registerControllers(AnimationData data) {
|
||||
data.addAnimationController(new AnimationController<>(this, "movement", 10, this::predicateMovement));
|
||||
data.addAnimationController(new AnimationController<>(this, "attack", 10, this::predicateAttack));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,10 +30,11 @@ public class MixinGeckoAddon {
|
||||
modelEntity.textureResLoc = NpcTextureUtils.getNpcTexture((EntityNPCInterface) copied);
|
||||
modelEntity.modelResLoc = new ResourceLocation(display.getCustomModelData().getModel());
|
||||
modelEntity.animResLoc = new ResourceLocation(display.getCustomModelData().getAnimFile());
|
||||
modelEntity.idleAnim = display.getCustomModelData().getIdleAnim();
|
||||
modelEntity.walkAnim = display.getCustomModelData().getWalkAnim();
|
||||
modelEntity.attackAnim = display.getCustomModelData().getAttackAnim();
|
||||
modelEntity.hurtAnim = display.getCustomModelData().getHurtAnim();
|
||||
modelEntity.idleAnimName = display.getCustomModelData().getIdleAnim();
|
||||
modelEntity.walkAnimName = display.getCustomModelData().getWalkAnim();
|
||||
modelEntity.meleeAttackAnimName = display.getCustomModelData().getMeleeAttackAnim();
|
||||
modelEntity.rangedAttackAnimName = display.getCustomModelData().getRangedAttackAnim();
|
||||
modelEntity.hurtAnimName = display.getCustomModelData().getHurtAnim();
|
||||
modelEntity.leftHeldItem = npc.inventory.getOffHand();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user