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

I want to drop an item when the player die. I know how it works with overriding the EntityPlayer Class.

But i need how it works without overriding the class.

 

How does it work? No random drop!

Make a class named:

 

EntityPlayer_Drops.class

 

Add this, tested working.

 

package YOUR.PACKAGE;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.player.PlayerDropsEvent;

public class EntityPlayer_Drops extends EntityPlayer
{
public final int dropCount = 2;
public final int item = Item.appleRed.itemID;

public EntityPlayer_Drops(World world, int i, int j)
{
	super(world);
	i = dropCount;
	j = item;
}

@ForgeSubscribe
public void onPlayerDeath(PlayerDropsEvent event)
{
	if (event.entityPlayer.getHealth() <= 0) //Checks if player is dead.
	{
        event.entityPlayer.dropItem(Item.appleRed.itemID, 2); //Field 1 : Item/Block, change above. Field 2: Drop Count, change above.
	}
}

@Override
public boolean canCommandSenderUseCommand(int i, String s) 
{
	return false;
} //Ignore, don't change.

@Override
public ChunkCoordinates getPlayerCoordinates() 
{	
	return null;
} //Ignore, don't change.

@Override
public void sendChatToPlayer(String s) 
{

} //Ignore, don't change.
}

Bah beat me to the punch, with real working code!  I was just coming back from a forum search for the code that causes Notch to drop an apple  ;D

omg why a class?? just use

@PreInit

public void preInit(FMLPreInitializationEvent e){

MinecraftForge.EVENT_BUS.register(this);

}

@ForgeSubscribe

public void onDeath(LivingDeathEvent e){

if(e.entity instanceof EntityPlayer && !e.entity.worldObj.isRemote){

EntityPlayer killed = e.entity;

Entity killer = e.damageSource.getEntity();//if u want to know what killed the player

//do stuff

killed.dropItem(Item.aplleRed.itemID,2);

}

}

  • Author

Thanks for the answerring.

I see there is a problem.

Somebody made for this another class and someone said that its easier if you implement it in your modfile.

For myself i would use the extra class beacuse its more clean and i find everything faster.

So i hope that the code works xD.

  • Author

both codes worked pretty good. I used the last one. Because its a little bit cleaner.

Thanks for the help. but now a hard question. Is it possible to make this drop based on time?

I want to get this drop only at night xD (so that people have to wait until they get the next rare drop xD.)

  • Author

Ok it works but the drop is me not rare enought now a new idea.

 

Is a possible to detect if the moon is a full moon?

 

  • Author

I got not enought time to explain it thats why the extra answer now.

 

 

I want a very rare item which is so powerful and a recipe is with

technik mods to easy to cheating (like ee3 with transmutation)

and i do not want a recipe which requier 9 diamond blocks.

 

Thats why i want to get this drop only that the player dies.

But than the player could make a suicide and get this item very often.

Thats why i think in a special time will prevent people from doing that.

But my drop is not rare enough for that.

I mean with this item you can make item/blocks turn into exp.

Thats why i think i want to detect it have to be a special day (the night where fullmoon is)

 

 

And that is my first question: Is it possible to make a player drops an item when the moon is a fullmoon and the time is (maybe 18 clock (ingametime))

 

 

secon question is: Is it possible to make that the player have also the exp (1000 or bigger?)?

 

And howw can i do it?

 

  • Author

how to detect exp is easy but how can i detect that it is fullmoon?

for the full moon time u will need to calculate manually the time (see in the render global at render sky method and render stars method) do some tests.

how would i go about dropping multiple items? because you cannot have two

 

public final int item = ashtonsmod.Manure.itemID;

 

and you cannot change the

 

event.entityPlayer.dropItem

 

???

 

 

Use examples, i have aspergers.

Examples make sense to me.

for the full moon time u will need to calculate manually the time (see in the render global at render sky method and render stars method) do some tests.

 

Nope, just use this:

worldInstance.getMoonPhase()

I didn't use this, but I think after looking at the code, it's returning a value between 0-7. You have to figure out which is the full moon.

 

how would i go about dropping multiple items? because you cannot have two

 

public final int item = ashtonsmod.Manure.itemID;

 

and you cannot change the

 

event.entityPlayer.dropItem

 

???

 

 

Don't ninja threads.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

what? i have a question related this this thread.. would you rather i started my own? i thought my question was just an extension of this thread anyway and i thought someone else may look at this and have the same problem and not have to find the answer in a new place or start another thread and wait. sorry.

Use examples, i have aspergers.

Examples make sense to me.

what? i have a question related this this thread.. would you rather i started my own? i thought my question was just an extension of this thread anyway and i thought someone else may look at this and have the same problem and not have to find the answer in a new place or start another thread and wait. sorry.

 

I thought of something different, sorry.

 

Well, if you want to edit the drops, you need to have a LivingDropsEvent, check if the entity is an instanceof EntityPlayer and if so, add new EntityItems to the event.drops list which are holding ItemStacks with your Items.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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.