72 lines
2.8 KiB
Java
72 lines
2.8 KiB
Java
/*
|
|
* MIT License
|
|
*
|
|
* Copyright (c) 2019 Joseph Burton (Earthcomputer)
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*/
|
|
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item;
|
|
|
|
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
|
import de.florianmichael.vialoadingbase.ViaLoadingBase;
|
|
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 org.spongepowered.asm.mixin.Mixin;
|
|
|
|
@Mixin(SwordItem.class)
|
|
public class MixinSwordItem extends ToolItem {
|
|
|
|
public MixinSwordItem(ToolMaterial material, Settings settings) {
|
|
super(material, settings);
|
|
}
|
|
|
|
@Override
|
|
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
|
|
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
|
ItemStack itemStack = user.getStackInHand(hand);
|
|
user.setCurrentHand(hand);
|
|
return TypedActionResult.consume(itemStack);
|
|
}
|
|
return super.use(world, user, hand);
|
|
}
|
|
|
|
@Override
|
|
public UseAction getUseAction(ItemStack stack) {
|
|
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
|
return UseAction.BLOCK;
|
|
}
|
|
return super.getUseAction(stack);
|
|
}
|
|
|
|
@Override
|
|
public int getMaxUseTime(ItemStack stack) {
|
|
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
|
return 72000;
|
|
}
|
|
return super.getMaxUseTime(stack);
|
|
}
|
|
}
|