Use Local annotation in mixins instead of capture locals

This commit is contained in:
FlorianMichael 2024-08-31 23:16:17 +02:00
parent 98e9d9b2c1
commit b0c8e96cc0
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
3 changed files with 11 additions and 8 deletions

View File

@ -19,6 +19,7 @@
package de.florianmichael.viafabricplus.injection.mixin.base.perserverversion;
import com.llamalad7.mixinextras.sugar.Local;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.injection.access.IServerInfo;
import de.florianmichael.viafabricplus.save.impl.SettingsSave;
@ -48,15 +49,15 @@ public abstract class MixinServerInfo implements IServerInfo {
@Unique
private ProtocolVersion viaFabricPlus$translatingVersion;
@Inject(method = "toNbt", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD)
private void saveForcedVersion(CallbackInfoReturnable<NbtCompound> cir, NbtCompound nbtCompound) {
@Inject(method = "toNbt", at = @At("TAIL"))
private void saveForcedVersion(CallbackInfoReturnable<NbtCompound> cir, @Local NbtCompound nbtCompound) {
if (viaFabricPlus$forcedVersion != null) {
nbtCompound.putString("viafabricplus_forcedversion", viaFabricPlus$forcedVersion.getName());
}
}
@Inject(method = "fromNbt", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD)
private static void loadForcedVersion(NbtCompound root, CallbackInfoReturnable<ServerInfo> cir, ServerInfo serverInfo) {
@Inject(method = "fromNbt", at = @At("TAIL"))
private static void loadForcedVersion(NbtCompound root, CallbackInfoReturnable<ServerInfo> cir, @Local ServerInfo serverInfo) {
if (root.contains("viafabricplus_forcedversion")) {
final ProtocolVersion version = SettingsSave.protocolVersionByName(root.getString("viafabricplus_forcedversion"));
if (version != null) {

View File

@ -19,6 +19,7 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity;
import com.llamalad7.mixinextras.sugar.Local;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.fixes.versioned.visual.BoatRenderer1_8;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
@ -42,8 +43,8 @@ public abstract class MixinEntityRenderDispatcher {
@Unique
private BoatRenderer1_8 viaFabricPlus$boatRenderer;
@Inject(method = "reload", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD)
private void createBoatRenderer1_8(ResourceManager manager, CallbackInfo ci, EntityRendererFactory.Context context) {
@Inject(method = "reload", at = @At("TAIL"))
private void createBoatRenderer1_8(ResourceManager manager, CallbackInfo ci, @Local EntityRendererFactory.Context context) {
viaFabricPlus$boatRenderer = new BoatRenderer1_8(context);
}

View File

@ -19,6 +19,7 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion;
import com.llamalad7.mixinextras.sugar.Local;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
@ -59,8 +60,8 @@ public abstract class MixinItemPacketRewriter1_14 extends ItemRewriter<Clientbou
this.protocol.registerServerbound(ServerboundPackets1_14.SELECT_TRADE, ServerboundPackets1_13.SELECT_TRADE, null, true);
}
@Inject(method = "lambda$registerPackets$0", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/util/ProtocolLogger;warning(Ljava/lang/String;)V", remap = false), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void supportLargeContainers(PacketWrapper wrapper, CallbackInfo ci, Short windowId, String type, JsonElement title, Short slots) {
@Inject(method = "lambda$registerPackets$0", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/util/ProtocolLogger;warning(Ljava/lang/String;)V", remap = false), cancellable = true)
private void supportLargeContainers(PacketWrapper wrapper, CallbackInfo ci, @Local(ordinal = 0) Short windowId, @Local String type, @Local JsonElement title, @Local(ordinal = 1) Short slots) {
if ((type.equals("minecraft:container") || type.equals("minecraft:chest")) && (slots > 54 || slots <= 0)) {
ci.cancel();