#Creating a subclass with native methods with ByteBuddy

1 messages · Page 1 of 1 (latest)

viral scarab
#

Hi !
I'm trying to create a subclass with byteBuddy, and I want to override some methods with a native one.
I have tried this :


        Class<?> dynamicType = new ByteBuddy()
                .subclass(Block.class)
                .name("fr.supersurviveur.rustcraftmod.DynamicBlock")
//                .defineMethod("onUse", ActionResult.class, Modifier.PUBLIC)
//                .withParameters(BlockState.class, World.class, BlockPos.class, PlayerEntity.class, Hand.class, BlockHitResult.class)
//                .intercept(MethodDelegation.to(new Test()))
                .defineMethod("onUse", ActionResult.class, Modifier.NATIVE | Modifier.PUBLIC)
                .withoutCode()
                .make()
                .load(getClass().getClassLoader())
                .getLoaded();

But i got this error : Caused by: java.lang.IllegalStateException: Cannot define abstract method 'onUse' for non-abstract class
Thank you !

cloud wolfBOT
# viral scarab Hi ! I'm trying to create a subclass with byteBuddy, and I want to override some...

Detected code, here are some useful tools:

Formatted code
Class<? > dynamicType = new ByteBuddy().subclass(Block.class ).name("fr.supersurviveur.rustcraftmod.DynamicBlock") //                .defineMethod("onUse", ActionResult.class, Modifier.PUBLIC)
//                .withParameters(BlockState.class, World.class, BlockPos.class, PlayerEntity.class, Hand.class, BlockHitResult.class)
//                .intercept(MethodDelegation.to(new Test()))
.defineMethod("onUse", ActionResult.class , Modifier.NATIVE | Modifier.PUBLIC).withoutCode().make().load(getClass().getClassLoader()).getLoaded();
#

<@&987246399047479336> please have a look, thanks.

cloud wolfBOT
#

@viral scarab

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure 👍

boreal igloo
viral scarab
boreal igloo
#

I don't think you can implement abstract methods with native ones

#

So that'd be it

viral scarab
#

But if I create a class like

class Foo extends Block {
  ...
  public native ActionResult onUse(....);
}
#

It works fine

boreal igloo
#

With @Override?

viral scarab
#

Yes

boreal igloo
#

hm ok

#

haven't touched native stuff yet

#

I guess bytebuddy is just confused about it

#

I've already looked around a bit and the only example I could find used the exact same methods and nothing more

viral scarab
#

I have already created a block (from Minecraft fabric if it helps) who call a native lib onUse, so I don't understand why byte buddy fail

viral scarab
boreal igloo
#

Probably the same one I found, yeah

#

I think it is fair to create an issue on the bytebuddy GitHub
You'll get an answer there if we're missing something

viral scarab
#

Ok, never created an issue before, but I will try, thank you !

viral scarab
boreal igloo
#

I think the issue is there somewhere

viral scarab
#

Edited

boreal igloo
#

Oh

#

Maybe you have to use method to select the inherited method

#

since it already exists

boreal igloo
#

oh wait you can't make it native then either

#

nvm

viral scarab
boreal igloo
#

yeah

viral scarab
#

But maybe I need to use ElementMatchers.named() with define method ?

boreal igloo
#

you can't do that right

#

defineMethod takes a string for the method name

viral scarab
#

Oh

cloud wolfBOT
#

@viral scarab

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure 👍

viral scarab
#

The bug was solved in the last commit of byte buddy

boreal igloo