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.

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

Featured Replies

Posted

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?

  • Author

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();
        }
        
}
}

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.

  • Author

it makes it so when it hits a block it dies, but when it hits an entity it pierces through it.

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.

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.