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 admit, I've never worked with events so it's probably something I'm overlooking but anyhow...

 

I'm trying to get a vanilla block to drop not only it's own item drop but also to have a chance of dropping a custom one.

 

Here's my Event code:

 

package com.holydevils.event;

import java.util.List;

import com.holydevils.items.ModItems;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class ModHarvestDropsEvent {
@SubscribeEvent
public void onHarvestBlock(BlockEvent.HarvestDropsEvent event)
{
	List<ItemStack> currentDrops = event.getDrops();
	final EntityPlayer PLAYER = event.getHarvester();
	if(null == PLAYER || null == PLAYER.getHeldItemMainhand()) return;

	if(event.getState().getBlock() == Blocks.DIAMOND_ORE && event.getWorld().rand.nextInt(100) < 75)
	{
		currentDrops.add(new ItemStack(ModItems.diamondDust, 1));
	}

	if(event.getState().getBlock() == Blocks.OBSIDIAN && event.getWorld().rand.nextInt(100) < 75)
	{
		currentDrops.add(new ItemStack(ModItems.obsidianDust, 1));
	}
	event.getDrops().clear();
	event.getDrops().addAll(currentDrops);
}
}

 

 

And here's my main registry:

 

package com.holydevils.main;

import com.holydevils.blocks.ModBlocks;
import com.holydevils.client.render.items.ItemRenderRegistry;
import com.holydevils.event.ModHarvestDropsEvent;
import com.holydevils.items.ModItems;
import com.holydevils.lib.StringReferences;
import com.holydevils.world.ModWorld;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = StringReferences.MODID, name =StringReferences.NAME, version =StringReferences.VERSION)
public class MainRegistry {
@SidedProxy(clientSide = StringReferences.CLIENTPROXY, serverSide = StringReferences.SERVERPROXY)
public static ServerProxy proxyServer;
public static ModWorld mWorld = new ModWorld();

@EventHandler
public static void preLoad(FMLPreInitializationEvent PreEvent){
	ModItems.createItems();
	ModBlocks.manageBlocks();

	CraftingManager.craftRegister();

	GameRegistry.registerWorldGenerator(mWorld, 1);

	proxyServer.registerRenderInfo();
}
public static void load(FMLInitializationEvent Event){
}

public static void postLoad(FMLPostInitializationEvent PostEvent){
	MinecraftForge.EVENT_BUS.register(new ModHarvestDropsEvent());
}
}

 

Note: I've tried registering it in both load and postLoad. If I put it into preLoad the default item it's self only droppes randomly.

That code should work and it should be in your load method. Can you be a little more detailed when explaining the problem?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author

Try doing event.getDrops().add instead of resetting the list.

 

I tried doing that and it didn't work so what I did was add " || true" to the if statements and it still didn't drop the item... And before you ask, I did move it to the load method.

When I said use event.getDrops.add(...) did you remove the clear and the new List you made from the method? Is it dropping any Items at all?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author

When I said use event.getDrops.add(...) did you remove the clear and the new List you made from the method? Is it dropping any Items at all?

 

It only drops the default item and yes I did remove the things that you mentioned

 

Updated code:

 

package com.holydevils.event;

import java.util.List;

import com.holydevils.items.ModItems;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class ModHarvestDropsEvent {
@SubscribeEvent
public void onHarvestBlock(BlockEvent.HarvestDropsEvent event)
{
	final EntityPlayer PLAYER = event.getHarvester();
	if(null == PLAYER || null == PLAYER.getHeldItemMainhand()) return;

	if(event.getState().getBlock() == Blocks.DIAMOND_ORE && event.getWorld().rand.nextInt(100) < 75 || true)
	{
		event.getDrops().add(new ItemStack(ModItems.diamondDust, 1));
	}

	if(event.getState().getBlock() == Blocks.OBSIDIAN && event.getWorld().rand.nextInt(100) < 75 || true)
	{
		event.getDrops().add(new ItemStack(ModItems.obsidianDust, 1));
	}
}
}

 

By chance do you have a github or skype/discord? And do the Items exist in the game?

 

*Edit you don't have @EventHandler above your load and postLoad methods.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

*Edit you don't have @EventHandler above your load and postLoad methods.

Yeah I didn't notice this before, but making a github is recommended for later posts.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author

*Edit you don't have @EventHandler above your load and postLoad methods.

Yeah I didn't notice this before, but making a github is recommended for later posts.

 

Ok, Thx!

Guest
This topic is now closed to further replies.

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.