Jump to content

[solved] Having An Issue With My Entity Disappearing After Piercing An Entity


gurujive

Recommended Posts

So I'm messin' around with this spell I'm working on.

 

It does,

this.doBlockCollisions();

when OnImpact EntityLivingBase

to pierce through entities, but when it goes through the first one, it disappears. It still exists and continues through the first entity to hit the ones behind it. It just doesn't render for some odd reason.

 

I can instead OnImpact do this seperately

And it will travel through blocks and entities and not disappear at all:

if (!this.worldObj.isRemote)
        {
        	this.doBlockCollisions();
        }

 

The thing is it doesn't need to travel through blocks it only needs to travel through entities.

This should work darn it.

 

Here is the one where it travels through blocks and entities and doesn't disappear:

public class EntityEarthOrb extends EntityOrb2
{
public EntityEarthOrb(World worldIn)
    {
        super(worldIn);
    } 
    public EntityEarthOrb(World worldIn, EntityLivingBase throwerIn)
    {
        super(worldIn, throwerIn);
    } 
    public void onUpdate()
    {
    	super.onUpdate();
    	this.worldObj.spawnParticle(EnumParticleTypes.BLOCK_CRACK, posX + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, posY + (worldObj.rand.nextFloat() / -2 - worldObj.rand.nextFloat()) / -1.3, posZ + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, 0, 0, 0,  new int[] {Block.getIdFromBlock(Blocks.DIRT)});
    	++ticksExisted;
        if (this.ticksExisted >= 54)
        {
        	this.setDead();
        }
    }
    public EntityEarthOrb(World worldIn, double x, double y, double z)
    {
        super(worldIn, x, y, z);
    }    
    protected void onImpact(RayTraceResult result)
    {
        if (result.entityHit != null)
        {
            int i = 0;
            if (result.entityHit instanceof EntityLivingBase)
            {
                i = 4;
            }
            result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
            worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.NEUTRAL, 0.8F, 1.5F / (worldObj.rand.nextFloat() * 0.4F + 0.8F));
        }
        for (int j = 0; j < 8; ++j)
        {
            this.worldObj.spawnParticle(EnumParticleTypes.BLOCK_CRACK, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[] {Block.getIdFromBlock(Blocks.DIRT)});
        }
        if (!this.worldObj.isRemote)
        {
        	this.doBlockCollisions();
        }
}
}

 

 

Here is the one that will die when it hits blocks but disappear after going through the first entity it hits:

public class EntityEarthOrb extends EntityOrb2
{
public EntityEarthOrb(World worldIn)
    {
        super(worldIn);
    } 
    public EntityEarthOrb(World worldIn, EntityLivingBase throwerIn)
    {
        super(worldIn, throwerIn);
    } 
    public void onUpdate()
    {
    	super.onUpdate();
    	this.worldObj.spawnParticle(EnumParticleTypes.BLOCK_CRACK, posX + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, posY + (worldObj.rand.nextFloat() / -2 - worldObj.rand.nextFloat()) / -1.3, posZ + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, 0, 0, 0,  new int[] {Block.getIdFromBlock(Blocks.DIRT)});
    	++ticksExisted;
        if (this.ticksExisted >= 54)
        {
        	this.setDead();
        }
    }
    public EntityEarthOrb(World worldIn, double x, double y, double z)
    {
        super(worldIn, x, y, z);
    }    
    protected void onImpact(RayTraceResult result)
    {
        if (result.entityHit != null)
        {
            int i = 0;
            if (result.entityHit instanceof EntityLivingBase)
            {
                i = 4;
            }
            result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
            worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.NEUTRAL, 0.8F, 1.5F / (worldObj.rand.nextFloat() * 0.4F + 0.8F));
            this.doBlockCollisions();
        }
        for (int j = 0; j < 8; ++j)
        {
            this.worldObj.spawnParticle(EnumParticleTypes.BLOCK_CRACK, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[] {Block.getIdFromBlock(Blocks.DIRT)});
        }
        if (this.worldObj.isRemote)
        {
        	this.setDead();
        }
}
}

 

any ideas?

Link to comment
Share on other sites

This is doing the same thing:

I'm really disappointed. The entity disappears after going through the first entity it hits, to travel through and hit whats behind it.

import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;

public class EntityEarthOrb extends EntityOrb2
{
public EntityEarthOrb(World worldIn)
    {
        super(worldIn);
    } 
    public EntityEarthOrb(World worldIn, EntityLivingBase throwerIn)
    {
        super(worldIn, throwerIn);
    } 
    public void onUpdate()
    {
    	super.onUpdate();
    	this.worldObj.spawnParticle(EnumParticleTypes.BLOCK_CRACK, posX + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, posY + (worldObj.rand.nextFloat() / -2 - worldObj.rand.nextFloat()) / -1.3, posZ + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, 0, 0, 0,  new int[] {Block.getIdFromBlock(Blocks.DIRT)});
    	++ticksExisted;
        if (this.ticksExisted >= 54)
        {
        	this.setDead();
        }
    }
    public EntityEarthOrb(World worldIn, double x, double y, double z)
    {
        super(worldIn, x, y, z);
    }    
    protected void onImpact(RayTraceResult result)
    {
        if (result.entityHit != null)
        {
            int i = 0;
            if (result.entityHit instanceof EntityLivingBase)
            {
                i = 4;
            }
            result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
            worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.NEUTRAL, 0.8F, 1.5F / (worldObj.rand.nextFloat() * 0.4F + 0.8F));
            this.canBeCollidedWith();
            {
            	boolean o;
            	o = true;
            }
        }
        for (int j = 0; j < 8; ++j)
        {
            this.worldObj.spawnParticle(EnumParticleTypes.BLOCK_CRACK, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[] {Block.getIdFromBlock(Blocks.DIRT)});
        }
        if (this.worldObj.isRemote)
        {
        	this.setDead();
        }
        
}
}

Link to comment
Share on other sites

Why do you do this?

if (this.worldObj.isRemote)
        {
        	this.setDead();
        }

What you are doing is killing the Entity client side. Therefore it doesn't render.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

You are only killing it client side though because world.isRemote you should be using !world.isRemote.

You are killing the entity anyways it is at the end of the method and always gets called. Try adding return; at the end of the if entityHit != null if statement.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.