Jump to content

Advanced Entity Problems


Tenyar97

Recommended Posts

Hello all! :)

 

I asked a question like this before, and I kind-of got an answer...Whenever my entity gets to half health, I want it to spawn two more entities, and then die. It does this about half way...if I damage it to half health, it does nothing. However, If I damage it to half health, and then relog, it dies and spawns a spider, but not a zombie. How can I "fix" this, so that the player doesn't have to relog, and spawn both the spider and a zombie? My code is below. :)

 

package assets.betterdefense.entity;

import java.util.UUID;

import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIBreakDoor;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMoveThroughVillage;
import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import assets.betterdefense.common.BetterDefense;
import assets.betterdefense.common.EntityAIBreakWood;

public class EntityRiot_Zombie extends EntityMob
{
boolean spawnZombie = true;
int spawnCooldown = 1;
int spawnTimer = 5;
private float heightOffset = -0.5F;

    /** ticks until heightOffset is randomized */
    private int heightOffsetUpdateTime;
    private int field_70846_g;
    private static final ResourceLocation textureLocation = new ResourceLocation("betterdefense:Riot_Zombie.png");
    private static final UUID field_110187_bq = UUID.fromString("B9766B59-9566-4402-BC1F-2EE2A276D836");
    private static final AttributeModifier field_110188_br = new AttributeModifier(field_110187_bq, "Baby speed boost", 0.5D, 1);

    public EntityRiot_Zombie(World par1World)
    {
        super(par1World);
        this.isImmuneToFire = true;
        this.canBreatheUnderwater();
        this.stepHeight = 1.2F;
        this.getNavigator().setBreakDoors(true);
        this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(1, new EntityAIBreakDoor(this));
        this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1D, false));
        this.tasks.addTask(3, new EntityAIAttackOnCollide(this, EntityVillager.class, 1D, true));
        this.tasks.addTask(5, new EntityAIMoveThroughVillage(this, 1D, false));
        this.tasks.addTask(6, new EntityAIWander(this, 1D));
        this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
        this.tasks.addTask(7, new EntityAILookIdle(this));
        this.tasks.addTask(8, new EntityAIBreakWood(this));
        this.tasks.addTask(9, new EntityAIMoveTowardsRestriction(this, 1.0D));
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));

    }

protected void func_110147_ax()
{
        super.func_110147_ax();
        // Max Health - default 20.0D - min 0.0D - max Double.MAX_VALUE
        this.func_110148_a(SharedMonsterAttributes.field_111267_a).func_111128_a(20.0D);
        // Follow Range - default 32.0D - min 0.0D - max 2048.0D
        this.func_110148_a(SharedMonsterAttributes.field_111265_b).func_111128_a(45.0D);
        // Knockback Resistance - default 0.0D - min 0.0D - max 1.0D
        this.func_110148_a(SharedMonsterAttributes.field_111266_c).func_111128_a(0.7D);
        // Movement Speed - default 0.699D - min 0.0D - max Double.MAX_VALUE
        this.func_110148_a(SharedMonsterAttributes.field_111263_d).func_111128_a(0.20000000417232513D);
        // Attack Damage - default 2.0D - min 0.0D - max Doubt.MAX_VALUE
        this.func_110148_a(SharedMonsterAttributes.field_111264_e).func_111128_a(2.0D);
        
}

protected ResourceLocation func_110775_a(Entity entity) {
return textureLocation;
}

    
    public boolean canBreatheUnderwater()
    {
    	return true;
    }
    public int getTotalArmorValue()
    {
        int i = super.getTotalArmorValue() + 2;

        if (i > 20)
        {
            i = 20;
        }

        return i;
    }
    
    public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
    {
        if (par1DamageSource.isFireDamage())
        {
            par2 = 0;
        }

        if (super.attackEntityFrom(par1DamageSource, par2))
        {
            if (par1DamageSource.getEntity() != null)
            {
                Entity par1Entity = par1DamageSource.getEntity();
                int j = 0;
                if (par1Entity instanceof EntityLiving)
                {
                    j += EnchantmentHelper.getKnockbackModifier((EntityLiving) par1Entity, this);

                    if (j > 0)
                    {
                        this.motionX /= 0.6D;
                        this.motionZ /= 0.6D;
                        this.addVelocity((double) (MathHelper.sin(par1Entity.rotationYaw * (float) Math.PI / 180.0F) * (float) j * 0.5F), -0.1D,
                                (double) (-MathHelper.cos(par1Entity.rotationYaw * (float) Math.PI / 180.0F) * (float) j * 0.5F));
                    }
                }

            }
            if (this.func_110143_aJ() <= this.func_110138_aP() / 2.0F)
    {
    	stage++;
        spawnZombie();
        spawnReplacement();
        this.setDead();
    }
    return true;
}

return false;
}
    
    private void spawnZombie()
    {
        int numSpawned = 0;

        if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
        {
            numSpawned++;
        }
        if (numSpawned >= 1)
            return;

        if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
        {
            numSpawned++;
        }
        if (numSpawned >= 1)
            return;

        if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
        {
            numSpawned++;
        }
        if (numSpawned >= 1)
            return;

        if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
        {
            numSpawned++;
        }
        if (numSpawned >= 1)
            return;

        if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
        {
            numSpawned++;
        }
        if (numSpawned >= 1)
            return;

        if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
        {
            numSpawned++;
        }
        if (numSpawned >= 1)
            return;

        if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
        {
            numSpawned++;
        }
        if (numSpawned >= 1)
            return;

        if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
        {
            numSpawned++;
        }
        if (numSpawned >= 1)
            return;

    }

    public boolean trySpawnZombie(int x, int y, int z)
    {
        EntityZombie zombie1 = new EntityZombie(worldObj);
        zombie1.setPosition(x, y, z);
        {
            if (!worldObj.isRemote)
                worldObj.spawnEntityInWorld(zombie1);
            zombie1.spawnExplosionParticle();
            return true;
        }
    }
    
    private void spawnReplacement()
    {
        int numSpawned = 0;

        if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ))
        {
            numSpawned++;
        }
        if (numSpawned >= 1)
            return;

        if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ))
        {
            numSpawned++;
        }
        if (numSpawned >= 2)
            return;

        if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ))
        {
            numSpawned++;
        }
        if (numSpawned >= 2)
            return;

        if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ))
        {
            numSpawned++;
        }
        if (numSpawned >= 2)
            return;

        if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ))
        {
            numSpawned++;
        }
        if (numSpawned >= 2)
            return;

        if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ))
        {
            numSpawned++;
        }
        if (numSpawned >= 2)
            return;

        if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ))
        {
            numSpawned++;
        }
        if (numSpawned >= 2)
            return;

        if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ))
        {
            numSpawned++;
        }
        if (numSpawned >= 2)
            return;

    }

    public boolean trySpawnReplacement(int x, int y, int z)
    {
        EntitySpider spider = new EntitySpider(worldObj);
        spider.setPosition(x, y, z);
        {
            if (!worldObj.isRemote)
                worldObj.spawnEntityInWorld(spider);
            spider.spawnExplosionParticle();
            return true;
        }
    }
    
  //if (this.worldObj.rand.nextInt(90) == 0)
    public void initCreature()
    {
        
        if (this.worldObj.rand.nextInt(100) == 0)
        {
        this.setCurrentItemOrArmor(1, new ItemStack(BetterDefense.Boots));

        }
        for (int i = 0; i < this.equipmentDropChances.length; ++i)
        {
            this.equipmentDropChances[i] = 0F;
        }
    }
    
    protected boolean isAIEnabled()
    {
        return true;
    }
    
    protected String getDecay()
    {
        return "townaura";
    }
    
    
    public void onLivingUpdate()
    {

        for (int i = 0; i < 2; ++i)
        {
            this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D);
            this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D);
            this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D);
            this.worldObj.playSoundAtEntity(attackingPlayer, "betterdefense:moan1", 1.0F, 1.0F);
            //this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D);
           //this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D);
           //this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D);
        }
        super.onLivingUpdate();
    }
    
    
public boolean attackEntityAsMob(Entity par1Entity)
    {
        boolean flag = super.attackEntityAsMob(par1Entity);

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

        return flag;
    }

    /**
     * Returns the sound this mob makes while it's alive.
     */
    protected String getLivingSound()
    {
        return "betterdefense:moan";
    }

    /**
     * Returns the sound this mob makes when it is hurt.
     */
    protected String getHurtSound()
    {
        return "mob.zombie.hurt";
    }

    /**
     * Returns the sound this mob makes on death.
     */
    protected String getDeathSound()
    {
        return "mob.zombie.death";
    }

    /**
     * Plays step sound at given x, y, z for the entity
     */
    protected void playStepSound(int par1, int par2, int par3, int par4)
    {
        this.playSound("mob.zombie.step", 0.15F, 1.0F);
    }

    /**
     * Returns the item ID for the item the mob drops on death.
     */
    protected int getDropItemId()
    {
        return Item.rottenFlesh.itemID;
    }

    /**
     * Get this Entity's EnumCreatureAttribute
     */
    public EnumCreatureAttribute getCreatureAttribute()
    {
        return EnumCreatureAttribute.UNDEAD;
    }

    protected void dropRareDrop(int par1)
    {
        switch (this.rand.nextInt(3))
        {
            case 0:
                this.dropItem(Item.diamond.itemID, 1);
                break;
            case 1:
                this.dropItem(BetterDefense.HISword.itemID, 1);
                break;
            case 2:
                this.dropItem(Item.ingotIron.itemID, 1);
        }
    }
/*
    protected void addRandomArmor()
    {
        super.addRandomArmor();
        super.canPickUpLoot();
        
        this.setCurrentItemOrArmor(2, new ItemStack(BetterDefense.Legs));

        if (this.rand.nextFloat() < (this.worldObj.difficultySetting == 3 ? 0.05F : 0.01F))
        {
            int i = this.rand.nextInt(3);

            if (i == 0)
            {
                this.setCurrentItemOrArmor(0, new ItemStack(Item.swordIron));
            }
            else
            {
                this.setCurrentItemOrArmor(0, new ItemStack(Item.shovelIron));
            }
        }
    }
    */

public void setGrowingAge(int i) {

}
}

 

Any help is appreciated, thanks for looking! :D

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • no this one https://pastebin.com/5uMxHeWf
    • I am in such a mess. I have lost over 4.7m due to a scammer... It started as bank wires and then bitcoin. it is hard to imagine but it is true and can send any proof, then I tried to use a couple of recovery companies and was as well. Graphic design has been more than just a hobby for me since high school—it has become a thriving career. Starting in my parents' garage, I eventually expanded to my office, running a successful graphic design business. However, like many, I faced the need to diversify my investments due to inflation. This led me to invest 60.16 in Bitcoin, a decision that paid off handsomely as my investment grew to 4.7m over time. This financial windfall allowed me to upgrade my equipment and take on more ambitious projects, furthering the growth of my business. Unfortunately, my excitement was abruptly cut short when I fell victim to a hacking incident. Malware infected my computer, giving hackers access to my Bitcoin wallet. The devastation of potentially losing all my hard-earned savings and plans weighed heavily on me. At this dire moment, a fellow designer suggested Linux Cyber Security Company as a potential solution. Desperate for a lifeline, I reached out to them, hoping for a miracle. The response from Linux Cyber Security Company was prompt, incredibly professional, and effective. Their team quickly traced the hacker’s activities and recovered most of my funds, alleviating a significant amount of stress and uncertainty. Beyond the recovery, they took the time to educate me on essential practices to secure my Bitcoin holdings better. They emphasized using antivirus software to prevent malware infections, avoiding suspicious downloads, and the added security provided by hardware wallets. This experience served as a critical wake-up call for me. It highlighted the vulnerabilities inherent in digital assets and underscored the importance of robust security measures. Thanks to the guidance and expertise of Linux Cyber Security Company, I now feel more equipped to protect my digital assets proactively. Their insights have empowered me to implement stronger security protocols in my business operations and personal finances alike. With my Bitcoin funds securely recovered and a newfound understanding of digital security best practices, I am more confident in navigating future challenges. This journey has reinforced my commitment to safeguarding my hard-earned assets and leveraging technology responsibly. I am optimistic about the growth opportunities ahead, creatively in graphic design and prudently in investment strategies. In conclusion, while the hacking incident was a setback, it ultimately became a catalyst for enhancing my digital security awareness and resilience. I am grateful to Linux Cyber Security Company for their expertise and support during a challenging time, enabling me to continue pursuing my passion for graphic design with renewed confidence and financial stability. Contact a professional company I am sure they can help you with your case too, Website [www.linuxcybersecurity.com Email the team; info@)(linuxcybersecurity.com
    • https://pastebin.com/B2HnBZTa
    • it was easy villager mate, thanks ill see how to do it without that mod! thanks
  • Topics

×
×
  • Create New...

Important Information

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