Jump to content

Has Forge figured out a way to replace a method (not override)?


Recommended Posts

Posted (edited)

I have learned how with Forge you can make private and/or final variables public and not final without reflection.  And how to add to enums at runtime even though they are supposed to always be read-only.  Very cool stuff.

 

So how about method replacement?  I know we can override things but if I want to modify vanilla behavior of existing mobs for example, I can't override that and there aren't really any hooks in place for most of what I am thinking.  My only option right now is to make new mobs and maybe disable the vanilla ones when they are replaced.  Or can we somehow override a vanilla method?

 

Edited by MrChoke
Posted
2 minutes ago, MrChoke said:

Or can we somehow override a vanilla method?

This is possible, but is not supported here and there are no tutorials. And ultimately the absolute last resort. You should just replace the entities with custom ones when they are spawned.

  • Thanks 1

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.

Posted

It is possible but it’s absolutely painful and requires dealing with the raw bytecode of the method. It’s painful, a single wrong thing will instantly crash everything, you need to pretty much learn 2 new languages (ASM & Java Bytecode) and you will have no support from anywhere (online tutorials are also a bit non existent).

3 hours ago, Animefan8888 said:

ultimately the absolute last resort

It shouldn’t even be a last resort. If your using it, your doing something wrong.

You should try submitting a PR to forge if you want hooks. It’s a slow process, but you will get a lot of feedback.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Wait, what are you trying to do exactly? You already can customize vanilla mobs completely. You can change all their AI, change all their attributes, change their models and textures, and fully intercept their update methods.

 

If you want to change anything vanilla you should look for ways in this order:

1) Look for natively public methods and fields. There are really quite a lot of these. For example, all entity AI is kept in public task List fields that you can directly manipulate completely.

2) Events. There are already events for most things you would want to mod.

3) Substitutions. You can do things like handle the event when an entity joins the world and replace with your own version. You can do similar thing with blocks during chunk populate event. Some of the modern registries can be manipulated to do substitutions as well.

4) Reflection. You can literally replace comprehensive things by accessing the various singleton fields in classes like the Minecraft class. For example you can replace the mouse helper class, or replace the item renderer or the global renderer or the texture manager or the model manager or whatever. Those are "intrusive" and can cause incompatibility with other mobs, but they are possible.

 

Anyway, mobs are particularly well covered by Forge. What are you trying to do that you think you can't?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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

    • Try other builds of this modpack or report it to the modpack creator Looks like an issue with environmental, naturalist and/or crafttweaker
    • Hello! There is an issue with my world(Chocolate Edition modpack), after joining the world all creatures are frozen and the game is not responding or the game crashes after short period of time. Reproduction Steps: Turn on the game Join the world Game crashes immediately or after short period of time. Additional info: Crash log saying that an entity crashed the game is created after the crash(not the logs that I posted, different file from crash-logs, game crashed 3x by Snail, 1x by Small Snail, 1x by Tortoise) Specification: CPU: i5-13600KF GPU: GTX 1070 RAM: 32GB 3200MhZ - allocated 10GB Log links: latest.log: https://mclo.gs/Lp8zlsv crash-reports/crash: https://mclo.gs/XhtyJQI Minecraft version: 1.19.2 Modpack Version: Chocolate Edition 1.9 OS: Windows 10 Java Version: 22.0.2 Minecraft Java: Java 17
    • Hello, for several days I've been trying to find a way to add my animations in this style. @Override public void setupAnim(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { }   My current public class is : public class FakePlayerModelWithAnim<T extends FakePlayerEntity> extends EntityModel<EntityRenderState>   But i can't do that :  public class FakePlayerModelWithAnim<T extends FakePlayerEntity> extends EntityModel<T> Type parameter 'T' is not within its bound; should extend 'net.minecraft.client.renderer.entity.state.EntityRenderState' But with EntityRenderState it ok and it work !   But my setupAnim look like this :  @Override public void setupAnim(EntityRenderState p_370046_) { super.setupAnim(p_370046_); }   I don't have any access to my entity ! Look like 1.21.1 : @Override public void setupAnim(FakePlayerEntity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { this.root().getAllParts().forEach(ModelPart::resetPose); this.applyHeadRotation(netHeadYaw, headPitch); this.animateWalk(FakePlayerEntityAnimations.ANIM_PLAYERS_WALKING, limbSwing, limbSwingAmount, 2f, 2.5f); this.animate(entity.idleAnimationState, FakePlayerEntityAnimations.ANIM_PLAYERS_IDLE, ageInTicks, 1f); } But i'm stuck with new version of Forge...
    • Looks like an issue with abyssalsovereigns - this mod has functions that are not working on a server (client-side-only mod)
    • I added some new mods and updated old ones to my forge server and they will run successfully but the moment I try to join ill briefly load into the world and get booted with the message, internal server error. The mods in question work fine on singleplayer and removing too many from the server causes it to stop working so I cant be sure which one is causing the problem... any ideas? server log: https://pastebin.com/hGH8UUjm client log (from modrinth app): https://mclo.gs/a3oOUGY
  • Topics

×
×
  • Create New...

Important Information

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