Jump to content

[1.14.4.] Custom Skeleton not shooting custom bow


erce312

Recommended Posts

I've made a custom skeleton entity and given him a custom bow but he doesn't shoot/use it. The skeleton just melee attacks me. I've tried to override the setCombatTask and attackEntityWithRangedAttack.

    @Override
    public void setCombatTask() 
    {
        this.getHeldItem(ProjectileHelper.getHandWith(this, InformatikacraftItems.amethyst_bow));
        super.setCombatTask();
    }
    @Override
    public void attackEntityWithRangedAttack(LivingEntity target, float distanceFactor) {
        ItemStack itemstack = this.findAmmo(this.getHeldItem(ProjectileHelper.getHandWith(this, InformatikacraftItems.amethyst_bow)));
        super.attackEntityWithRangedAttack(target, distanceFactor);
    }
InformatikacraftItems.amethyst_bow = new BowItem(new Item.Properties().defaultMaxDamage(1000).group(ItemGroup.TOOLS)).setRegistryName(location("amethyst_bow")),

 

I've also checked if my custom bow is an instance of BowItem, which it is.

        try {
            BufferedWriter BR = new BufferedWriter(new FileWriter("C:\\Users\\erikp\\Documents\\test.txt"));
            
            if(InformatikacraftItems.amethyst_bow instanceof BowItem)
                BR.write("true");
            else
                BR.write("false");
            BR.flush();
            BR.close();
        }catch(Exception e) {
            
        }

 

Link to comment
Share on other sites

Firstly, why the hell are you writing into a file to check if your item is an instance of BowItem or not. Your item is actually created as a new instance of BowItem, so a check is not necessary at all here, yet if you would want to, just use a println.

 

As for your problem, are you sure your entity extends from AbstractSkeletonEntity 

Also, I don't know if you think you are doing anything at setCombatTask and attackEntityWithRangedAttack but if you do, you aren't actually doing anything at all there, so might as well not override them.

Edited by Cerandior
Link to comment
Share on other sites

Yes the class extends the AbstractSkeletonEntity.public class Reaper extends AbstractSkeletonEntity
 

{
    
    public Reaper(EntityType<? extends AbstractSkeletonEntity> type, World wotldIn) 
    {
        super((EntityType<? extends SkeletonEntity>) InformatikacraftEntities.REAPER, wotldIn);
    }
    @Override
     protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty) 
    {
         super.setEquipmentBasedOnDifficulty(difficulty);
         this.setItemStackToSlot(EquipmentSlotType.MAINHAND, new ItemStack(InformatikacraftItems.amethyst_bow));

    }
    @Override
    protected SoundEvent getStepSound() {
        return null;
    }
     

}

 

Link to comment
Share on other sites

So I have changed my class to this 

package com.github.erce312.informatikacraft.entities;

import com.github.erce312.informatikacraft.init.InformatikacraftEntities;
import com.github.erce312.informatikacraft.init.InformatikacraftItems;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.goal.MeleeAttackGoal;
import net.minecraft.entity.ai.goal.RangedBowAttackGoal;
import net.minecraft.entity.monster.AbstractSkeletonEntity;
import net.minecraft.entity.monster.SkeletonEntity;
import net.minecraft.entity.projectile.AbstractArrowEntity;
import net.minecraft.entity.projectile.ProjectileHelper;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.Difficulty;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.World;

public class Reaper extends AbstractSkeletonEntity
{
        private final RangedBowAttackGoal<AbstractSkeletonEntity> aiArrowAttack = new RangedBowAttackGoal<>(this, 1.0D, 20, 15.0F);
        private final MeleeAttackGoal aiAttackOnCollide = new MeleeAttackGoal(this, 1.2D, false) 
        {

              public void resetTask() {
                 super.resetTask();
                 Reaper.this.setAggroed(false);
              }


              public void startExecuting() {
                 super.startExecuting();
                 Reaper.this.setAggroed(true);
              }
        };
         
    public Reaper(EntityType<? extends AbstractSkeletonEntity> type, World wotldIn) 
    {
        super((EntityType<? extends SkeletonEntity>) InformatikacraftEntities.REAPER, wotldIn);
    }
    @Override
     protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty) 
    {
         super.setEquipmentBasedOnDifficulty(difficulty);
         this.setItemStackToSlot(EquipmentSlotType.MAINHAND, new ItemStack(InformatikacraftItems.amethyst_bow));

    }
    @Override
    protected SoundEvent getStepSound() {
        return null;
    }
    @Override
    public void attackEntityWithRangedAttack(LivingEntity target, float distanceFactor) {
          ItemStack itemstack = this.findAmmo(this.getHeldItem(ProjectileHelper.getHandWith(this, InformatikacraftItems.amethyst_bow)));
          AbstractArrowEntity abstractarrowentity = this.func_213624_b(itemstack, distanceFactor);
          if (this.getHeldItemMainhand().getItem() instanceof net.minecraft.item.BowItem)
             abstractarrowentity = ((net.minecraft.item.BowItem)this.getHeldItemMainhand().getItem()).customeArrow(abstractarrowentity);
          double d0 = target.posX - this.posX;
          double d1 = target.getBoundingBox().minY + (double)(target.getHeight() / 3.0F) - abstractarrowentity.posY;
          double d2 = target.posZ - this.posZ;
          double d3 = (double)MathHelper.sqrt(d0 * d0 + d2 * d2);
          abstractarrowentity.shoot(d0, d1 + d3 * (double)0.2F, d2, 1.6F, (float)(14 - this.world.getDifficulty().getId() * 4));
          this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
          this.world.addEntity(abstractarrowentity);
        super.attackEntityWithRangedAttack(target, distanceFactor);
    }
    @Override
    public void setCombatTask() {
           if (this.world != null && !this.world.isRemote) {
              this.goalSelector.removeGoal(this.aiAttackOnCollide);
              this.goalSelector.removeGoal(this.aiArrowAttack);
              ItemStack itemstack = this.getHeldItem(ProjectileHelper.getHandWith(this, InformatikacraftItems.amethyst_bow));
              if (itemstack.getItem() instanceof net.minecraft.item.BowItem) {
                 int i = 20;
                 if (this.world.getDifficulty() != Difficulty.HARD) {
                    i = 40;
                 }

                 this.aiArrowAttack.setAttackCooldown(i);
                 this.goalSelector.addGoal(4, this.aiArrowAttack);
              } else {
                 this.goalSelector.addGoal(4, this.aiAttackOnCollide);
                 }

              }
           }
     

}

But now I get an error when the entity is spawned. This is the crash report

 [Server thread/FATAL] [minecraft/ThreadTaskExecutor]: Error executing task on Server
java.lang.NullPointerException: null
        at net.minecraft.entity.ai.goal.PrioritizedGoal.hashCode(PrioritizedGoal.java:97) ~[?:?] {re:classloading}
        at java.util.HashMap.hash(HashMap.java:339) ~[?:1.8.0_221] {}
        at java.util.HashMap.put(HashMap.java:612) ~[?:1.8.0_221] {}
        at java.util.HashSet.add(HashSet.java:220) ~[?:1.8.0_221] {}
        at net.minecraft.entity.ai.goal.GoalSelector.addGoal(GoalSelector.java:42) ~[?:?] {re:classloading}
        at com.github.erce312.informatikacraft.entities.Reaper.setCombatTask(Reaper.java:87) ~[?:?] {re:classloading}
        at net.minecraft.entity.monster.AbstractSkeletonEntity.<init>(AbstractSkeletonEntity.java:69) ~[?:?] {re:classloading,pl:accesstransformer:B}
        at com.github.erce312.informatikacraft.entities.Reaper.<init>(Reaper.java:44) ~[?:?] {re:classloading}
        at net.minecraft.entity.EntityType.create(EntityType.java:415) ~[?:?] {re:classloading}
        at net.minecraft.entity.EntityType.create(EntityType.java:305) ~[?:?] {re:classloading}
        at net.minecraft.entity.EntityType.spawn(EntityType.java:297) ~[?:?] {re:classloading}
        at net.minecraft.entity.EntityType.spawn(EntityType.java:292) ~[?:?] {re:classloading}
        at net.minecraft.item.SpawnEggItem.onItemUse(SpawnEggItem.java:80) ~[?:?] {re:classloading}
        at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:607) ~[?:?] {re:classloading}
        at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:168) ~[?:?] {re:classloading}
        at net.minecraft.server.management.PlayerInteractionManager.func_219441_a(PlayerInteractionManager.java:341) ~[?:?] {re:classloading}
        at net.minecraft.network.play.ServerPlayNetHandler.processTryUseItemOnBlock(ServerPlayNetHandler.java:870) ~[?:?] {re:classloading}
        at net.minecraft.network.play.client.CPlayerTryUseItemOnBlockPacket.processPacket(CPlayerTryUseItemOnBlockPacket.java:42) ~[?:?] {re:classloading}
        at net.minecraft.network.play.client.CPlayerTryUseItemOnBlockPacket.processPacket(CPlayerTryUseItemOnBlockPacket.java:12) ~[?:?] {re:classloading}
        at net.minecraft.network.PacketThreadUtil.lambda$checkThreadAndEnqueue$0(PacketThreadUtil.java:19) ~[?:?] {re:classloading}
        at net.minecraft.util.concurrent.TickDelayedTask.run(TickDelayedTask.java:20) ~[?:?] {re:classloading}
        at net.minecraft.util.concurrent.ThreadTaskExecutor.run(ThreadTaskExecutor.java:140) [?:?] {re:classloading,pl:accesstransformer:B}
        at net.minecraft.util.concurrent.RecursiveEventLoop.run(RecursiveEventLoop.java:22) [?:?] {re:classloading}
        at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(ThreadTaskExecutor.java:110) [?:?] {re:classloading,pl:accesstransformer:B}
        at net.minecraft.server.MinecraftServer.func_213205_aW(MinecraftServer.java:726) [?:?] {re:classloading,pl:accesstransformer:B}
        at net.minecraft.server.MinecraftServer.driveOne(MinecraftServer.java:720) [?:?] {re:classloading,pl:accesstransformer:B}
        at net.minecraft.util.concurrent.ThreadTaskExecutor.drainTasks(ThreadTaskExecutor.java:97) [?:?] {re:classloading,pl:accesstransformer:B}
        at net.minecraft.server.MinecraftServer.runScheduledTasks(MinecraftServer.java:705) [?:?] {re:classloading,pl:accesstransformer:B}
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:650) [?:?] {re:classloading,pl:accesstransformer:B}
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_221] {}

It says something is wrong with 

this.goalSelector.addGoal(4, this.aiAttackOnCollide);

But I haven't changed that part. Does anyone know what is going on ?

Link to comment
Share on other sites

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.