Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Converting mods from Fabric to Forge


Samv2005
 Share

Recommended Posts

I'm trying to convert the Expanded Origins addon (https://www.curseforge.com/minecraft/mc-mods/origins-plus) from Fabric to Forge for the Monke origin, but I'm having some trouble with it, as I know next to nothing about programming. So far, what I did was move most of the files from Expanded Origins to a forge Origins addon that I almost completely cleared out, since a good chunk of the code is identical. This kind of worked, as most of the abilities stuck around, but the main ability (grappling) won't work since it requires a few .CLASS files that aren't coded the same way forge is. After finding what I believe to be one of the main files for the grapple, I compared the files for forge Origins to the files for fabric Origins, and found that the key difference was that in the lines with "import net.minecraft.class_xxxx", the "class_xxxx" was replaced with the forge counterpart (usually entity.something, util.something, or network.something). This was also true for field_xxxx and method_xxxx. Currently, my main issue is that I can't test the changes since in order to edit the code, I had to convert it to .java, and now whenever I try to convert it back to .CLASS, it gives me this error message:

Spoiler

r2.java:11: error: class, interface, or enum expected
package com.github.originsplus.power;
^
r2.java:13: error: class, interface, or enum expected
import com.github.originsplus.entity.IGrappleHook;
^
r2.java:14: error: class, interface, or enum expected
import io.github.apace100.origins.power.ActiveCooldownPower;
^
r2.java:15: error: class, interface, or enum expected
import io.github.apace100.origins.power.PowerType;
^
r2.java:16: error: class, interface, or enum expected
import io.github.apace100.origins.util.HudRender;
^
r2.java:17: error: class, interface, or enum expected
import net.minecraft.entity.Entity;
^
r2.java:18: error: class, interface, or enum expected
import net.minecraft.entity.projectile.FishingBobberEntity;
^
r2.java:19: error: class, interface, or enum expected
import net.minecraft.entity.player.PlayerEntity;
^
r2.java:20: error: class, interface, or enum expected
import net.minecraft.util.math.vector.Vector3d;
^
r2.java:21: error: class, interface, or enum expected
import net.minecraft.network.Packet;
^
r2.java:22: error: class, interface, or enum expected
import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket;
^
r2.java:23: error: class, interface, or enum expected
import net.minecraft.entity.player.ServerPlayerEntity;
^
r2.java:24: error: class, interface, or enum expected
import net.minecraft.util.SoundEvent;
^
r2.java:25: error: class, interface, or enum expected
import net.minecraft.util.SoundCategory;
^
14 errors

I am using Eclipse IDE to edit the files. Also this is the code I am trying to convert, followed by the edited mod:

Spoiler

public class r {

    public static void main(String[] args) {
        //Printing Hello World    
        System.out.println("This is HelloWorld! example");

    }

}
package com.github.originsplus.power;

import com.github.originsplus.entity.IGrappleHook;
import io.github.apace100.origins.power.ActiveCooldownPower;
import io.github.apace100.origins.power.PowerType;
import io.github.apace100.origins.util.HudRender;
import net.minecraft.entity.Entity;
import net.minecraft.entity.projectile.FishingBobberEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.network.Packet;
import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundCategory;

public class GrapplePower extends ActiveCooldownPower {
    SoundEvent soundOnThrown;
  
    SoundEvent soundOnRetract;
  
  double strength;
  
  boolean thrown;
  
  FishingBobberEntity grappleHook;
  
  public GrapplePower(PowerType<?> type, PlayerEntity player, int cooldownDuration, HudRender hudRender, SoundEvent soundOnThrownEvent, SoundEvent soundOnRetractEvent, double strength) {
    super(type, player, cooldownDuration, hudRender, null);
    this.soundOnThrown = soundOnThrownEvent;
    this.soundOnRetract = soundOnRetractEvent;
    this.strength = strength;
    this.thrown = false;
  }
  
  public void onUse() {
    if (!this.player.field_70170_p.field_72995_K)
      if (this.thrown && !this.grappleHook.field_5988) {
        retractGrapple();
      } else if (canUse()) {
        throwGrapple();
        use();
      }  
  }
  
  private void throwGrapple() {
    if (this.soundOnThrown != null)
      this.player.field_70170_p.func_184148_a((PlayerEntity)null, this.player.func_226277_ct_(), this.player.func_226278_cu_(), this.player.func_226281_cx_(), this.soundOnThrown, SoundCategory.NEUTRAL, 0.5F, 0.4F / (this.player
          .func_70681_au().nextFloat() * 0.4F + 0.8F)); 
    FishingBobberEntity playerHook = this.player.field_7513;
    this.grappleHook = new FishingBobberEntity(this.player, this.player.field_70170_p, 0, 0);
    ((IGrappleHook)this.grappleHook).setGrapple(true);
    this.player.field_7513 = playerHook;
    this.player.field_70170_p.func_217376_c((Entity)this.grappleHook);
    this.thrown = true;
  }
  
  private void retractGrapple() {
    if (this.soundOnRetract != null)
      this.player.field_70170_p.func_184148_a((PowerType)null, this.player.func_226277_ct_(), this.player.func_226278_cu_(), this.player.func_226281_cx_(), this.soundOnRetract, SoundCategory.NEUTRAL, 0.5F, 0.4F / (this.player
          .func_70681_au().nextFloat() * 0.4F + 0.8F)); 
    Vector3d bobberPos = this.grappleHook.func_213303_ch();
    Vector3d distance = new Vector3d(bobberPos.field_72450_a - (this.player.func_213303_ch()).field_72450_a, bobberPos.field_72448_b - (this.player.func_213303_ch()).field_1351, bobberPos.field_72449_c - (this.player.func_213303_ch()).field_72449_c);
    distance = distance.func_72432_b();
    Vector3d velocity = new Vector3d(distance.field_72450_a * this.strength, distance.field_72448_b * this.strength, distance.field_72449_c * this.strength);
    Vector3d playerVelocity = this.player.func_213322_ci().func_178787_e(velocity);
    this.player.func_213317_d(playerVelocity);
    if (this.player instanceof ServerPlayerEntity) {
        ServerPlayerEntity serverPlayer = (ServerPlayerEntity)this.player;
      serverPlayer.field_13987.func_234923_W_((Packet)new EntityVelocityUpdateS2CPacket(this.player.method_5628(), playerVelocity));
    } 
    this.grappleHook.method_5768();
    this.thrown = false;
  }
}

mod:
https://www.dropbox.com/s/5447brs1zquzebw/Expanded Origins Forge.jar?dl=0

Link to comment
Share on other sites

10 hours ago, Samv2005 said:

as I know next to nothing about programming

Then unfortunately you need to first go and learn Java. Writing a mod without programming knowledge is not possible.

Also, first get permission from the original mod author to do this and then use their source code instead of trying to decompile the class files.

Link to comment
Share on other sites

  • 3 months later...
On 7/3/2021 at 6:21 PM, Samv2005 said:

I'm trying to convert the Expanded Origins addon (https://www.curseforge.com/minecraft/mc-mods/origins-plus) from Fabric to Forge for the Monke origin, but I'm having some trouble with it, as I know next to nothing about programming. So far, what I did was move most of the files from Expanded Origins to a forge Origins addon that I almost completely cleared out, since a good chunk of the code is identical. This kind of worked, as most of the abilities stuck around, but the main ability (grappling) won't work since it requires a few .CLASS files that aren't coded the same way forge is. After finding what I believe to be one of the main files for the grapple, I compared the files for forge Origins to the files for fabric Origins, and found that the key difference was that in the lines with "import net.minecraft.class_xxxx", the "class_xxxx" was replaced with the forge counterpart (usually entity.something, util.something, or network.something). This was also true for field_xxxx and method_xxxx. Currently, my main issue is that I can't test the changes since in order to edit the code, I had to convert it to .java, and now whenever I try to convert it back to .CLASS, it gives me this error message:

  Reveal hidden contents

r2.java:11: error: class, interface, or enum expected
package com.github.originsplus.power;
^
r2.java:13: error: class, interface, or enum expected
import com.github.originsplus.entity.IGrappleHook;
^
r2.java:14: error: class, interface, or enum expected
import io.github.apace100.origins.power.ActiveCooldownPower;
^
r2.java:15: error: class, interface, or enum expected
import io.github.apace100.origins.power.PowerType;
^
r2.java:16: error: class, interface, or enum expected
import io.github.apace100.origins.util.HudRender;
^
r2.java:17: error: class, interface, or enum expected
import net.minecraft.entity.Entity;
^
r2.java:18: error: class, interface, or enum expected
import net.minecraft.entity.projectile.FishingBobberEntity;
^
r2.java:19: error: class, interface, or enum expected
import net.minecraft.entity.player.PlayerEntity;
^
r2.java:20: error: class, interface, or enum expected
import net.minecraft.util.math.vector.Vector3d;
^
r2.java:21: error: class, interface, or enum expected
import net.minecraft.network.Packet;
^
r2.java:22: error: class, interface, or enum expected
import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket;
^
r2.java:23: error: class, interface, or enum expected
import net.minecraft.entity.player.ServerPlayerEntity;
^
r2.java:24: error: class, interface, or enum expected
import net.minecraft.util.SoundEvent;
^
r2.java:25: error: class, interface, or enum expected
import net.minecraft.util.SoundCategory;
^
14 errors

I am using Eclipse IDE to edit the files. Also this is the code I am trying to convert, followed by the edited mod:

  Reveal hidden contents

public class r {

    public static void main(String[] args) {
        //Printing Hello World    
        System.out.println("This is HelloWorld! example");

    }

}
package com.github.originsplus.power;

import com.github.originsplus.entity.IGrappleHook;
import io.github.apace100.origins.power.ActiveCooldownPower;
import io.github.apace100.origins.power.PowerType;
import io.github.apace100.origins.util.HudRender;
import net.minecraft.entity.Entity;
import net.minecraft.entity.projectile.FishingBobberEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.network.Packet;
import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundCategory;

public class GrapplePower extends ActiveCooldownPower {
    SoundEvent soundOnThrown;
  
    SoundEvent soundOnRetract;
  
  double strength;
  
  boolean thrown;
  
  FishingBobberEntity grappleHook;
  
  public GrapplePower(PowerType<?> type, PlayerEntity player, int cooldownDuration, HudRender hudRender, SoundEvent soundOnThrownEvent, SoundEvent soundOnRetractEvent, double strength) {
    super(type, player, cooldownDuration, hudRender, null);
    this.soundOnThrown = soundOnThrownEvent;
    this.soundOnRetract = soundOnRetractEvent;
    this.strength = strength;
    this.thrown = false;
  }
  
  public void onUse() {
    if (!this.player.field_70170_p.field_72995_K)
      if (this.thrown && !this.grappleHook.field_5988) {
        retractGrapple();
      } else if (canUse()) {
        throwGrapple();
        use();
      }  
  }
  
  private void throwGrapple() {
    if (this.soundOnThrown != null)
      this.player.field_70170_p.func_184148_a((PlayerEntity)null, this.player.func_226277_ct_(), this.player.func_226278_cu_(), this.player.func_226281_cx_(), this.soundOnThrown, SoundCategory.NEUTRAL, 0.5F, 0.4F / (this.player
          .func_70681_au().nextFloat() * 0.4F + 0.8F)); 
    FishingBobberEntity playerHook = this.player.field_7513;
    this.grappleHook = new FishingBobberEntity(this.player, this.player.field_70170_p, 0, 0);
    ((IGrappleHook)this.grappleHook).setGrapple(true);
    this.player.field_7513 = playerHook;
    this.player.field_70170_p.func_217376_c((Entity)this.grappleHook);
    this.thrown = true;
  }
  
  private void retractGrapple() {
    if (this.soundOnRetract != null)
      this.player.field_70170_p.func_184148_a((PowerType)null, this.player.func_226277_ct_(), this.player.func_226278_cu_(), this.player.func_226281_cx_(), this.soundOnRetract, SoundCategory.NEUTRAL, 0.5F, 0.4F / (this.player
          .func_70681_au().nextFloat() * 0.4F + 0.8F)); 
    Vector3d bobberPos = this.grappleHook.func_213303_ch();
    Vector3d distance = new Vector3d(bobberPos.field_72450_a - (this.player.func_213303_ch()).field_72450_a, bobberPos.field_72448_b - (this.player.func_213303_ch()).field_1351, bobberPos.field_72449_c - (this.player.func_213303_ch()).field_72449_c);
    distance = distance.func_72432_b();
    Vector3d velocity = new Vector3d(distance.field_72450_a * this.strength, distance.field_72448_b * this.strength, distance.field_72449_c * this.strength);
    Vector3d playerVelocity = this.player.func_213322_ci().func_178787_e(velocity);
    this.player.func_213317_d(playerVelocity);
    if (this.player instanceof ServerPlayerEntity) {
        ServerPlayerEntity serverPlayer = (ServerPlayerEntity)this.player;
      serverPlayer.field_13987.func_234923_W_((Packet)new EntityVelocityUpdateS2CPacket(this.player.method_5628(), playerVelocity));
    } 
    this.grappleHook.method_5768();
    this.thrown = false;
  }
}

mod:
https://www.dropbox.com/s/5447brs1zquzebw/Expanded Origins Forge.jar?dl=0

While I don't know how to port the mod, what you can do is extract the .jar file into a folder. Origins mods are compiled just like a datapack. All you have to do is drag and drop the folder into a world's datapack folder.

Link to comment
Share on other sites

8 hours ago, Toityle said:

While I don't know how to port the mod, what you can do is extract the .jar file into a folder. Origins mods are compiled just like a datapack. All you have to do is drag and drop the folder into a world's datapack folder.

Yes, jar files are just zip files. However that still only gives you .class files and you still don't have permission to do this.

Link to comment
Share on other sites

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.