Jump to content

Recommended Posts

Posted

I am trying to change a mob's drops as if they were killed with Looting, but without using an enchanted item. The best I could come up with is to hook into LivingDropsEvent, and do this:

 

if (!mob.isChild() && mob.worldObj.getGameRules().getBoolean("doMobLoot")) {
mob.capturedDrops.clear();
mob.captureDrops = true;

try {
	Method dropFewItems = mob.getClass().getMethod("dropFewItems", boolean.class, int.class);
	Method dropEquipment = mob.getClass().getMethod("dropEquipment", boolean.class, int.class);
	Method addRandomDrop = mob.getClass().getMethod("addRandomDrop");

	dropFewItems.invoke(mob, true, customLootingLevel);
	dropEquipment.invoke(mob, true, customLootingLevel);

        if (mob.worldObj.rand.nextFloat() < 0.025F + (float)customLootingLevel* 0.01F) {
            addRandomDrop.invoke(mob);
        }
        
        mob.captureDrops = false;
        event.drops.clear();
	event.drops.addAll(mob.capturedDrops);
}

 

I now have 2 probems:

1. I am getting this error:

 java.lang.NoSuchMethodException: net.minecraft.entity.passive.EntityChicken.dropFewItems(boolean, int)

 

2. I realized this might break when its re-obfuscated because the method names change.

 

What is the best way to do this?

Posted

Is it also possible to get the Method with getDeclaredMethods() and then using the right number ? Or is the position changing (on server/client side, deobfuscated/reobfuscated)

catch(Exception e)

{

 

}

Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).

Posted

Using the index is a very unreliable method.

 

Is it better to iterate over the array and check params and return type ?

catch(Exception e)

{

 

}

Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).

Posted

First of all, look up the methods once and store them in a static field. You will also need to use

getDeclaredMethod

, since

getMethod

only works with public methods (read the JavaDocs on the methods you use -.-).

You will also have to call

setAccessible

on the Method objects, since they are protected.

 

Then you have to choose the correct method name based on

(Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment")

. If that is true, use the normal MCP name you can see in your source code. If it is false, you need to use the SRG name, which you can look up using MCPBot.

 

Moreover:

Do not mess with

mob.capturedDrops

or

mob.captureDrops

at all. Call

event.drops.clear()

before you invoke the methods, then invoke them. That is all you need to do.

 

Great advice, its working great now. I should add that I had to call getDeclaredMethod on EntityLivingBase.class, not the mob's class (if anybody else runs into this same problem).

 

The only thing left is: addRandomDrop. I checked methods.csv on the most recent MCP, and I can't find it. I found another mod that uses is, and decompiled to find func_82164_bB... but after some googling, I feel like that maps to something regarding armor. Am I missing something here?

Posted

Thanks! Here are some snippets of code I used to get this working:

 

private static Method dropFewItems;
private static Method dropEquipment;
private static Method addRandomDrop;

 

Boolean deobf = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
dropFewItems = EntityLivingBase.class.getDeclaredMethod(deobf ? "dropFewItems" : "func_70628_a",
	boolean.class, int.class);
dropEquipment = EntityLivingBase.class.getDeclaredMethod(deobf ? "dropEquipment" : "func_82160_b",
	boolean.class, int.class);
addRandomDrop = EntityLivingBase.class.getDeclaredMethod(deobf ? "addRandomDrop" : "func_82164_bB");
dropFewItems.setAccessible(true);
dropEquipment.setAccessible(true);
addRandomDrop.setAccessible(true);

 

 

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

    • https://mclo.gs/46Xf7Sq thanks
    • That seems to have fixed it, thank you!
    • I am having some issues starting an RLCraft server on a minimal install of Debian 12. I have Java installed and I'm able to start the vanilla Minecraft server jar no problem and people can join and play without any issues, as soon as I try to create a new directory with the Forge jar the initial install with the INSTALLER jar works when I use the java command with the --installServer flag, but as soon as I try to start the server using the forge jar that is NOT labelled with installer I get the following error: A problem occurred running the Server launcher.java.lang.reflect.InvocationTargetException         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)         at java.base/java.lang.reflect.Method.invoke(Method.java:569)         at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:70)         at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:34) Caused by: java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')         at net.minecraft.launchwrapper.Launch.<init>(Launch.java:34)         at net.minecraft.launchwrapper.Launch.main(Launch.java:28)         ... 6 more   I have tried using newer versions of Java directly from Oracle as well. Has anybody been successful in starting and running a RLCraft server from the terminal on a Linux machine? I cannot figure out why it doesn't want to work but the vanilla jar works without issue. Thank you in advance!
    • This is my latest attempt :  public class ManaScreen extends Screen { Mana mana = new Mana(); boolean removeManaBar = false; ResourceLocation manaBar = ResourceLocation.fromNamespaceAndPath(RSGArmoury.MOD_ID, "/textures/block/spawnable_arena_wall.png"); public ManaScreen() { super(Component.literal("Mana")); } @Override protected void init() { super.init(); Minecraft.getInstance().setScreen(this); } @Override public boolean isPauseScreen() { return false; } @Override public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) { pGuiGraphics.blit(manaBar, 10, -10, 0, 0, mana.getMana(), 10, mana.getMana(), 10); if (removeManaBar) { this.onClose(); return; } super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick); } public void addManaBar() { removeManaBar = false; Minecraft.getInstance().setScreen(new ManaScreen()); } public boolean removeManaBar() { return removeManaBar = true; } }
  • Topics

×
×
  • Create New...

Important Information

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