com.magistuarmory.event.ClientEvents Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of 1.20.2-epic-knights-fabric Show documentation
Show all versions of 1.20.2-epic-knights-fabric Show documentation
mod that adds medieval stuff to the game
The newest version!
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.common.LifecycleEvent;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.class_1657;
import net.minecraft.class_1799;
import net.minecraft.class_239;
import net.minecraft.class_304;
import net.minecraft.class_310;
import net.minecraft.class_3966;
@Environment(EnvType.CLIENT)
public class ClientEvents
{
public static void init()
{
ClientRawInputEvent.MOUSE_CLICKED_PRE.register(ClientEvents::onMouseInput);
LifecycleEvent.SETUP.register(ModRender::registerRenderers);
}
public static EventResult onMouseInput(class_310 mc, int button, int action, int mods)
{
if (mc.field_1687 == null || mc.field_1755 != null || mc.method_1493())
return EventResult.pass();
class_304 keyattack = mc.field_1690.field_1886;
if (button == keyattack.method_1429().method_1444())
{
class_1657 player = mc.field_1724;
if (player == null || player.method_6039())
return EventResult.pass();
class_1799 stack = player.method_6047();
if (stack.method_7909() instanceof MedievalWeaponItem weapon)
{
class_239 hit = ClientHelper.getMouseOver(mc, CombatHelper.getAttackReach(player, weapon));
if (hit instanceof class_3966 entityhit && !weapon.onAttackClickEntity(stack, player, entityhit.method_17782()))
{
return weapon instanceof LanceItem ? EventResult.interruptFalse() : EventResult.interruptDefault();
}
}
}
return EventResult.pass();
}
}