Files
src
build.gradle
gradle.properties
settings.gradle
Code
8 363
src/main/java/com/kodari/stormscythe/StormScytheMod.java
package com.kodari.stormscythe;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.entity.player.ItemCooldownManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.ToolMaterial;
import net.minecraft.util.Hand;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.Registries;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class StormScytheMod implements ModInitializer {
public static final String MOD_ID = "stormscythe";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
private static final Identifier SCYTHE_ID = Identifier.of(MOD_ID, "storm_scythe");
private static final RegistryKey<Item> SCYTHE_KEY = RegistryKey.of(RegistryKeys.ITEM, SCYTHE_ID);
public static final Item STORM_SCYTHE = Registry.register(
Registries.ITEM,
SCYTHE_KEY,
new Item(new Item.Settings()
.registryKey(SCYTHE_KEY)
.sword(ToolMaterial.NETHERITE, 3.0F, -2.4F))
);
private static final int ABILITY_ONE_COOLDOWN = 30;
private static final int ABILITY_TWO_COOLDOWN = 50;
private static final int ABILITY_THREE_COOLDOWN = 70;
private static final int ULTIMATE_COOLDOWN = 200;
@Override
public void onInitialize() {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> registerCommands(dispatcher));
LOGGER.info("Storm Scythe initialized");
}
private static void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(CommandManager.literal("scythe")
.then(CommandManager.literal("start")
.requires(CommandManager.requirePermissionLevel(CommandManager.GAMEMASTERS_CHECK))
.executes(context -> startSystem(context.getSource())))
.then(CommandManager.literal("get")
.requires(CommandManager.requirePermissionLevel(CommandManager.GAMEMASTERS_CHECK))
.executes(context -> giveScythe(context.getSource())))
.then(CommandManager.literal("obtain")
.requires(CommandManager.requirePermissionLevel(CommandManager.GAMEMASTERS_CHECK))
.executes(context -> giveScythe(context.getSource())))
.then(CommandManager.literal("ability1")
.executes(context -> executeAbility(context.getSource(), 1)))
.then(CommandManager.literal("ability2")
.executes(context -> executeAbility(context.getSource(), 2)))
.then(CommandManager.literal("ability3")
.executes(context -> executeAbility(context.getSource(), 3)))
.then(CommandManager.literal("ultimate")
.executes(context -> executeAbility(context.getSource(), 4))));
}
private static int startSystem(ServerCommandSource source) {
source.sendFeedback(() -> Text.literal("Storm Scythe system started."), true);
return 1;
}
private static int giveScythe(ServerCommandSource source) throws CommandSyntaxException {
ServerPlayerEntity player = source.getPlayerOrThrow();
ItemStack scythe = STORM_SCYTHE.getDefaultStack();
if (!player.getInventory().insertStack(scythe)) {
player.dropItem(scythe, false);
}
return 1;
}
private static int executeAbility(ServerCommandSource source, int ability) throws CommandSyntaxException {
ServerPlayerEntity player = source.getPlayerOrThrow();
if (!isHoldingStormScythe(player)) {
return 0;
}
ItemCooldownManager cooldowns = player.getItemCooldownManager();
if (cooldowns.isCoolingDown(STORM_SCYTHE.getDefaultStack())) {
return 0;
}
ServerWorld world = (ServerWorld) player.getEntityWorld();
switch (ability) {
case 1 -> abilityOne(world, player);
case 2 -> abilityTwo(world, player);
case 3 -> abilityThree(world, player);
case 4 -> ultimate(world, player);
default -> throw new IllegalArgumentException("Unknown Storm Scythe ability: " + ability);
}
cooldowns.set(STORM_SCYTHE.getDefaultStack(), cooldownFor(ability));
return 1;
}
private static int cooldownFor(int ability) {
return switch (ability) {
case 1 -> ABILITY_ONE_COOLDOWN;
case 2 -> ABILITY_TWO_COOLDOWN;
case 3 -> ABILITY_THREE_COOLDOWN;
case 4 -> ULTIMATE_COOLDOWN;
default -> ULTIMATE_COOLDOWN;
};
}
private static boolean isHoldingStormScythe(PlayerEntity player) {
return player.getMainHandStack().isOf(STORM_SCYTHE)
|| player.getOffHandStack().isOf(STORM_SCYTHE);
}
private static void abilityOne(ServerWorld world, ServerPlayerEntity caster) {
spawnWind(world, caster, 24, 0.65, 0.35, 0.65, 0.08);
world.spawnParticles(ParticleTypes.GUST_EMITTER_SMALL, caster.getX(), caster.getY() + 1.0, caster.getZ(),
2, 0.2, 0.35, 0.2, 0.0);
world.playSound(null, caster.getX(), caster.getY(), caster.getZ(),
SoundEvents.ENTITY_BREEZE_SHOOT, SoundCategory.PLAYERS, 1.2F, 1.05F);
world.playSound(null, caster.getX(), caster.getY(), caster.getZ(),
SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, SoundCategory.PLAYERS, 0.8F, 1.25F);
for (ServerPlayerEntity target : world.getPlayers(player -> player != caster
&& player.squaredDistanceTo(caster) <= 64.0)) {
damageAndPush(world, caster, target, 8.0F, 1.2);
breakShield(world, target);
}
}
private static void abilityTwo(ServerWorld world, ServerPlayerEntity caster) {
spawnWind(world, caster, 36, 1.25, 0.35, 1.25, 0.09);
world.spawnParticles(ParticleTypes.GUST_EMITTER_SMALL, caster.getX(), caster.getY() + 0.5, caster.getZ(),
4, 0.9, 0.15, 0.9, 0.0);
world.playSound(null, caster.getX(), caster.getY(), caster.getZ(),
SoundEvents.ENTITY_BREEZE_WHIRL, SoundCategory.PLAYERS, 1.5F, 0.9F);
for (ServerPlayerEntity target : world.getPlayers(player -> player != caster
&& player.squaredDistanceTo(caster) <= 36.0)) {
damageAndPush(world, caster, target, 5.0F, 1.8);
target.addVelocity(0.0, 0.45, 0.0);
world.spawnParticles(ParticleTypes.CLOUD, target.getX(), target.getY() + 1.0, target.getZ(),
8, 0.35, 0.45, 0.35, 0.04);
breakShield(world, target);
}
}
private static void abilityThree(ServerWorld world, ServerPlayerEntity caster) {
double yaw = Math.toRadians(caster.getYaw());
double directionX = -Math.sin(yaw);
double directionZ = Math.cos(yaw);
caster.addVelocity(directionX * 1.35, 0.35, directionZ * 1.35);
spawnDashTrail(world, caster, directionX, directionZ);
world.playSound(null, caster.getX(), caster.getY(), caster.getZ(),
SoundEvents.ENTITY_BREEZE_JUMP, SoundCategory.PLAYERS, 1.0F, 1.25F);
for (ServerPlayerEntity target : world.getPlayers(player -> player != caster
&& player.squaredDistanceTo(caster) <= 12.25)) {
damageAndPush(world, caster, target, 6.0F, 1.0);
breakShield(world, target);
}
}
private static void ultimate(ServerWorld world, ServerPlayerEntity caster) {
spawnWind(world, caster, 72, 2.6, 1.0, 2.6, 0.16);
world.spawnParticles(ParticleTypes.GUST_EMITTER_LARGE, caster.getX(), caster.getY() + 1.0, caster.getZ(),
2, 1.2, 0.4, 1.2, 0.0);
world.spawnParticles(ParticleTypes.ELECTRIC_SPARK, caster.getX(), caster.getY() + 1.0, caster.getZ(),
28, 2.4, 1.0, 2.4, 0.08);
world.spawnParticles(ParticleTypes.EXPLOSION, caster.getX(), caster.getY() + 1.0, caster.getZ(),
1, 0.0, 0.0, 0.0, 0.0);
world.playSound(null, caster.getX(), caster.getY(), caster.getZ(),
SoundEvents.ENTITY_BREEZE_WIND_BURST, SoundCategory.PLAYERS, 2.0F, 0.7F);
world.playSound(null, caster.getX(), caster.getY(), caster.getZ(),
SoundEvents.ENTITY_LIGHTNING_BOLT_THUNDER, SoundCategory.PLAYERS, 1.4F, 1.0F);
for (ServerPlayerEntity target : world.getPlayers(player -> player != caster
&& player.squaredDistanceTo(caster) <= 256.0)) {
damageAndPush(world, caster, target, 14.0F, 2.4);
target.addVelocity(0.0, 0.75, 0.0);
world.spawnParticles(ParticleTypes.ELECTRIC_SPARK, target.getX(), target.getY() + 1.0, target.getZ(),
12, 0.45, 0.75, 0.45, 0.06);
breakShield(world, target);
}