Skip to content

Commit

Permalink
fix(infoacc): bearing now stays in expected range
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-kirby committed Jul 8, 2024
1 parent 68548af commit 5e2f49d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version_base = 1.12.0
version_base = 1.13.0

# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public class SevPatchesLoadingPlugin implements IFMLLoadingPlugin {
public static String WOODEN_HOE;
public static String PRISMARINE_SHARD;

public static String ENTITY_ROTATION_YAW;
public static String POSITIVE_MODULO;
public static String FLOOR;

public SevPatchesLoadingPlugin() {
LOGGER.info("setting up mixin environment");
MixinBootstrap.init();
Expand Down Expand Up @@ -121,6 +125,10 @@ public void injectData(Map<String, Object> data) {

SevPatchesLoadingPlugin.WOODEN_HOE = dev ? "WOODEN_HOE" : "field_151017_I";
SevPatchesLoadingPlugin.PRISMARINE_SHARD = dev ? "PRISMARINE_SHARD" : "field_179562_cC";

SevPatchesLoadingPlugin.ENTITY_ROTATION_YAW = dev ? "rotationYaw" : "field_70177_z";
SevPatchesLoadingPlugin.POSITIVE_MODULO = dev ? "positiveModulo" : "func_188207_b";
SevPatchesLoadingPlugin.FLOOR = dev ? "floor" : "func_76141_d";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
return new PatchGalacticraftInventories(basicClass).apply();
case "micdoodle8.mods.galacticraft.planets.mars.entities.EntitySlimeling":
return new PatchGalacticraftSlimeling(basicClass).apply();
case "net.darkhax.infoaccessories.info.InfoType":
return new PatchInfoAccCompass(basicClass).apply();
default:
return basicClass;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package tv.darkosto.sevpatches.core.patches;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
import tv.darkosto.sevpatches.core.utils.AsmUtils;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import static tv.darkosto.sevpatches.core.SevPatchesLoadingPlugin.*;

public class PatchInfoAccCompass extends Patch {
public PatchInfoAccCompass(byte[] inputClass) {
super(inputClass);
}

@Override
protected boolean patch() {
MethodNode addDirectionInfo = AsmUtils.findMethod(this.classNode, "addDirectionInfo");
if (addDirectionInfo == null) return false;
InsnList insnlist = addDirectionInfo.instructions;

Iterable<AbstractInsnNode> insnsIter = insnlist::iterator;
Stream<AbstractInsnNode> insns = StreamSupport.stream(insnsIter.spliterator(), false);

// - int yaw = MathHelper.floor(player.rotationYaw % 360.0);
List<AbstractInsnNode> labels = insns.filter(insn -> insn instanceof LabelNode).collect(Collectors.toList());
int startIndex = insnlist.indexOf(labels.get(0)) + 2;
int endIndex = insnlist.indexOf(labels.get(1));

for (int i = startIndex; i < endIndex; i++) {
AbstractInsnNode insn = insnlist.get(startIndex);
insnlist.remove(insn);
}

// + int yaw = MathHelper.floor(MathHelper.positiveModulo(player.rotationYaw));
InsnList modYaw = new InsnList();
modYaw.add(new VarInsnNode(Opcodes.ALOAD, 1));
modYaw.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/entity/player/EntityPlayer", ENTITY_ROTATION_YAW, "F"));
modYaw.add(new LdcInsnNode(360.0f));
modYaw.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/minecraft/util/math/MathHelper", POSITIVE_MODULO, "(FF)F", false));
modYaw.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/minecraft/util/math/MathHelper", FLOOR, "(F)I", false));
modYaw.add(new VarInsnNode(Opcodes.ISTORE, 3));

insnlist.insert(labels.get(0), modYaw);

return true;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"modid": "sevpatches",
"name": "SevPatches",
"description": "Consolidated patches for mods that are EOL used in SevTech: Ages",
"version": "1.12.0",
"version": "1.13.0",
"mcversion": "1.12.2",
"url": "https://www.curseforge.com/minecraft/mc-mods/sevpatches",
"updateUrl": "",
Expand Down

0 comments on commit 5e2f49d

Please sign in to comment.