Posted July 24, 20169 yr 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.