Fix sword blocking in creative mode in <= 1.8 (#580)

This commit is contained in:
lowercasebtw 2024-10-11 15:09:27 -04:00 committed by GitHub
parent f6acb9b9a5
commit 563e47cc9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,11 +21,15 @@ 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.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.item.ToolItem;
import net.minecraft.item.ToolMaterial;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.UseAction;
import net.minecraft.world.World;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import org.spongepowered.asm.mixin.Mixin;
@ -36,6 +40,17 @@ public abstract class MixinSwordItem extends ToolItem {
super(material, settings);
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
if (ProtocolTranslator.getTargetVersion().betweenInclusive(LegacyProtocolVersion.b1_8tob1_8_1, ProtocolVersion.v1_8)) {
ItemStack itemStack = user.getStackInHand(hand);
user.setCurrentHand(hand);
return TypedActionResult.success(itemStack);
} else {
return super.use(world, user, hand);
}
}
@Override
public UseAction getUseAction(ItemStack stack) {
if (ProtocolTranslator.getTargetVersion().betweenInclusive(LegacyProtocolVersion.b1_8tob1_8_1, ProtocolVersion.v1_8)) {