Swing hand on lead item interaction in <= 1.21.1

This commit is contained in:
FlorianMichael 2024-10-29 20:51:04 +01:00
parent 5d7dd8b247
commit 0c151ddf05
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
2 changed files with 50 additions and 1 deletions

View File

@ -0,0 +1,45 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
* Copyright (C) 2023-2024 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.protocoltranslator.ProtocolTranslator;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.item.LeadItem;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.util.ActionResult;
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(LeadItem.class)
public abstract class MixinLeadItem {
@Inject(method = "useOnBlock", at = @At("RETURN"), cancellable = true)
private void swingHand(ItemUsageContext context, CallbackInfoReturnable<ActionResult> cir) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_21)) {
if (context.getWorld().getBlockState(context.getBlockPos()).isIn(BlockTags.FENCES)) {
cir.setReturnValue(ActionResult.SUCCESS);
}
}
}
}

View File

@ -219,5 +219,9 @@
},
"overwrites": {
"requireAnnotations": true
}
},
"mixins": [
"fixes.minecraft.item.MixinEmptyMapItem",
"fixes.minecraft.item.MixinLeadItem"
]
}