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

So I've written a custom Entity; nothing special, it just extends EntityTameable, follows the player around and attacks stuff for them. The only difference is that it's summoned from an item, rather than tamed in the traditional way.

 

However, when the user quits, then comes back in, the entity takes damage until it dies.

 

Here's the class in case it's needed:

package com.nosrick.masterofmagic.entities;

import java.util.UUID;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IEntityOwnable;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;

public class EntityGuardianSpirit extends EntityTameable implements IEntityOwnable
{

public EntityGuardianSpirit(World worldIn) 
{
	super(worldIn);
        this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 1.0D, true));
        this.tasks.addTask(2, new EntityAIFollowOwner(this, 0.4D, 10.0F, 2.0F));
        this.tasks.addTask(3, new EntityAIWander(this, 0.2D));
        this.tasks.addTask(4, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
        this.tasks.addTask(4, new EntityAILookIdle(this));
        this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this));
        this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this));
        this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true, new Class[0]));
}

@Override
protected void applyEntityAttributes()
{
    super.applyEntityAttributes(); 

    // standard attributes registered to EntityLivingBase
   getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D);
   getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.80D);
   getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(0.8D);
   getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(16.0D);

    // need to register any additional attributes
   getAttributeMap().registerAttribute(SharedMonsterAttributes.attackDamage);
   getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(6.0D);
}

@Override
public String getOwnerId() 
{
	return this.dataWatcher.getWatchableObjectString(17);
}

@Override
public EntityLivingBase getOwner() 
{
        UUID uuid = UUID.fromString(this.getOwnerId());
        EntityPlayer owner = this.worldObj.getPlayerEntityByUUID(uuid);
        return owner;
}

public void setOwnerId(String owner)
{
	this.dataWatcher.updateObject(17, owner);
}

@Override
public EntityAgeable createChild(EntityAgeable ageable) 
{
	return null;
}

}

  • Author

Sorry for the double post, but I'm going to use this thread to log my adventures in case anyone else has the same problem.

 

It seems the entity is taking damage from an "inWall" source, even when they are standing in the middle of an open field. I'm not sure why.

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.