Jump to content

Custom SpiderEntity ignoring goals


Recommended Posts

I am trying to make a spider a pet.  So far, it is tameable, but once it is tamed, it sits there.  It seems to be ignoring its goals even though I get the tamed advancement and his texture switches.  He moves and if he's attacked, he defends himself, but he won't follow.  I'm completely new to this, maybe a few weeks in, but I know C# and some Java.  I used the TameableEntity class extending IAngerable mimicking the WolfEntity class without all the collar and swim code.  Any suggestions would help.  I hope it's something simple I'm not doing.  I've added some unnecessary code trying to figure out what I'm missing from the WolfEntity class but would appreciate any help or ideas. 


package com.shortman.raydenhall.entities;

import com.shortman.raydenhall.RaydenHall;
import com.shortman.raydenhall.init.RaydenhallEntities;
import com.shortman.raydenhall.init.RaydenhallItems;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.entity.WolfRenderer;
import net.minecraft.entity.*;
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.entity.ai.goal.*;
import net.minecraft.entity.monster.AbstractSkeletonEntity;
import net.minecraft.entity.monster.CreeperEntity;
import net.minecraft.entity.monster.GhastEntity;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.passive.TameableEntity;
import net.minecraft.entity.passive.TurtleEntity;
import net.minecraft.entity.passive.WolfEntity;
import net.minecraft.entity.passive.horse.AbstractHorseEntity;
import net.minecraft.entity.passive.horse.LlamaEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.AbstractArrowEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import javax.annotation.Nullable;
import java.util.Objects;
import java.util.UUID;
import java.util.function.Predicate;

public class OrangeSpiderEntity extends TameableEntity implements IAngerable
    private static final DataParameter<Integer> ANGER_TIME = EntityDataManager.createKey(OrangeSpiderEntity.class, DataSerializers.VARINT);
    private UUID oSpiderUUID;
    public static final Predicate<LivingEntity> TARGET_ENTITIES = (OrangeSpiderEntity) -> {
        EntityType<?> entitytype = OrangeSpiderEntity.getType();
        return entitytype == EntityType.ZOMBIE || entitytype == EntityType.HUSK || entitytype == EntityType.ZOMBIE_VILLAGER;

    public OrangeSpiderEntity(EntityType<? extends TameableEntity> type, World worldIn) {
        super(type, worldIn);

    protected void registerGoals() {
            this.goalSelector.addGoal(1, new SwimGoal(this));
            this.goalSelector.addGoal(2, new SitGoal(this));
            this.goalSelector.addGoal(4, new LeapAtTargetGoal(this, 0.4F));
            this.goalSelector.addGoal(5, new MeleeAttackGoal(this, 1.0D, true));
            this.goalSelector.addGoal(6, new FollowOwnerGoal(this, 1.0D, 10.0F, 2.0F, false));
            this.goalSelector.addGoal(7, new BreedGoal(this, 1.0D));
            this.goalSelector.addGoal(8, new WaterAvoidingRandomWalkingGoal(this, 1.0D));
            this.goalSelector.addGoal(10, new LookAtGoal(this, PlayerEntity.class, 8.0F));
            this.goalSelector.addGoal(10, new LookRandomlyGoal(this));
            this.targetSelector.addGoal(1, new OwnerHurtByTargetGoal(this));
            this.targetSelector.addGoal(2, new OwnerHurtTargetGoal(this));
            this.targetSelector.addGoal(3, (new HurtByTargetGoal(this)).setCallsForHelp());
            this.targetSelector.addGoal(4, new NearestAttackableTargetGoal<>(this, PlayerEntity.class, 10, true, false, this::func_233680_b_));
            this.targetSelector.addGoal(5, new NonTamedTargetGoal<>(this, AnimalEntity.class, false, TARGET_ENTITIES));
            this.targetSelector.addGoal(7, new NearestAttackableTargetGoal<>(this, AbstractSkeletonEntity.class, false));
            this.targetSelector.addGoal(8, new ResetAngerGoal<>(this, true));

    protected void updateAITasks() {

    public static AttributeModifierMap.MutableAttribute registerAttributes() {
        return MobEntity.func_233666_p_()
                .createMutableAttribute(Attributes.MOVEMENT_SPEED, 0.7D)
                .createMutableAttribute(Attributes.MAX_HEALTH, 16.0D)
                .createMutableAttribute(Attributes.ATTACK_DAMAGE, 8.0D);

    public void registerData() {
        this.dataManager.register(ANGER_TIME, 0);

    protected void playStepSound(BlockPos pos, BlockState blockIn) {
        this.playSound(SoundEvents.ENTITY_SPIDER_STEP, 0.15F, 1.0F);

    protected SoundEvent getAmbientSound() {
        return SoundEvents.ENTITY_SPIDER_AMBIENT;

    protected SoundEvent getHurtSound(DamageSource damageSourceIn) {
        return SoundEvents.ENTITY_SPIDER_HURT;

    protected SoundEvent getDeathSound() {
        return SoundEvents.ENTITY_SPIDER_DEATH;

    protected float getSoundVolume() {
        return 0.4F;

    public void onDeath(DamageSource cause) {

    public boolean attackEntityFrom(DamageSource source, float amount) {
        if (this.isInvulnerableTo(source)) {
            return false;
        } else {
            Entity entity = source.getTrueSource();
            if (entity != null && !(entity instanceof PlayerEntity) && !(entity instanceof AbstractArrowEntity)) {
                amount = (amount + 1.0F) / 2.0F;

            return super.attackEntityFrom(source, amount);

    public boolean attackEntityAsMob(Entity entityIn) {
        boolean flag = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), (float)((int)this.getAttributeValue(Attributes.ATTACK_DAMAGE)));
        if (flag) {
            this.applyEnchantments(this, entityIn);

        return flag;

    public void setTamed(boolean tamed) {
        if (tamed) {
        } else {


    public ActionResultType func_230254_b_(PlayerEntity p_230254_1_, Hand p_230254_2_) {
        ItemStack itemstack = p_230254_1_.getHeldItem(p_230254_2_);
        Item item = itemstack.getItem();
        if (this.world.isRemote) {
            boolean flag = this.isOwner(p_230254_1_) || this.isTamed() || item == Items.ROTTEN_FLESH && !this.isTamed() && !this.func_233678_J__();
            return flag ? ActionResultType.CONSUME : ActionResultType.PASS;
        } else {
            if (this.isTamed()) {
                if (this.isBreedingItem(itemstack) && this.getHealth() < this.getMaxHealth()) {
                    if (!p_230254_1_.abilities.isCreativeMode) {

                    this.heal((float) Objects.requireNonNull(item.getFood()).getHealing());
                    return ActionResultType.SUCCESS;
            } else if (item == Items.ROTTEN_FLESH && !this.func_233678_J__()) {
                if (!p_230254_1_.abilities.isCreativeMode) {

                if (this.rand.nextInt(3) == 0 && !net.minecraftforge.event.ForgeEventFactory.onAnimalTame(this, p_230254_1_)) {
                    this.setAttackTarget((LivingEntity) null);
                    this.world.setEntityState(this, (byte) 7);
                } else {
                    this.world.setEntityState(this, (byte) 6);

                return ActionResultType.SUCCESS;
            return super.func_230254_b_(p_230254_1_, p_230254_2_);

    public AgeableEntity createChild(AgeableEntity ageable) {
        OrangeSpiderEntity orangeSpiderEntity = RaydenhallEntities.ORANGE_SPIDER_ENTITY.get().create(this.world);
        UUID uuid = this.getOwnerId();
        if (uuid != null) {

        return orangeSpiderEntity;

    public boolean isBreedingItem(ItemStack stack) {
        Item item = stack.getItem();
        return item.isFood() && item.getFood().isMeat();

    public int getMaxSpawnedInChunk() {
        return 8;

    public int getAngerTime() {
        return this.dataManager.get(ANGER_TIME);

    public void setAngerTime(int time) {
        this.dataManager.set(ANGER_TIME, time);

    public UUID getAngerTarget() {
        return this.oSpiderUUID;

    public void setAngerTarget(@Nullable UUID target) {
        this.oSpiderUUID = target;

    public void func_230258_H__() {

    public boolean canBeLeashedTo(PlayerEntity player) {
        return !this.func_233678_J__() && super.canBeLeashedTo(player);

    public void playTameEffect(boolean play) {
        this.playSound(SoundEvents.ENTITY_SPIDER_AMBIENT, 0.15F, 1.0F);

    public void tick() {

    public boolean canMateWith(AnimalEntity otherAnimal) {
        if (otherAnimal == this) {
            return false;
        } else if (!this.isTamed()) {
            return false;
        } else if (!(otherAnimal instanceof OrangeSpiderEntity)) {
            return false;
        } else {
            OrangeSpiderEntity spiderentity = (OrangeSpiderEntity)otherAnimal;
            if (!spiderentity.isTamed()) {
                return false;
            } else if (super.func_233684_eK_()) {
                return false;
            } else {
                return this.isInLove() && spiderentity.isInLove();


Link to comment
Share on other sites

  • 3 weeks later...

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.

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.


  • Create New...

Important Information

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