Jump to content

Recommended Posts

Posted (edited)

So im making a mod that removes the strafe from skeletons, but i need some help figuring out the exact way to make it. like naming the class, how to get the skeleton code, etc. Help would be appreciated, thanks!

Edited by wiisoup
Posted

Take a look through AbstractSkeletonEntity, and RangedBowAttackGoalRangedBowAttackGoal has the strafing code (in its tick() implementation).

 

What you'll need to do is remove that goal for the skeleton and replace it with a goal that lacks the strafe code.  Fortunately, it looks like that shouldn't be too hard, since the skel's combat code is set up via AbstractSkeletonEntity#setCombatTask(), which gets called when the skel is created (whether via spawn or restoration from NBT), and when its held weapon changes.  You should be able to hook entity spawning to call your own code to add your own ranged attack goal.  Not sure offhand about hooking equipment changes, though.

  • Like 2
Posted

I get an understanding of the code, but how do i set it up? im new to modding but have a heavy understanding of java, and ive started using 1.14.3 code which i know is different from 1.12 code. if i was starting the class, what would i name it and what would i add to the starting? sorry if im bothering you.

Posted

You would subscribe to the EntityJoinWorld event, check if the entity is a skeleton and if so modify its task list. 

  • Like 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)

 

14 hours ago, Cadiboo said:

You would subscribe to the EntityJoinWorld event, check if the entity is a skeleton and if so modify its task list. 

Ok so i set up the code, and what desht said above about looking through their ai, how would i do that? 

 

EDIT: I have inserted the RangedBowAttackGoal, how would i go by editing that?

 

wiisoup.PNGInsert other media

Edited by wiisoup
Posted

Does your code get called? I would recommend using a static event subscriber instead.

1 hour ago, wiisoup said:

looking through their ai, how would i do that

Check if event#entity is a skeleton, and if so change it's AI.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)
package com.wiisoup.stopstrafing.events;

import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class SkeletonSpawnInWorldEvent {

@SubscribeEvent
    public static void joinWorld(EntityJoinWorldEvent event) {
        System.out.println("Entity Spawned!");
    }
}

I think i changed the code to static.

Edited by wiisoup
figured out the reason for error
Posted

No. You only made the method static. You also need to annotate the class with @Mod.EventBusSubscriber for it to be a static event subscriber.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)

WAIT, so digging around in the folders of my mod directory, i found that in the rangedbowattack goal it contains all of the code i need to change within the skeleton. if i was to remove the strafe, what would i remove? i see strafing time, but not sure what to do with that.

 

EDIT: Okay, so i implemented the code changing the ai, so what do i do next?

 

 

package net.minecraft.entity.ai.goal;

import java.util.EnumSet;
import net.minecraft.entity.IRangedAttackMob;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.monster.MonsterEntity;
import net.minecraft.entity.projectile.ProjectileHelper;
import net.minecraft.item.BowItem;
import net.minecraft.item.Items;

public class RangedBowAttackGoal<T extends MonsterEntity & IRangedAttackMob> extends Goal {
   private final T entity;
   private final double moveSpeedAmp;
   private int attackCooldown;
   private final float maxAttackDistance;
   private int attackTime = -1;
   private int seeTime;
   private boolean strafingClockwise;
   private boolean strafingBackwards;
   private int strafingTime = -1;

   public RangedBowAttackGoal(T mob, double moveSpeedAmpIn, int attackCooldownIn, float maxAttackDistanceIn) {
      this.entity = mob;
      this.moveSpeedAmp = moveSpeedAmpIn;
      this.attackCooldown = attackCooldownIn;
      this.maxAttackDistance = maxAttackDistanceIn * maxAttackDistanceIn;
      this.setMutexFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.LOOK));
   }

   public void setAttackCooldown(int p_189428_1_) {
      this.attackCooldown = p_189428_1_;
   }

   /**
    * Returns whether the EntityAIBase should begin execution.
    */
   public boolean shouldExecute() {
      return this.entity.getAttackTarget() == null ? false : this.isBowInMainhand();
   }

   protected boolean isBowInMainhand() {
      net.minecraft.item.ItemStack main = this.entity.getHeldItemMainhand();
      net.minecraft.item.ItemStack off  = this.entity.getHeldItemOffhand();
      return main.getItem() instanceof BowItem || off.getItem() instanceof BowItem;
   }

   /**
    * Returns whether an in-progress EntityAIBase should continue executing
    */
   public boolean shouldContinueExecuting() {
      return (this.shouldExecute() || !this.entity.getNavigator().noPath()) && this.isBowInMainhand();
   }

   /**
    * Execute a one shot task or start executing a continuous task
    */
   public void startExecuting() {
      super.startExecuting();
      this.entity.setAggroed(true);
   }

   /**
    * Reset the task's internal state. Called when this task is interrupted by another one
    */
   public void resetTask() {
      super.resetTask();
      this.entity.setAggroed(false);
      this.seeTime = 0;
      this.attackTime = -1;
      this.entity.resetActiveHand();
   }

   /**
    * Keep ticking a continuous task that has already been started
    */
   public void tick() {
      LivingEntity livingentity = this.entity.getAttackTarget();
      if (livingentity != null) {
         double d0 = this.entity.getDistanceSq(livingentity.posX, livingentity.getBoundingBox().minY, livingentity.posZ);
         boolean flag = this.entity.getEntitySenses().canSee(livingentity);
         boolean flag1 = this.seeTime > 0;
         if (flag != flag1) {
            this.seeTime = 0;
         }

         if (flag) {
            ++this.seeTime;
         } else {
            --this.seeTime;
         }

         if (!(d0 > (double)this.maxAttackDistance) && this.seeTime >= 20) {
            this.entity.getNavigator().clearPath();
            ++this.strafingTime;
         } else {
            this.entity.getNavigator().tryMoveToEntityLiving(livingentity, this.moveSpeedAmp);
            this.strafingTime = -1;
         }

         if (this.strafingTime >= 20) {
            if ((double)this.entity.getRNG().nextFloat() < 0.3D) {
               this.strafingClockwise = !this.strafingClockwise;
            }

            if ((double)this.entity.getRNG().nextFloat() < 0.3D) {
               this.strafingBackwards = !this.strafingBackwards;
            }

            this.strafingTime = 0;
         }

         if (this.strafingTime > -1) {
            if (d0 > (double)(this.maxAttackDistance * 0.75F)) {
               this.strafingBackwards = false;
            } else if (d0 < (double)(this.maxAttackDistance * 0.25F)) {
               this.strafingBackwards = true;
            }

            this.entity.getMoveHelper().strafe(this.strafingBackwards ? -0.5F : 0.5F, this.strafingClockwise ? 0.5F : -0.5F);
            this.entity.faceEntity(livingentity, 30.0F, 30.0F);
         } else {
            this.entity.getLookController().setLookPositionWithEntity(livingentity, 30.0F, 30.0F);
         }

         if (this.entity.isHandActive()) {
            if (!flag && this.seeTime < -60) {
               this.entity.resetActiveHand();
            } else if (flag) {
               int i = this.entity.getItemInUseMaxCount();
               if (i >= 20) {
                  this.entity.resetActiveHand();
                  ((IRangedAttackMob)this.entity).attackEntityWithRangedAttack(livingentity, BowItem.getArrowVelocity(i));
                  this.attackTime = this.attackCooldown;
               }
            }
         } else if (--this.attackTime <= 0 && this.seeTime >= -60) {
            this.entity.setActiveHand(ProjectileHelper.getHandWith(this.entity, Items.BOW));
         }

      }
   }
}

 

Edited by wiisoup
Posted
54 minutes ago, wiisoup said:

It says that @Mod.EventBusSubscriber is not applicable to method..

58 minutes ago, Cadiboo said:

You also need to annotate the class

 

36 minutes ago, wiisoup said:

i implemented the code changing the ai, so what do i do next?

1 hour ago, Cadiboo said:

Check if event#entity is a skeleton, and if so change it's AI.

You can AT (AccessTransform) AbstractSkeletonEntity#aiArrowAttack from private final to public and then set it to your own one. For maximum compatibility, use a delegating RangedBowAttackGoal.

The AT for AbstractSkeletonEntity#aiArrowAttack would be public-f net.minecraft.entity.monster.AbstractSkeletonEntity field_85037_d # aiArrowAttack (According K9)

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)

Im really sorry, but im not understanding anything of which you are doing. You probably are, but as i was saying i want to implement the changes i made to RangedBowAttackGoal to the game itself. Again, heres the code for RangedBowAttackGoal, and my workspace is set up like this.

package com.wiisoup.stopstrafing.entity.ai.goal;

import java.util.EnumSet;
import net.minecraft.entity.IRangedAttackMob;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.goal.Goal;
import net.minecraft.entity.ai.goal.Goal.Flag;
import net.minecraft.entity.monster.MonsterEntity;
import net.minecraft.entity.projectile.ProjectileHelper;
import net.minecraft.item.BowItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import java.util.EnumSet;

public class RangedBowAttackGoal<T extends MonsterEntity & IRangedAttackMob> extends Goal {
    private final T entity;
    private final double moveSpeedAmp;
    private int attackCooldown;
    private final float maxAttackDistance;
    private int attackTime = -1;
    private int seeTime;


    public RangedBowAttackGoal(T mob, double moveSpeedAmpIn, int attackCooldownIn, float maxAttackDistanceIn) {
        this.entity = mob;
        this.moveSpeedAmp = moveSpeedAmpIn;
        this.attackCooldown = attackCooldownIn;
        this.maxAttackDistance = maxAttackDistanceIn * maxAttackDistanceIn;
        this.setMutexFlags(EnumSet.of(Flag.MOVE, Flag.LOOK));
    }

    public void setAttackCooldown(int p_189428_1_) {
        this.attackCooldown = p_189428_1_;
    }

    public boolean shouldExecute() {
        return this.entity.getAttackTarget() == null ? false : this.isBowInMainhand();
    }

    protected boolean isBowInMainhand() {
        ItemStack main = this.entity.getHeldItemMainhand();
        ItemStack off = this.entity.getHeldItemOffhand();
        return main.getItem() instanceof BowItem || off.getItem() instanceof BowItem;
    }

    public boolean shouldContinueExecuting() {
        return (this.shouldExecute() || !this.entity.getNavigator().noPath()) && this.isBowInMainhand();
    }

    public void startExecuting() {
        super.startExecuting();
        this.entity.setAggroed(true);
    }

    public void resetTask() {
        super.resetTask();
        this.entity.setAggroed(false);
        this.seeTime = 0;
        this.attackTime = -1;
        this.entity.resetActiveHand();
    }

    public void tick() {
        LivingEntity livingentity = this.entity.getAttackTarget();
        if (livingentity != null) {
            double d0 = this.entity.getDistanceSq(livingentity.posX, livingentity.getBoundingBox().minY, livingentity.posZ);
            boolean flag = this.entity.getEntitySenses().canSee(livingentity);
            boolean flag1 = this.seeTime > 0;
            if (flag != flag1) {
                this.seeTime = 0;
            }

            if (flag) {
                ++this.seeTime;
            } else {
                --this.seeTime;
            }

            if (d0 <= (double)this.maxAttackDistance && this.seeTime >= 20) {
                this.entity.getNavigator().clearPath();
            } else {
                this.entity.getNavigator().tryMoveToEntityLiving(livingentity, this.moveSpeedAmp);
            }


                if ((double)this.entity.getRNG().nextFloat() < 0.3D) {

                }

                if ((double)this.entity.getRNG().nextFloat() < 0.3D) {

                }

            }}}

 

wrew.PNG

Edited by wiisoup
Posted

What aren't you understanding?

To remove strafing in skeletons you need to replace the AI of each skeleton with your own one that doesn't tell the skeleton to strafe.

You do this by
1) Having your own implementation of RangedBowAttackGoal that doesn't strafe

2) Replacing the AI of each skeleton with your own AI implementation

 

The EntityJoinWorldEvent gives you access to all entities that join the world. You want to subscribe to this event. Whenever an entity is added to a world you're code will be called. You want to check if the entity is a skeleton, and if so replace it's AI. Because AbstractSkeletonEntity#aiArrowAttack is private and final, you need to use an Access Transformer to make it public and non-final so that you can replace it. 

 

Because all of the fields in RangedBowAttackGoal are private, you'll probably want to AT them to public with public net.minecraft.entity.ai.goal.RangedBowAttackGoal * # all fields

 

The most compatible way to remove the strafing would probably be to just set strafingTime to -2 right before calling super/delegate.tick().

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)

Thanks for explaining it a bit more, i think i got the general understanding and ill update you for results.

 

EDIT: Yea i still sadly cant figure out how to implement it into the game. the EntityJoinWorldEvent is the one i dont understand at all. I have no clue where to put any code in there besides the @Mod.EventBusSubscriber which still isnt applicable to the method. If i cant figure this out im probably just gonna cancel the mod because 1.14 code is confusing

Edited by wiisoup

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.