Jump to content

Recommended Posts

Posted

Hey,

I am trying to get a throwable entity to drop itself on impact. I have basically used to code from the snow ball and changed the damage and made it drop the itself as an item on impact. It works just fine when I throw it against a mob but when I throw it against a block it drops multiple floating icons, only one of which can be picked up. The rest just float there until you reload the world. any ideas as to why?

 

Hear is my code for EntityRangerThrowingKnife

 

 

import thelion1997.test.TestItems;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.projectile.EntityArrow;

import net.minecraft.entity.projectile.EntityThrowable;

import net.minecraft.item.ItemStack;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.util.DamageSource;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.util.Vec3;

import net.minecraft.world.World;

 

public class EntityRangerThrowingKnife extends EntityThrowable {

 

private World world;

public EntityRangerThrowingKnife(World world) {

super(world);

this.world = world;

}

 

public EntityRangerThrowingKnife(World world, EntityLivingBase entity) {

super(world, entity);

this.world = world;

}

 

public EntityRangerThrowingKnife(World world, double x, double y, double z) {

super(world, x, y, z);

this.world = world;

}

 

 

@Override

protected void onImpact(MovingObjectPosition mop) {

 

Block block = world.getBlock(mop.blockX, mop.blockY, mop.blockZ);

 

if (mop.entityHit != null) {

 

// I changed this to type 'float' and set to '15';

float knifeDamage = 15;

 

mop.entityHit.attackEntityFrom(

DamageSource.causeThrownDamage(this, this.getThrower()),

knifeDamage);

}

//This is where I drop the item

entityDropItem(new ItemStack(TestItems.itemRangerThrowingKnife), 0);

 

// I changed particles to "crit" particles at the point of impact

for (int l = 0; l < 4; ++l) {

this.worldObj.spawnParticle("crit", this.posX, this.posY,

this.posZ, 0.0D, 0.0D, 0.0D);

}

 

if (!worldObj.isRemote) {

setDead();

}

 

}

 

}

 

Posted

I have no experience with projectiles but I do know this:

 

You have to summon (or "drop") your item on server side. Try putting in a check that checks if the world isn't remote.

 

The experts can correct me if I'm wrong though.

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.