Search in sources :

Example 1 with IOffhandAttack

use of chronosacaria.mcdw.api.interfaces.IOffhandAttack in project MCDungeonsWeapons by chronosacaria.

the class CombatEventHandler method checkForOffHandAttack.

public static void checkForOffHandAttack() {
    MinecraftClient mc = MinecraftClient.getInstance();
    PlayerEntity player = mc.player;
    HitResult hitResult = mc.crosshairTarget;
    if (MinecraftClient.getInstance().world != null && MinecraftClient.getInstance().currentScreen == null && !MinecraftClient.getInstance().isPaused() && player != null && !player.isBlocking()) {
        ItemStack offhand = player.getOffHandStack();
        if (offhand.getItem() instanceof IOffhandAttack) {
            if (hitResult instanceof EntityHitResult) {
                if (mc.crosshairTarget != null && mc.interactionManager != null) {
                    mc.interactionManager.attackEntity(player, ((EntityHitResult) mc.crosshairTarget).getEntity());
                }
            }
        }
    }
}
Also used : HitResult(net.minecraft.util.hit.HitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) IOffhandAttack(chronosacaria.mcdw.api.interfaces.IOffhandAttack) MinecraftClient(net.minecraft.client.MinecraftClient) ItemStack(net.minecraft.item.ItemStack) EntityHitResult(net.minecraft.util.hit.EntityHitResult) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

IOffhandAttack (chronosacaria.mcdw.api.interfaces.IOffhandAttack)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ItemStack (net.minecraft.item.ItemStack)1 EntityHitResult (net.minecraft.util.hit.EntityHitResult)1 HitResult (net.minecraft.util.hit.HitResult)1