Skip to content

Commit

Permalink
Simplify AR mixin
Browse files Browse the repository at this point in the history
- Using `@Group` to consolidate v1.7.0 and v2.0.0 into one mixin
  • Loading branch information
jchung01 committed May 30, 2024
1 parent 82c251d commit 15ea752
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 65 deletions.
14 changes: 4 additions & 10 deletions src/main/java/org/dimdev/jeid/core/JEIDMixinLoader.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.dimdev.jeid.core;

import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import zone.rong.mixinbooter.ILateMixinLoader;

import java.util.ArrayList;
import java.util.List;

import net.minecraftforge.fml.common.Loader;

import zone.rong.mixinbooter.ILateMixinLoader;

public class JEIDMixinLoader implements ILateMixinLoader {
public List<String> getMixinConfigs() {
Expand All @@ -21,12 +20,7 @@ public List<String> getMixinConfigs() {
configs.add("mixins.jeid.abyssalcraft.json");
}
if (Loader.isModLoaded("advancedrocketry")) {
String version = Loader.instance().getIndexedModList().get("advancedrocketry").getVersion();
if (version.split("-")[1].contains(".") && Integer.parseInt(version.split("-")[1].split("\\.")[0]) >= 2) {
configs.add("mixins.jeid.advancedrocketry.v2_0_0.json");
} else {
configs.add("mixins.jeid.advancedrocketry.v1_7_0.json");
}
configs.add("mixins.jeid.advancedrocketry.json");
}
if (Loader.isModLoaded("atum")) {
configs.add("mixins.jeid.atum.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
package org.dimdev.jeid.mixin.modsupport.advancedrocketry.v1_7_0;
package org.dimdev.jeid.mixin.modsupport.advancedrocketry;

import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import org.dimdev.jeid.ducks.INewChunk;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Group;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import zmaster587.advancedRocketry.util.BiomeHandler;

/**
* Mixin for Advanced Rocketry 1.7.0
*/
@SuppressWarnings("target")
@Mixin(value = BiomeHandler.class, remap = false)
public class MixinBiomeHandler {
@Dynamic("Only present with AR 1.7.0")
@Shadow
public static void changeBiome(World world, int biomeId, BlockPos pos) {
}
// Do not use @Local sugar for these injectors, it doesn't handle invalid targets well!

@Dynamic("Use int biome array for AR 1.7.0")
@Inject(method = "changeBiome(Lnet/minecraft/world/World;ILnet/minecraft/util/math/BlockPos;)V", at = @At(value = "INVOKE", target = "Lzmaster587/libVulpes/network/PacketHandler;sendToNearby(Lzmaster587/libVulpes/network/BasePacket;ILnet/minecraft/util/math/BlockPos;D)V"), require = 0)
private static void reid$toIntBiomeArray1_7_0(World world, int biomeId, BlockPos pos, CallbackInfo ci, @Local Chunk chunk) {
@Group(name = "versionAgnosticAR", min = 1, max = 2)
@Inject(method = "changeBiome(Lnet/minecraft/world/World;ILnet/minecraft/util/math/BlockPos;)V", at = @At(value = "INVOKE", target = "Lzmaster587/libVulpes/network/PacketHandler;sendToNearby(Lzmaster587/libVulpes/network/BasePacket;ILnet/minecraft/util/math/BlockPos;D)V"), locals = LocalCapture.CAPTURE_FAILHARD, require = 0)
private static void reid$toIntBiomeArray1_7_0(World world, int biomeId, BlockPos pos, CallbackInfo ci, Chunk chunk) {
((INewChunk) chunk).getIntBiomeArray()[(pos.getZ() & 0xF) << 4 | pos.getX() & 0xF] = biomeId;
chunk.markDirty();
// Method sends packet
}

@Dynamic("Overload for AR 1.7.0")
@Group(name = "versionAgnosticAR", min = 1, max = 2)
@Inject(method = "changeBiome(Lnet/minecraft/world/World;ILnet/minecraft/world/chunk/Chunk;Lnet/minecraft/util/math/BlockPos;)V", at = @At(value = "HEAD"), cancellable = true, require = 0)
private static void reid$toIntBiomeArray1_7_0Chunk(World world, int biomeId, Chunk chunk, BlockPos pos, CallbackInfo ci) {
changeBiome(world, biomeId, pos);
BiomeHandler.changeBiome(world, biomeId, pos);
ci.cancel();
}

@Dynamic("Use int biome array for AR 2.0.0")
@Group(name = "versionAgnosticAR", min = 1, max = 2)
@Inject(method = "changeBiome(Lnet/minecraft/world/World;Lnet/minecraft/world/biome/Biome;Lnet/minecraft/util/math/BlockPos;)V", at = @At(value = "INVOKE", target = "Lzmaster587/libVulpes/network/PacketHandler;sendToNearby(Lzmaster587/libVulpes/network/BasePacket;ILnet/minecraft/util/math/BlockPos;D)V"), locals = LocalCapture.CAPTURE_FAILHARD, require = 0)
private static void reid$toIntBiomeArray2_0_0(World world, Biome biomeId, BlockPos pos, CallbackInfo ci, Chunk chunk) {
((INewChunk) chunk).getIntBiomeArray()[(pos.getZ() & 0xF) << 4 | pos.getX() & 0xF] = Biome.getIdForBiome(biomeId);
chunk.markDirty();
// Method sends packet
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": [
"v1_7_0.MixinBiomeHandler",
"MixinBiomeHandler",
"MixinPacketBiomeIDChange"
]
}
11 changes: 0 additions & 11 deletions src/main/resources/mixins.jeid.advancedrocketry.v2_0_0.json

This file was deleted.

0 comments on commit 15ea752

Please sign in to comment.