I am making a mod in 1.16.5 with Forge to drop an emerald once 50 blocks of any kind have been broken, and I cannot figure it out. I have tried BlockEvent.BreakEvent, onBlockHarvested, and harvestBlock, but I cannot figure it out. Another problem is I cannot give the player an item, I have tried several ways. Can anyone help?
My current code is:
package com.taxolotl.cubitemerald;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;;
@Mod("cubitemerald")
public class CubitEmerald {
public static final Logger LOGGER = LogManager.getLogger();
public static final String MOD_ID = "cubitemerald";
public static int blok = 0;
public CubitEmerald() {
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
MinecraftForge.EVENT_BUS.register(this);
if(/*block broken*/) {
blok = blok + 1;
}
if(blok>=50) {
/*drop an emerald*/
blok = 0;
}
}
}