Started by
ahmadnhak
on
Topic category: Advanced modding
Hi i try to make two custom element one of them for handling animations from geckolib and on other for handling movment with tryToMoveXYZ method .
in game when i run the cods sometimes both work sometimes just one of them works and there is no error ,
this is my first cod
@SteveModElements.ModElement.Tag
public class AnimManeger extends SteveModElements.ModElement {
public AnimManeger(SteveModElements instance) {
super(instance, 24);
}
public static void animrep (String contoller , String animid , int repeat ){
IWorld world = (IWorld) Variables.world; //came from player entity
double xcor = Variables.xos; //came from other method
double ycor = Variables.yos;
double zcor = Variables.zos;
if ((((Entity) world.getEntitiesWithinAABB(SteveEntity.CustomEntity.class,
new AxisAlignedBB((xcor) - (4 / 2d), (ycor) - (4 / 2d), (zcor) - (4 / 2d), (xcor) + (4 / 2d), (ycor) + (4 / 2d), (zcor) + (4 / 2d)),
null).stream().sorted(new Object() {
Comparator<Entity> compareDistOf(double _x, double _y, double _z) {
return Comparator.comparing((Function<Entity, Double>) (_entcnd -> _entcnd.getDistanceSq(_x, _y, _z)));
}
}.compareDistOf((xcor), (ycor), (zcor))).findFirst().orElse(null)) != null)) {
if (((Entity) world.getEntitiesWithinAABB(SteveEntity.CustomEntity.class, new AxisAlignedBB((xcor) - (4 / 2d), (ycor) - (4 / 2d),
(zcor) - (4 / 2d), (xcor) + (4 / 2d), (ycor) + (4 / 2d), (zcor) + (4 / 2d)), null).stream().sorted(new Object() {
Comparator<Entity> compareDistOf(double _x, double _y, double _z) {
return Comparator.comparing((Function<Entity, Double>) (_entcnd -> _entcnd.getDistanceSq(_x, _y, _z)));
}
}.compareDistOf((xcor), (ycor), (zcor))).findFirst().orElse(null)) instanceof IAnimatedEntity) {
new Object() {
@OnlyIn(Dist.CLIENT)
void playAnimation(Entity entity, String animationID) {
IAnimatedEntity aniEntity = (IAnimatedEntity) entity;
aniEntity.getAnimationManager().get(contoller)
.setAnimation(new AnimationBuilder().addRepeatingAnimation(animationID, (repeat)));
}
}.playAnimation(
((Entity) world
.getEntitiesWithinAABB(SteveEntity.CustomEntity.class, new AxisAlignedBB((xcor) - (4 / 2d), (ycor) - (4 / 2d),
(zcor) - (4 / 2d), (xcor) + (4 / 2d), (ycor) + (4 / 2d), (zcor) + (4 / 2d)), null)
.stream().sorted(new Object() {
Comparator<Entity> compareDistOf(double _x, double _y, double _z) {
return Comparator.comparing((Function<Entity, Double>) (_entcnd -> _entcnd.getDistanceSq(_x, _y, _z)));
}
}.compareDistOf((xcor), (ycor), (zcor))).findFirst().orElse(null)),
(animid));
}
}
}
}
and the second one exactly look like this except for this parts
if(steve!=null){
CreatureEntity creature =(CreatureEntity) steve ;
creature.getNavigator().tryMoveToXYZ(xd , yd , zd, speed);
}
why when i want to us them in same time in a same method , some times both work but some times just on of them work ?
please help!
Edited by ahmadnhak on Mon, 12/13/2021 - 10:24