Skip to content

Commit

Permalink
Update sword blocking fix mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Oct 30, 2024
1 parent 19f2264 commit 4e9276f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.item.consume.UseAction;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;
Expand All @@ -49,13 +47,4 @@ public ActionResult use(World world, PlayerEntity user, Hand hand) {
}
}

@Override
public UseAction getUseAction(ItemStack stack) {
if (ProtocolTranslator.getTargetVersion().betweenInclusive(LegacyProtocolVersion.b1_8tob1_8_1, ProtocolVersion.v1_8)) {
return UseAction.BLOCK;
} else {
return super.getUseAction(stack);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <[email protected]> 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.viaversion;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.BlockItemPacketRewriter1_21_2;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(value = BlockItemPacketRewriter1_21_2.class, remap = false)
public abstract class MixinBlockItemPacketRewriter1_21_2 {

@Redirect(method = "appendItemDataFixComponents", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;olderThanOrEqualTo(Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;)Z"))
private boolean changeSwordFixVersionRange(ProtocolVersion instance, ProtocolVersion other) {
if (other == ProtocolVersion.v1_8) {
return instance.betweenInclusive(LegacyProtocolVersion.b1_8tob1_8_1, ProtocolVersion.v1_8);
} else {
return instance.olderThanOrEqualTo(other);
}
}

}
5 changes: 3 additions & 2 deletions src/main/resources/viafabricplus.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"fixes.minecraft.item.MixinItemRenderer",
"fixes.minecraft.item.MixinItemStack",
"fixes.minecraft.item.MixinKnowledgeBookItem",
"fixes.minecraft.item.MixinLeadItem",
"fixes.minecraft.item.MixinShovelItem",
"fixes.minecraft.item.MixinSwordItem",
"fixes.minecraft.network.MixinChatMessageC2SPacket",
Expand Down Expand Up @@ -184,6 +185,7 @@
"fixes.vialegacy.MixinProtocolc0_30cpeToc0_28_30",
"fixes.vialegacy.MixinProtocolr1_7_6_10Tor1_8",
"fixes.viaversion.MixinBlockItemPacketRewriter1_20_5",
"fixes.viaversion.MixinBlockItemPacketRewriter1_21_2",
"fixes.viaversion.MixinCommandBlockProvider",
"fixes.viaversion.MixinCommonBoss",
"fixes.viaversion.MixinEntityPacketRewriter1_12",
Expand Down Expand Up @@ -212,8 +214,7 @@
"fixes.viaversion.MixinWorldPacketRewriter1_19",
"viabedrock.MixinJoinPackets",
"vialegacy.MixinExtensionProtocolMetadataStorage",
"vialegacy.MixinViaLegacyConfig",
"fixes.minecraft.item.MixinLeadItem"
"vialegacy.MixinViaLegacyConfig"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 4e9276f

Please sign in to comment.