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.18.2) How i can make that a entity when explodes drop a quantity of items with a porcentage?

Featured Replies

Posted

Hello, how the title says i have the question on how to make a mob drop a quantity of items when explodes.

What i want is that when the mob explodes, it drops 1 item 100% and 3 more with a 50%, the 4 are the same items.

But it would be enough if i can make the item drop with a posibility since i found a way to make it drop always.

I already wrote a code that makes the mob drop the item when explodes but i couldn't find a way to make it drop with a posibility (like a 50% chance).

I am using the default creeper private void explodeCreeper.

I also tried using the loot_tables but i couldn't find a way to make it drop the item when explodes but when dies.

Thank you for reading and trying helping me. (Also sorry for the typos, not my main language)

 

This is the code: 

-------------------------------------------------------------------------

private void explodeCreeper () {

if (!this.level.isClientSide) {

Explosion.BlockInteraction explosion$blockinteraction = net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.level, this) ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.NONE;

float f = this.isPowered() ? 2.0F : 1.0F;

this.dead = true;

this.level.explode(this, this.getX(), this.getY(), this.getZ(), (float) this.explosionRadius * f, explosion$blockinteraction);

this.discard();

this.spawnLingeringCloud();

this.spawnAtLocation(ModItems.POWEREDPOWDER.get());             <------ What i wrote

}

}                               

-------------------------------------------------------------------------

 

You can try using a random value to do it.

You can find more about creating random numbers here.

I'm not good at modding, but at least I can read a crash report (well enough). That's something, right?

  • Author

Yeah i saw what you send and i think it should work, but i can't figure where to put the int randomNum on the this.spawnAtLocation(ModItems.POWEREDPOWDER.get()), i tried putting randomNum on diferrent spots but i couldn't find the correct spot

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.