Files
src
build.gradle
gradle.properties
README.md
settings.gradle
Code
50 799
src/main/java/com/kodari/novacircuit/NovaCircuitMod.java
package com.kodari.novacircuit;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.event.player.UseItemCallback;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LightningEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
public final class NovaCircuitMod implements ModInitializer {
public static final String MOD_ID = "novacircuit";
private static final Map<UUID, Long> ULTIMATE_COOLDOWNS = new HashMap<>();
private static int tickCounter;
@Override
public void onInitialize() {
NovaItems.registerGroup();
UseItemCallback.EVENT.register(NovaCircuitMod::onUseItem);
ServerTickEvents.END_SERVER_TICK.register(NovaCircuitMod::onServerTick);
}
private static TypedActionResult<ItemStack> onUseItem(PlayerEntity player, World world, Hand hand) {
ItemStack stack = player.getStackInHand(hand);
Item item = stack.getItem();
if (!isHandledItem(item)) {
return TypedActionResult.pass(stack);
}
if (world.isClient) {
return TypedActionResult.success(stack);
}
if (!(player instanceof ServerPlayerEntity serverPlayer)) {
return TypedActionResult.pass(stack);
}
NovaProgression progression = NovaProgression.get(serverPlayer.getServerWorld().getServer());
UUID playerId = serverPlayer.getUuid();
if (item == NovaItems.AWAKENING_SERUM) {
if (progression.getStage(playerId) > 0) {
serverPlayer.sendMessage(Text.literal("Your NOVA origin is already awakened."), true);
} else {
progression.setAwakeningReady(playerId, true);
stack.decrement(1);
serverPlayer.sendMessage(Text.literal("Awakening primed. Raise the NOVA ring beneath open sky during a thunderstorm."), true);
}
return TypedActionResult.success(stack);
}
if (item == NovaItems.NANOTECH_CORE_RING) {
useRing(serverPlayer, progression);
return TypedActionResult.success(stack);
}
useUpgradeCore(serverPlayer, progression, stack, item);
return TypedActionResult.success(stack);
}
private static boolean isHandledItem(Item item) {
return item == NovaItems.AWAKENING_SERUM
|| item == NovaItems.NANOTECH_CORE_RING
|| item == NovaItems.STABILIZED_CORE
|| item == NovaItems.ADVANCED_CORE
|| item == NovaItems.MASTERY_CORE;
}
private static void useRing(ServerPlayerEntity player, NovaProgression progression) {
UUID playerId = player.getUuid();
int stage = progression.getStage(playerId);
ServerWorld world = player.getServerWorld();
if (stage == 0 && progression.isAwakeningReady(playerId)) {
if (!world.isThundering()) {
player.sendMessage(Text.literal("The awakening requires a thunderstorm."), true);
return;
}
if (!world.isSkyVisible(player.getBlockPos())) {
player.sendMessage(Text.literal("Move into an open area with a clear view of the sky."), true);
return;
}
LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(world);
if (lightning == null) {
player.sendMessage(Text.literal("The lightning ritual could not be started."), true);
return;
}
lightning.refreshPositionAfterTeleport(player.getPos());
lightning.setChanneler(player);
if (!world.spawnEntity(lightning)) {
player.sendMessage(Text.literal("The lightning ritual could not be started."), true);
return;
}
progression.setAwakeningReady(playerId, false);
progression.setStage(playerId, 1);
ItemStack blueprint = new ItemStack(NovaItems.RESEARCH_BLUEPRINT, 4);
if (!player.getInventory().insertStack(blueprint)) {
player.dropItem(blueprint, false);
}
player.sendMessage(Text.literal("NOVA CIRCUIT awakened. Four research blueprints were released."), true);
return;
}
if (stage == 0) {
player.sendMessage(Text.literal("Consume the NOVA Awakening Serum first."), true);
return;
}
if (progression.isDeployed(playerId)) {
if (player.isSneaking() && stage >= 5) {
activateUltimate(player);
return;
}
progression.setDeployed(playerId, false);
player.removeStatusEffect(StatusEffects.SPEED);
player.removeStatusEffect(StatusEffects.RESISTANCE);
player.removeStatusEffect(StatusEffects.STRENGTH);
player.sendMessage(Text.literal("NOVA suit retracted."), true);
return;
}
if (stage == 1 && hasPrototypeSuit(player)) {
progression.setStage(playerId, 2);
stage = 2;
player.sendMessage(Text.literal("Prototype Nanotech unlocked."), true);
}
progression.setDeployed(playerId, true);
if (stage >= 5 && player.isSneaking()) {
activateUltimate(player);
} else {
player.sendMessage(Text.literal("NOVA suit deployed. Sneak-use the ring at NOVA Mastery to trigger the ultimate."), true);
}
}
private static void useUpgradeCore(ServerPlayerEntity player, NovaProgression progression, ItemStack stack, Item item) {
UUID playerId = player.getUuid();
int stage = progression.getStage(playerId);
if (item == NovaItems.STABILIZED_CORE && stage == 2) {
progression.setStage(playerId, 3);
stack.decrement(1);
player.sendMessage(Text.literal("Stabilized Nanotech unlocked: enhanced movement is online."), true);
} else if (item == NovaItems.ADVANCED_CORE && stage == 3 && hasAdvancedSuit(player)) {
progression.setStage(playerId, 4);
stack.decrement(1);
player.sendMessage(Text.literal("Advanced Nanotech unlocked."), true);
} else if (item == NovaItems.MASTERY_CORE && stage == 4) {
progression.setStage(playerId, 5);
stack.decrement(1);
player.sendMessage(Text.literal("NOVA Mastery unlocked. Sneak-use the deployed ring for the ultimate burst."), true);
} else if (item == NovaItems.ADVANCED_CORE && stage == 3) {
player.sendMessage(Text.literal("Wear the complete Advanced Nanotech suit before using this core."), true);
} else {
player.sendMessage(Text.literal("This core does not match your current NOVA progression."), true);
}
}
private static boolean hasPrototypeSuit(PlayerEntity player) {
return player.getEquippedStack(EquipmentSlot.HEAD).getItem() == NovaItems.PROTOTYPE_HELMET
&& player.getEquippedStack(EquipmentSlot.CHEST).getItem() == NovaItems.PROTOTYPE_CHESTPLATE
&& player.getEquippedStack(EquipmentSlot.LEGS).getItem() == NovaItems.PROTOTYPE_LEGGINGS
&& player.getEquippedStack(EquipmentSlot.FEET).getItem() == NovaItems.PROTOTYPE_BOOTS;
}
private static boolean hasAdvancedSuit(PlayerEntity player) {
return player.getEquippedStack(EquipmentSlot.HEAD).getItem() == NovaItems.ADVANCED_HELMET
&& player.getEquippedStack(EquipmentSlot.CHEST).getItem() == NovaItems.ADVANCED_CHESTPLATE
&& player.getEquippedStack(EquipmentSlot.LEGS).getItem() == NovaItems.ADVANCED_LEGGINGS
&& player.getEquippedStack(EquipmentSlot.FEET).getItem() == NovaItems.ADVANCED_BOOTS;
}
private static void activateUltimate(ServerPlayerEntity player) {
long now = System.currentTimeMillis();
long availableAt = ULTIMATE_COOLDOWNS.getOrDefault(player.getUuid(), 0L);
if (now < availableAt) {
long seconds = Math.max(1L, (availableAt - now + 999L) / 1000L);
player.sendMessage(Text.literal("NOVA ultimate recharging: " + seconds + "s."), true);
return;
}
ULTIMATE_COOLDOWNS.put(player.getUuid(), now + 60_000L);
player.addStatusEffect(new StatusEffectInstance(StatusEffects.STRENGTH, 200, 2, false, true, true));
player.addStatusEffect(new StatusEffectInstance(StatusEffects.RESISTANCE, 200, 1, false, true, true));
player.sendMessage(Text.literal("NOVA CIRCUIT: ultimate burst."), true);
}
private static void onServerTick(MinecraftServer server) {
if (++tickCounter % 10 != 0) {