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.

[1.10.2] Weird bug when working with Entity.onImpact

Featured Replies

Posted

Hi, my mod has an item which can be thrown to catch a mob (similar like catching a Pokémon). The mob NBT data is stored in the item stack. When using the item, an entity will be thrown which detects an impact to catch or release a mob. It worked just fine a while ago, but after upgrading to 1.10.2 there is a random bugging behaviour when I try to catch a mob. Other mobs in the world behave laggy when slapping them or when they walk for example and there is no error thrown in the console. Here is the code:

 

@Override

    protected void onImpact(RayTraceResult mop)

    {

    if(!this.worldObj.isRemote){

    if (mop.entityHit != null && entity_nbt == null && mop.entityHit instanceof EntityLivingBase){

    if(MyUtils.checkHasTag(mop.entityHit, DENY_TAG)){

                    dropEmptySoulPearl(this.posX, this.posY, this.posZ, damage);

                    if(this.getThrower() != null){

                    MyUtils.sendChatMessage(getThrower(), "This entity has a protection which makes it uncatchable");

                    }

                    this.setDead();

                    return;

            }else{

                ItemStack is = new ItemStack(MyItems.SOUL_PEARL, 1);

                is.setItemDamage(damage);

                if(mop.entityHit.hasCustomName()){

                is.setStackDisplayName(mop.entityHit.getCustomNameTag());

                }

                ItemSoulPearl.catchEntity(is, (EntityLivingBase)mop.entityHit);

                mop.entityHit.setDead();

    this.worldObj.playSound(this.posX, this.posY, this.posZ, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.NEUTRAL, 4.0F, (1.0F + (this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat()) * 0.2F) * 0.7F, true);

                this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, this.posX, this.posY, this.posZ, ((double)this.rand.nextFloat() - 0.5D) * 0.08D, ((double)this.rand.nextFloat() - 0.5D) * 0.08D, ((double)this.rand.nextFloat() - 0.5D) * 0.08D, new int[] {Item.getIdFromItem(MyItems.SOUL_PEARL)});

                EntityItem ei = new EntityItem(this.worldObj, mop.entityHit.posX, mop.entityHit.posY, mop.entityHit.posZ, is);

                this.worldObj.spawnEntityInWorld(ei);

                this.setDead();

                return;

            }

    }else if (entity_nbt != null){

    Entity entity = EntityList.createEntityFromNBT(entity_nbt, worldObj);

                if(entity == null){

            dropEmptySoulPearl(this.posX, this.posY, this.posZ, damage);

                this.setDead();

                return;

                }

                entity.setUniqueId(UUID.randomUUID());//if(!can_drop)

                if(custom_name != null)entity.setCustomNameTag(custom_name);

                entity.setPosition(this.posX, this.posY, this.posZ);

            this.worldObj.spawnEntityInWorld(entity);

            this.worldObj.playSound(this.posX, this.posY, this.posZ, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.NEUTRAL, 4.0F, (1.0F + (this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat()) * 0.2F) * 0.7F, true);

            this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, this.posX, this.posY, this.posZ, ((double)this.rand.nextFloat() - 0.5D) * 0.08D, ((double)this.rand.nextFloat() - 0.5D) * 0.08D, ((double)this.rand.nextFloat() - 0.5D) * 0.08D, new int[] {Item.getIdFromItem(MyItems.SOUL_PEARL)});

            }

    dropEmptySoulPearl(this.posX, this.posY, this.posZ, damage + 1);

            this.setDead();

    }

    }

   

    private void dropEmptySoulPearl(double x, double y, double z, int damage){

    if(can_drop && damage < MyItems.SOUL_PEARL.getMaxDamage()){

    ItemStack is = new ItemStack(MyItems.SOUL_PEARL, 1);

        is.setItemDamage(damage);

    EntityItem ei = new EntityItem(this.worldObj, x, y, z, is);

        this.worldObj.spawnEntityInWorld(ei);

    }

    }

 

 

Btw I'm using Forge 12.18.1.2020

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.