Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Okay, so, I have an "animal" that I want to be able to make attack different types of mobs. She goes after them, but doesn't do damage, though. I'm aware, however, of a line of coding missing in the following code, and that is the AttackDamage coding. Problem is, most mobs don't seem to have that coding anyway, and when I do add that coding, I get an error. Here's the coding without the Attack Damage coding line.

package craftygirls.entity;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIAvoidEntity;
import net.minecraft.entity.ai.EntityAIFollowParent;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAIPanic;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAITempt;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class EntityTomboy extends EntityAnimal
{
    public EntityTomboy(World par1World)
    {
        super(par1World);
        this.setSize(0.9F, 2F);
        this.getNavigator().setAvoidsWater(true);
        this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(1, new EntityAIAttackOnCollide(this, EntityZombie.class, 1.0D, true));
        this.tasks.addTask(1, new EntityAIAttackOnCollide(this, EntitySkeleton.class, 1.0D, true));
        this.tasks.addTask(1, new EntityAIAttackOnCollide(this, EntityEnderman.class, 1.0D, true));
        this.tasks.addTask(1, new EntityAIAttackOnCollide(this, EntitySpider.class, 1.0D, true));
        this.tasks.addTask(2, new EntityAIPanic(this, 1.4D));
        this.tasks.addTask(2, new EntityAIMate(this, 1.0D));
        this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Items.cookie, false));
        this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D));
        this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
        this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
        this.tasks.addTask(7, new EntityAILookIdle(this));
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityZombie.class, 0, true));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntitySkeleton.class, 0, true));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityEnderman.class, 0, true));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntitySpider.class, 0, true));
    }

    public boolean isAIEnabled() {
    	return true;
    }
    
    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D);
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.3D);
    }

    protected void fall(float par1) {}
    
    @Override
    protected String getLivingSound()
    {
        return null;//this refers to:yourmod/sound/YourSound
    }

    @Override
    protected String getHurtSound()
    {
        return null;//this refers to:yourmod/sound/optionalFile/YourSound
    }

    @Override
    protected String getDeathSound()
    {
        return null;//etc.
    }

    @Override
    protected float getSoundVolume()
    {
        return 0.4F;
    }

@Override
public EntityAgeable createChild(EntityAgeable var1) {
	return new EntityTomboy(this.worldObj);
}

public boolean isBreedingItem(ItemStack par1ItemStack)
    {
        return par1ItemStack != null && par1ItemStack.getItem() == Items.cookie;
    }

public boolean attackEntityAsMob(Entity par1Entity)
    {
        boolean flag = super.attackEntityAsMob(par1Entity);

        if (flag)
        {
            int i = this.worldObj.difficultySetting.getDifficultyId();

            if (this.getHeldItem() == null && this.isBurning() && this.rand.nextFloat() < (float)i * 0.3F)
            {
                par1Entity.setFire(2 * i);
            }
        }

        return flag;
    }
}

 

The line of code I'm referring to is

this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(3.0D);

 

When I add the coding, though, she unspawns everywhere and when I try to spawn here I get this error:

java.lang.reflect.InvocationTargetException
[19:08:15] [server thread/WARN]: Skipping Entity with id 4
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at net.minecraft.entity.EntityList.createEntityByID(EntityList.java:233)
at net.minecraft.item.ItemMonsterPlacer.spawnCreature(ItemMonsterPlacer.java:173)
at net.minecraft.item.ItemMonsterPlacer.onItemUse(ItemMonsterPlacer.java:79)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:150)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:424)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:596)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:242)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:190)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:762)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:650)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:528)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:787)
Caused by: java.lang.NullPointerException
at craftygirls.entity.EntityTomboy.applyEntityAttributes(EntityTomboy.java:65)
at net.minecraft.entity.EntityLivingBase.<init>(EntityLivingBase.java:204)
at net.minecraft.entity.EntityLiving.<init>(EntityLiving.java:98)
at net.minecraft.entity.EntityCreature.<init>(EntityCreature.java:44)
at net.minecraft.entity.EntityAgeable.<init>(EntityAgeable.java:17)
at net.minecraft.entity.passive.EntityAnimal.<init>(EntityAnimal.java:34)
at craftygirls.entity.EntityTomboy.<init>(EntityTomboy.java:34)
... 19 more

I don't get it?

Did you check that EntityAnimal actually has the attributes:

this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D);
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.3D);

that you are trying to set values on?

I'm guessing it doesn't and that is causing your NPE.

  • Author

It does not seem to, however, it also doesn't seem to have the maxHealth attribute in its coding either, yet that's not causing me an issue. But, assuming that is the issue...how would I go about giving it an attack power? I figured copying that code would do it, but if not, then I'm at a loss as of how to do it, but I need her to have attack ability...

I suggest goind into the EntityCreature class as taking a look at that code. I copy and pasted thr attack code in, tested the tasks to get it working, then modified the variables to what i wanted. But thats what i had to do to get my mod working the way i wanted, for you there may be a simpler way, but thats the way i know.

  • Author

I tried copying the attackDamage coding from the SharedMonsterAttributes into Tomboy's coding and then running the same line again (aimed at her coding for the attribute) and I'm still getting the same error. I don't understand why she's erroring when I give her attack power...

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.