com.magistuarmory.event.CommonEvents 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-common Show documentation
Show all versions of 1.20.2-epic-knights-common Show documentation
mod that adds medieval stuff to the game
package com.magistuarmory.event;
import com.magistuarmory.EpicKnights;
import com.magistuarmory.misc.ModMerchOffers;
import com.magistuarmory.network.PacketBetterCombatOrEpicFightInstalled;
import com.magistuarmory.misc.ModLoot;
import com.magistuarmory.item.MedievalShieldItem;
import com.magistuarmory.item.MedievalWeaponItem;
import com.magistuarmory.util.MobEquipment;
import com.magistuarmory.util.MobEquipmentHelper;
import com.magistuarmory.util.ModDamageSources;
import dev.architectury.event.EventResult;
import dev.architectury.event.events.common.EntityEvent;
import dev.architectury.event.events.common.LifecycleEvent;
import dev.architectury.event.events.common.LootEvent;
import dev.architectury.event.events.common.PlayerEvent;
import net.minecraft.class_1282;
import net.minecraft.class_1297;
import net.minecraft.class_1309;
import net.minecraft.class_1657;
import net.minecraft.class_1799;
import net.minecraft.class_1937;
import net.minecraft.class_2960;
import net.minecraft.class_3222;
import net.minecraft.class_60;
import net.minecraft.server.MinecraftServer;
public class CommonEvents
{
public static void init()
{
LootEvent.MODIFY_LOOT_TABLE.register(CommonEvents::onModifyLootTable);
LifecycleEvent.SETUP.register(CommonEvents::onSetup);
LifecycleEvent.SERVER_STARTING.register(CommonEvents::onServerStarting);
LifecycleEvent.SERVER_LEVEL_LOAD.register(CommonEvents::onServerLevelLoad);
EntityEvent.ADD.register(CommonEvents::onEntityJoinLevel);
EntityEvent.LIVING_HURT.register(CommonEvents::onLivingHurt);
PlayerEvent.PLAYER_JOIN.register(CommonEvents::onPlayerJoin);
}
public static void onModifyLootTable(class_60 lootmanager, class_2960 id, LootEvent.LootTableModificationContext context, boolean builtin)
{
ModLoot.modifyLootTable(id, context);
}
public static void onSetup()
{
ModMerchOffers.setup();
}
public static void onServerStarting(MinecraftServer server)
{
MobEquipment.setup(server);
EpicKnights.checkBetterCombatOrEpicFightInstalled();
}
public static void onServerLevelLoad(class_1937 level)
{
ModDamageSources.setup(level.method_30349());
}
public static EventResult onEntityJoinLevel(class_1297 entity, class_1937 level)
{
if (entity instanceof class_1309 livingentity)
MobEquipmentHelper.equip(livingentity);
return EventResult.pass();
}
public static EventResult onLivingHurt(class_1309 victim, class_1282 source, float damage)
{
class_1799 stack = victim.method_6030();
if (victim.method_5655() || (victim instanceof class_1657 player && player.method_7337()))
return EventResult.pass();
if (victim.method_6039() && stack.method_7909() instanceof MedievalShieldItem shield)
{
shield.onBlocked(stack, damage, victim, source);
return EventResult.pass();
}
if (victim.method_6039() && stack.method_7909() instanceof MedievalWeaponItem weapon && weapon.canBlock())
{
weapon.onBlocked(stack, damage, victim, source);
return EventResult.pass();
}
if (source.method_5529() instanceof class_1309 attacker && attacker.method_6047().method_7909() instanceof MedievalWeaponItem weapon2)
{
weapon2.onHurtEntity(source, victim, damage);
}
return EventResult.pass();
}
public static void onPlayerJoin(class_3222 player)
{
PacketBetterCombatOrEpicFightInstalled.sendToPlayer(player);
}
}