Started by
filiprb
on
Topic category: Help with Minecraft modding (Java Edition)
I am trying to make bats drop chicken. The code I am using doesn't seem to be working. I am new to Java, so details are appreciated. If you are able of fixing the issue, please send new code and explain what I did wrong. THANKS!
I have tried many variations of this. If this method doesn't work, I would like to request some newly written code.
package net.mcreator.trevcorp_meat_paste;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraft.world.World;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.passive.EntityBat;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.boss.EntityWither;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
public class MCreatorBatMeat{
public static class RenderGameOverlayEvent{
@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
public void onEvent(LivingDropsEvent event)
{
if (event.entity instanceof EntityBat)
{
// DEBUG
System.out.println("EntityBat drops event");
event.drops.clear();
}
}
@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
public void onEvent(LivingDropsEvent event)
{
if (event.entity instanceof EntityBat)
{
// DEBUG
System.out.println("EntityBat drops event");
event.drops.clear();
ItemStack itemStackToDrop = new ItemStack(Items.CHICKEN, 2);
event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX,
event.entity.posY, event.entity.posZ, itemStackToDrop));
}
}
}
}
The console shows this when I run it:
Executing gradle command: runClient Build info: MCreator 1.9.1, 64-bit, 16227 MB, Windows 10 - cmd, JVM 1.8.0_222, JAVA_HOME: C:\Program Files\Pylo\MCreator\jdk C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste>gradlew -Dorg.gradle.java.home="C:/Program Files/Pylo/MCreator/jdk" -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs="-Xms625m -Xmx2048m" runClient This mapping 'snapshot_20171003' was designed for MC 1.12! Use at your own peril. :deobfCompileDummyTask :deobfProvidedDummyTask :sourceApiJava UP-TO-DATE :compileApiJava NO-SOURCE :processApiResources NO-SOURCE :apiClasses UP-TO-DATE :sourceMainJava UP-TO-DATE C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:25: error: method onEvent(LivingDropsEvent) is already defined in class RenderGameOverlayEvent public void onEvent(LivingDropsEvent event) { ^ C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:17: error: entity has private access in EntityEvent if (event.entity instanceof EntityBat) { ^ C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:20: error: drops has private access in LivingDropsEvent event.drops.clear(); ^ C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:26: error: entity has private access in EntityEvent if (event.entity instanceof EntityBat) { ^ C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:29: error: drops has private access in LivingDropsEvent event.drops.clear(); ^ C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:31: error: entity has private access in EntityEvent event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemStackToDrop)); ^ C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:31: error: cannot find symbol event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemStackToDrop)); ^ symbol: variable worldObj location: variable entity of type Entity C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:31: error: entity has private access in EntityEvent event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemStackToDrop)); ^ C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:31: error: entity has private access in EntityEvent event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemStackToDrop)); ^ C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:31: error: entity has private access in EntityEvent event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemStackToDrop)); ^ C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:31: error: drops has private access in LivingDropsEvent event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemStackToDrop)); ^ 11 errors :compileJava FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileJava'. > Compilation failed; see the compiler error output for details. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 6s 5 actionable tasks: 3 executed, 2 up-to-date C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste> Task completed with return code 0 in 8492 milliseconds
I know you said Java but you could do this in blockcode.
On event mob dies event If current entity = bat Drop gem chicken.
https://www.youtube.com/watch?v=sqxF0F1CmZo
How do I attach it to a vanilla entity?
You're a genius. Thank you.
Thank you.
The issue with the code seems to be that you have two methods with the same signature (name and parameters). Also, the entity variable is set to private in the event class, so you can't call it. There's probably a getEntity() method you can use in its place. Anyway yeah, easiest solution us using procedures