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

Hello, I have made a custom grenade and it harms all but the player! How do I make it damage the player and display a custom death message, please could you tell me how or give me a link to a video tutorial?

Which code?

 

I have made a custom grenade

 

Probably this code...

I'll need help, and I'll give help. Just ask, you know I will!

  • Author

Grenade Class:

 

package palmerjj01.YoshiCraft.Grenades;

 

import palmerjj01.YoshiCraft.Entity.EntityYoshiGrenade;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

 

public class ItemYoshiGrenade extends Item {

 

public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player){

if(!player.capabilities.isCreativeMode){

--itemstack.stackSize;

}

world.playSoundAtEntity(player, "random.fizz", 0.7F, 0.8F);

 

if(!world.isRemote){

world.spawnEntityInWorld(new EntityYoshiGrenade(world, player));

}

 

return itemstack;

}

}

 

EntityGrenadeClass:

 

package palmerjj01.YoshiCraft.Entity;

 

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.projectile.EntityThrowable;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.world.World;

 

public class EntityYoshiGrenade extends EntityThrowable {

 

 

public EntityYoshiGrenade(World p_i1776_1_) {

super(p_i1776_1_);

}

 

public EntityYoshiGrenade(World world, EntityLivingBase entity){

super(world, entity);

}

 

@Override

public void onImpact(MovingObjectPosition p_70184_1_) {

for(int i = 0; i < 10; i++){

this.worldObj.spawnParticle("flame", this.posX, this.posY, this.posZ, 0,9F, 0.9F);

}

 

if(!this.worldObj.isRemote){

this.setDead();

if(!this.worldObj.isRemote){

this.worldObj.createExplosion((Entity) null, this.posX, this.posY, this.posZ, 4.5F, true);

}

}

}

 

}

Get rid of the player arg when you spawn the entity.

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Where is the player argument? What do you mean by "When I spawn Entity"?

 

 world.spawnEntityInWorld(new EntityYoshiGrenade(world, player));

I'll need help, and I'll give help. Just ask, you know I will!

  • Author

Are you sure that removing the player argument will make the grenade kill the player if in contact with the explosion?

That, specifically, I can't really say from experience. I was trying to answer this question:

 

Where is the player argument? What do you mean by "When I spawn Entity"?

I'll need help, and I'll give help. Just ask, you know I will!

     
if(!this.worldObj.isRemote){
         this.setDead();
         if(!this.worldObj.isRemote){
            this.worldObj.createExplosion((Entity) null, this.posX, this.posY, this.posZ, 4.5F, true);
         }
      }

 

I ran that code and it produced perfectly valid explosions that damaged the player. So I think something else is preventing your character from taking damage. This may sound silly but I must ask. Are you testing this in creative mode? If not I would start looking at things like blast resistance or other parts of your mod.

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.