Fixed Armor and Elytra item interaction 1.19.4 -> 1.19.3

This commit is contained in:
FlorianMichael 2023-03-22 16:33:34 +01:00
parent 6adb66da2a
commit 76b64552ce
4 changed files with 126 additions and 2 deletions

View File

@ -118,7 +118,7 @@ public abstract class MixinPlayerEntity extends LivingEntity {
public boolean viafabricplus_isSprinting;
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;setMovementSpeed(F)V"))
public void updateFlyingSpeed(CallbackInfo ci) {
public void trackOldField(CallbackInfo ci) {
viafabricplus_isSprinting = this.isSprinting();
}

View File

@ -0,0 +1,61 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stat.Stats;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ArmorItem.class)
public class MixinArmorItem extends Item {
public MixinArmorItem(Settings settings) {
super(settings);
}
@Inject(method = "use", at = @At("HEAD"), cancellable = true)
public void implementLegacyAction(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_19_3)) {
ItemStack itemStack = user.getStackInHand(hand);
EquipmentSlot equipmentSlot = MobEntity.getPreferredEquipmentSlot(itemStack);
ItemStack itemStack2 = user.getEquippedStack(equipmentSlot);
if (itemStack2.isEmpty()) {
user.equipStack(equipmentSlot, itemStack.copy());
if (!world.isClient()) {
user.incrementStat(Stats.USED.getOrCreateStat(this));
}
itemStack.setCount(0);
cir.setReturnValue(TypedActionResult.success(itemStack, world.isClient()));
}
cir.setReturnValue(TypedActionResult.fail(itemStack));
}
}
}

View File

@ -0,0 +1,61 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ElytraItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stat.Stats;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ElytraItem.class)
public class MixinElytraItem extends Item {
public MixinElytraItem(Settings settings) {
super(settings);
}
@Inject(method = "use", at = @At("HEAD"), cancellable = true)
public void implementLegacyAction(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_19_3)) {
ItemStack itemStack = user.getStackInHand(hand);
EquipmentSlot equipmentSlot = MobEntity.getPreferredEquipmentSlot(itemStack);
ItemStack itemStack2 = user.getEquippedStack(equipmentSlot);
if (itemStack2.isEmpty()) {
user.equipStack(equipmentSlot, itemStack.copy());
if (!world.isClient()) {
user.incrementStat(Stats.USED.getOrCreateStat(this));
}
itemStack.setCount(0);
cir.setReturnValue(TypedActionResult.success(itemStack, world.isClient()));
}
cir.setReturnValue(TypedActionResult.fail(itemStack));
}
}
}

View File

@ -147,7 +147,9 @@
"fixes.viaversion.protocol1_9to1_8.MixinEntityTracker1_9",
"fixes.viaversion.protocol1_9to1_8.MixinMetadataRewriter1_9To1_8",
"fixes.viaversion.protocol1_9to1_8.MixinMovementTracker",
"fixes.viaversion.protocol1_9to1_8.MixinViaIdleThread"
"fixes.viaversion.protocol1_9to1_8.MixinViaIdleThread",
"fixes.minecraft.item.MixinArmorItem",
"fixes.minecraft.item.MixinElytraItem"
],
"injectors": {
"defaultRequire": 1