com.magistuarmory.event.ClientEvents Maven / Gradle / Ivy
package com.magistuarmory.event;
import com.magistuarmory.client.ClientHelper;
import com.magistuarmory.client.render.ModRender;
import com.magistuarmory.item.LanceItem;
import com.magistuarmory.item.MedievalWeaponItem;
import com.magistuarmory.util.CombatHelper;
import dev.architectury.event.EventResult;
import dev.architectury.event.events.client.ClientRawInputEvent;
import dev.architectury.event.events.client.ClientTextureStitchEvent;
import dev.architectury.event.events.common.LifecycleEvent;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import java.util.function.Consumer;
@Environment(EnvType.CLIENT)
public class ClientEvents
{
public static void init()
{
ClientRawInputEvent.MOUSE_CLICKED_PRE.register(ClientEvents::onMouseInput);
LifecycleEvent.SETUP.register(ModRender::registerRenderers);
ClientTextureStitchEvent.PRE.register(ClientEvents::onStitchPre);
}
public static void onStitchPre(TextureAtlas atlas, Consumer adder)
{
ModRender.stitch(atlas, adder);
}
public static EventResult onMouseInput(Minecraft mc, int button, int action, int mods)
{
if (mc.f_91073_ == null || mc.f_91080_ != null || mc.m_91104_())
return EventResult.pass();
KeyMapping keyattack = mc.f_91066_.f_92096_;
if (button == keyattack.m_90861_().m_84873_())
{
Player player = mc.f_91074_;
if (player == null || player.m_21254_())
return EventResult.pass();
ItemStack stack = player.m_21205_();
if (stack.m_41720_() instanceof MedievalWeaponItem weapon)
{
HitResult hit = ClientHelper.getMouseOver(mc, CombatHelper.getAttackReach(player, weapon));
if (hit instanceof EntityHitResult entityhit && !weapon.onAttackClickEntity(stack, player, entityhit.m_82443_()))
{
return weapon instanceof LanceItem ? EventResult.interruptFalse() : EventResult.interruptDefault();
}
}
}
return EventResult.pass();
}
}