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.

Featured Replies

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

}

 

}

 

}

 

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...

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.