mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-09-19 03:11:00 +02:00
Simplified item interaction fix
This commit is contained in:
parent
740a439eff
commit
18b4340649
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 net.raphimc.vialoader.util.VersionEnum;
|
|
||||||
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(VersionEnum.r1_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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 net.raphimc.vialoader.util.VersionEnum;
|
|
||||||
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(VersionEnum.r1_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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,8 +18,10 @@
|
|||||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item;
|
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item;
|
||||||
|
|
||||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||||
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.Equipment;
|
import net.minecraft.item.Equipment;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.raphimc.vialoader.util.VersionEnum;
|
import net.raphimc.vialoader.util.VersionEnum;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@ -28,6 +30,23 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
|||||||
@Mixin(Equipment.class)
|
@Mixin(Equipment.class)
|
||||||
public interface MixinEquipment {
|
public interface MixinEquipment {
|
||||||
|
|
||||||
|
@Redirect(method = "equipAndSwap", at = @At(value = "INVOKE", target = "Lnet/minecraft/enchantment/EnchantmentHelper;hasBindingCurse(Lnet/minecraft/item/ItemStack;)Z"))
|
||||||
|
default boolean removeBindingCurseCondition(ItemStack stack) {
|
||||||
|
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_3)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return EnchantmentHelper.hasBindingCurse(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Redirect(method = "equipAndSwap", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;areEqual(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z"))
|
||||||
|
default boolean simplifyCondition(ItemStack left, ItemStack right) {
|
||||||
|
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_3)) {
|
||||||
|
return !right.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ItemStack.areEqual(left, right);
|
||||||
|
}
|
||||||
|
|
||||||
@Redirect(method = "equipAndSwap", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isCreative()Z"))
|
@Redirect(method = "equipAndSwap", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isCreative()Z"))
|
||||||
default boolean removeCreativeCondition(PlayerEntity instance) {
|
default boolean removeCreativeCondition(PlayerEntity instance) {
|
||||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
|
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
|
||||||
|
@ -96,11 +96,9 @@
|
|||||||
"fixes.minecraft.input.MixinKeyboard",
|
"fixes.minecraft.input.MixinKeyboard",
|
||||||
"fixes.minecraft.input.MixinKeyboardInput",
|
"fixes.minecraft.input.MixinKeyboardInput",
|
||||||
"fixes.minecraft.input.MixinMouse",
|
"fixes.minecraft.input.MixinMouse",
|
||||||
"fixes.minecraft.item.MixinArmorItem",
|
|
||||||
"fixes.minecraft.item.MixinAxeItem",
|
"fixes.minecraft.item.MixinAxeItem",
|
||||||
"fixes.minecraft.item.MixinBlockItem",
|
"fixes.minecraft.item.MixinBlockItem",
|
||||||
"fixes.minecraft.item.MixinBrushItem",
|
"fixes.minecraft.item.MixinBrushItem",
|
||||||
"fixes.minecraft.item.MixinElytraItem",
|
|
||||||
"fixes.minecraft.item.MixinEnderPearlItem",
|
"fixes.minecraft.item.MixinEnderPearlItem",
|
||||||
"fixes.minecraft.item.MixinEquipment",
|
"fixes.minecraft.item.MixinEquipment",
|
||||||
"fixes.minecraft.item.MixinFireworkRocketItem",
|
"fixes.minecraft.item.MixinFireworkRocketItem",
|
||||||
|
Loading…
Reference in New Issue
Block a user