Jump to content

[1.7.10] Modifying the drop(s) of an existing block


winnetrie

Recommended Posts

I'm looking for something i can remove/add drop(s) of an existing block. I found some information on forums but nothing like that was working, so i tried something myself:

 

I made a new class for this and i do not even know if this is right.

If it is right, how do i register this?

public class TemDrops {

@SubscribeEvent
 public void Temloot(BlockEvent.HarvestDropsEvent event)

 {
	List<ItemStack> loot = event.drops;
    	Iterator<ItemStack> Leash = loot.iterator();
    	
    	while (Leash.hasNext()) {
	ItemStack is = Leash.next();

	if (is != null && is.getItem() == Item.getItemFromBlock(Blocks.leaves))
		{
		((List<ItemStack>) Leash).add(new ItemStack(Items.potato));
		}
    	}
}
}

Link to comment
Share on other sites

MinecraftForge.EVENT_BUS.register(new YourClass());

 

In pre-1.8 there is also FML event bus, but that is for different events. (google).

Yeah that was the first thing i tried, but it didn't do anything

i registered it in my CommonProxy class like this:

 

public void init(FMLInitializationEvent event) {
    	TemRecipes.init();
    	
    	if(Loader.isModLoaded("BiomesOPlenty")){
		BOPAddonRecipes.init();
		}
    	MinecraftForge.EVENT_BUS.register(new TemDrops());
    	 //
    	 GameRegistry.registerWorldGenerator(new TemChunkGenerator(), 1);
    	 GameRegistry.registerWorldGenerator(new ChalkStoneGenerator(), 10);
    	 

    }

So i guess there is something wrong with the TemDrops.class itself

Link to comment
Share on other sites

Are you saying method is not called or logic is not working like it is supposed to?

 

Make Syso there and check.

 

Also - very important - Harvesting is NOT called in creative mode (notice there is no drops when you pawn block in creative). Ppl often forget that.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

For 1.7.10, the event is fired on the

MinecraftForge.EVENT_BUS

, which you are doing.

 

Show your current TemDrops class with the "TEST TEST TEST" line.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I have it working now. I tried something else:

public class TemDrops {


@SubscribeEvent
public void Temloot(BlockEvent.BreakEvent e)

{
	Block block =e.block;
	if ( block instanceof BlockLeaves)
	  {
	   Random r = new Random();
	  
	   if ( r.nextFloat() < 0.2F){
	   EntityItem i = new EntityItem(e.world, e.x, e.y, e.z, new ItemStack(Items.stick));
	   System.out.println("TEST TEST TESTertje");
	   e.world.spawnEntityInWorld(i);
	   }
	  
	  }

}

}

I have seen a page "jabelar's minecraft forge tutorials"(lot's of information there!!  ;D). There the autor says on his page to use breakevent instead of harvestevent to get a drop from blocks like leaves.

So the registering was done but my method wasn't right. I now have made a better 1 with some help ofc.

While this method adds a drop, i was wondering how i would remove  a drop.

I also made it check an instance of BlockLeaves.

 

EDIT:

Oh btw leaves DO drop the sticks in creative mode, but only the sticks.

Maybe i need to make a check if the player is in creative mode or not. Does it matter anyway?

Link to comment
Share on other sites

Leaves still triggers

HarvestDropsEvent

.  It overrides

harvestBlock

, but all it does is call super().

 

The block default method calls

dropBlockAsItem

which passes off to

dropBlockAsItemWithChance

which calls

getDrops

just prior to firing the event, which BlockLeaves overrides again (to possibly drop a sapling).

 

Adding a stick to that is just as easy as

event.drops.add(new ItemStack(...))

 

Removing is a bit trickier, as you should loop through the array to locate the item you want to remove, and for every other item add it to a new array (you don't want to just delete everything: some other mod may have added an item that should still drop!).  Then call

event.drops.clear()

and then copy your saved list back to event.drops.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Because I forget things.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I have this now:

public class TemDrops {

@SubscribeEvent
public void Temloot(HarvestDropsEvent event) 
{
	System.out.println("TEST TEST TESTertje");
   	Iterator<ItemStack> Leash = event.drops.iterator();
   	while (Leash.hasNext()) {
   		Block block= event.block;
		ItemStack is = Leash.next();
		if (block != Blocks.leaves)
			{
			System.out.println("nothing"); 
			}
		else{ 
			System.out.println("leaves!!"); 
			event.drops.add(new ItemStack(Items.potato));
		}
   	}
}
}

But this isn't working at all and it makes minecraft crash if the 'else' statement triggers.

 

Link to comment
Share on other sites

You are trying to add to a List while iterating through it, this is not allowed.

AAAH yes now i understand it.

So i can only remove from that list while iterating but not adding.

To add something to the drop i now have this:

public class TemDrops {

@SubscribeEvent
public void Temloot(HarvestDropsEvent event) 
{
	Block block = event.block;
	if (block instanceof BlockLeaves){
		event.drops.add(new ItemStack(Items.potato));
	}
}
}

I didn't had a need to remove something but i was wondering how to.

It is ennoying not to know. And yes i really need to study more java, i know!

Link to comment
Share on other sites

Yes.  There's no point in adding inside the loop (even if it didn't crash, you'd then have to check the item you just added as well and that could be bad!).

 

Also, your loop in your prior post makes no sense.

 

//for each item in the list
//  save a reference to the item
//  if the block harvested is Leaves
//    add potato.

 

You never do anything with the ItemStack

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • SLOT Ratubet77 adalah bocoran slot gacor rekomendasi dari Ratubet77 yang bisa anda temukan di SLOT Ratubet77. Situs SLOT Ratubet77 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ratubet77 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ratubet77 merupakan SLOT Ratubet77 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ratubet77. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ratubet77 hari ini yang telah disediakan SLOT Ratubet77. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ratubet77 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ratubet77 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ratubet77 di link SLOT Ratubet77. DAFTAR SEKARANG DAFTAR SEKARANG DAFTAR SEKARANG
    • I am currently running the 1.20.1 Occultcraft modpack in Curseforge and am having numerous troubles making a mob farm with the apotheosis mod. When trying to modify the stats of the spawners specific stats such as the range, spawn count, and max entities reset to default after every spawn. When the spawners spawn boss mobs with certain attributes, that I'm not sure of, the building it is in explode even with mob griefing turned off. This has happened multiple times with varying sizes for the explosions. I was wonder if there is any way to disable these explosions from happening or disable boss abilities with something in the game. I also wanted to know a fix for the resetting stats on spawners and why this is happening.
    • SLOT Bank BSI adalah pilihan terbaik untuk Anda yang ingin merasakan sensasi bermain slot dengan layanan dari Bank BSI. Dengan keamanan terjamin, beragam pilihan permainan, kemudahan deposit via Bank BSI, dan berbagai bonus menarik, kami siap memberikan Anda pengalaman bermain yang tak terlupakan. Bergabunglah dengan kami sekarang dan mulailah petualangan seru Anda!    
    • Mengapa Memilih WINNING303? WINNING303 telah dikenal sebagai salah satu platform terbaik untuk bermain slot Pragmatic di Indonesia. Apa yang membuat kami unggul? Kami memiliki sejumlah keunggulan yang akan membuat pengalaman bermain Anda lebih menyenangkan. Keamanan Terjamin Keamanan adalah prioritas utama kami di WINNING303. Kami menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan Anda. Dengan begitu, Anda dapat bermain dengan tenang tanpa perlu khawatir tentang keamanan informasi Anda. Beragam Pilihan Permainan Kami menyediakan berbagai macam permainan slot Pragmatic yang menarik dan menghibur. Mulai dari tema klasik hingga yang paling modern, Anda pasti akan menemukan permainan yang sesuai dengan selera Anda di WINNING303. Selain itu, kami juga secara teratur memperbarui koleksi permainan kami untuk memberikan pengalaman bermain yang segar dan menarik setiap saat. Kemudahan Deposit Via Bank Niaga 24 Jam Kami mengerti bahwa kenyamanan dalam bertransaksi sangatlah penting bagi para pemain. Oleh karena itu, kami menyediakan layanan deposit melalui Bank Niaga yang dapat diakses 24 jam sehari, 7 hari seminggu. Prosesnya cepat dan mudah, sehingga Anda dapat langsung memulai permainan tanpa menunggu waktu lama. Bonus dan Promosi Menarik Di WINNING303, kami selalu memberikan bonus dan promosi yang menggiurkan bagi para pemain setia kami. Mulai dari bonus selamat datang hingga bonus deposit, ada banyak penawaran menarik yang dapat Anda manfaatkan untuk meningkatkan peluang kemenangan Anda.         
    • LINK DAFTAR KLIK DISINI Slot Bank BJB adalah situs slot online paling mudah untuk meraih JP (JackPot). Mainkan slot online pada link Slot Bank BJB untuk mendapatkan bonus New member hanya dengan deposit 5000 Ribu Tanpa TO dan raih JP instant BJB hari ini! Lihat dan amati cara bermain dari pro player untuk menambah kemampuan anda dalam memainkan slot online!
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.