Files
src
build.gradle
gradle.properties
settings.gradle
Code
56 633
src/main/java/com/kodari/arcweapons/ArcWeapons.java
package com.kodari.arcweapons;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
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.item.ToolMaterial;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.entity.projectile.FireballEntity;
public class ArcWeapons implements ModInitializer {
public static final String MOD_ID = "arcweapons";
private static final List<Item> ITEMS = new ArrayList<>();
private static final Map<UUID, Map<Item, Integer>> KILLS = new HashMap<>();
private static final Item WAND_OF_ILLUSION = register("wand_of_illusion", ToolMaterial.DIAMOND, 3.0F, -2.4F, 100);
private static final Item BLOODLUST = register("bloodlust", ToolMaterial.DIAMOND, 4.0F, -2.4F, 100);
private static final Item VULCANS_CROSSBOW = register("vulcans_crossbow", ToolMaterial.IRON, 2.5F, -2.6F, 80);
private static final Item FROST_SCYTHE = register("frost_scythe", ToolMaterial.DIAMOND, 4.0F, -2.6F, 100);
private static final Item BONE_BLADE = register("bone_blade", ToolMaterial.IRON, 3.0F, -2.4F, 80);
private static final Item ANCIENT_BLADE = register("ancient_blade", ToolMaterial.NETHERITE, 5.0F, -2.4F, 100);
private static final Item DRAGONREND = register("dragonrend", ToolMaterial.NETHERITE, 4.0F, -2.4F, 80);
private static final Item WITHER_SYMBIOTE = register("wither_symbiote", ToolMaterial.NETHERITE, 4.5F, -2.4F, 100);
private static final Item TIDEBREAKER = register("tidebreaker", ToolMaterial.DIAMOND, 4.0F, -2.6F, 100);
private static final Item OMEN = register("omen", ToolMaterial.IRON, 3.5F, -2.4F, 80);
private static final Item KNIGHTFALL = register("knightfall", ToolMaterial.NETHERITE, 5.0F, -2.8F, 120);
private static final Item ECLIPSE = register("eclipse", ToolMaterial.DIAMOND, 4.0F, -2.4F, 80);
private static final Item ECHO = register("echo", ToolMaterial.DIAMOND, 3.5F, -2.4F, 80);
@Override
public void onInitialize() {
ItemGroupEvents.modifyEntriesEvent(RegistryKey.of(RegistryKeys.ITEM_GROUP, Identifier.of("minecraft", "combat")))
.register(entries -> ITEMS.forEach(item -> entries.prepend(item)));
ServerLivingEntityEvents.AFTER_DEATH.register((entity, damageSource) -> {
if (!(damageSource.getAttacker() instanceof PlayerEntity killer)) {
return;
}
ItemStack held = killer.getStackInHand(Hand.MAIN_HAND);
Item weapon = held.isOf(BLOODLUST) ? BLOODLUST
: held.isOf(ANCIENT_BLADE) ? ANCIENT_BLADE
: held.isOf(KNIGHTFALL) ? KNIGHTFALL
: null;
if (weapon != null) {
KILLS.computeIfAbsent(killer.getUuid(), ignored -> new HashMap<>()).merge(weapon, 1, Integer::sum);
}
});
}
private static Item register(String name, ToolMaterial material, float damage, float attackSpeed, int cooldown) {
RegistryKey<Item> key = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MOD_ID, name));
Item.Settings settings = material.applySwordSettings(new Item.Settings().registryKey(key), damage, attackSpeed);
Item item = new ArcWeaponItem(name, settings, cooldown);
Item registered = Registry.register(Registries.ITEM, key, item);
ITEMS.add(registered);
return registered;
}
private static int kills(PlayerEntity player, Item weapon) {
return KILLS.getOrDefault(player.getUuid(), Map.of()).getOrDefault(weapon, 0);
}
private static void addEffect(PlayerEntity player, StatusEffectInstance effect) {
player.addStatusEffect(effect);
}
private static void nearbyPlayers(World world, PlayerEntity source, double radius, Consumer<PlayerEntity> action) {
if (world instanceof ServerWorld serverWorld) {
for (var target : serverWorld.getPlayers()) {
if (target != source && target.distanceTo(source) <= radius) {
action.accept(target);
}
}
}
}
private static void radialKnockback(World world, PlayerEntity source, double radius, double strength, double lift) {
nearbyPlayers(world, source, radius, target -> {
double dx = target.getX() - source.getX();
double dz = target.getZ() - source.getZ();
double length = Math.max(0.1, Math.sqrt(dx * dx + dz * dz));
target.addVelocity(dx / length * strength, lift, dz / length * strength);
});
}
private static void dash(PlayerEntity player, double strength) {
double yaw = Math.toRadians(player.getYaw());
player.addVelocity(-Math.sin(yaw) * strength, 0.35, Math.cos(yaw) * strength);
}
private static void fireball(World world, PlayerEntity player, double speed, int power) {
if (world instanceof ServerWorld serverWorld) {
Vec3d velocity = player.getRotationVec(1.0F).multiply(speed);
serverWorld.spawnEntity(new FireballEntity(serverWorld, player, velocity, power));
}
}
private static void activate(String name, World world, PlayerEntity player) {
switch (name) {
case "wand_of_illusion" -> {
addEffect(player, new StatusEffectInstance(StatusEffects.INVISIBILITY, 220, 0));
nearbyPlayers(world, player, 5.0, target -> target.addStatusEffect(new StatusEffectInstance(StatusEffects.BLINDNESS, 40, 0)));
}
case "bloodlust" -> {
int count = kills(player, BLOODLUST);
addEffect(player, new StatusEffectInstance(StatusEffects.STRENGTH, 160, 0));
if (count >= 3) {
addEffect(player, new StatusEffectInstance(StatusEffects.SPEED, 999999, 0));
}
if (count >= 6) {
addEffect(player, new StatusEffectInstance(StatusEffects.STRENGTH, 999999, 0));
radialKnockback(world, player, 5.0, 1.1, 0.7);
}
}
case "vulcans_crossbow" -> {
fireball(world, player, 1.8, 2);
addEffect(player, new StatusEffectInstance(StatusEffects.FIRE_RESISTANCE, 100, 0));
}
case "frost_scythe" -> {
addEffect(player, new StatusEffectInstance(StatusEffects.JUMP_BOOST, 100, 1));
nearbyPlayers(world, player, 8.0, target -> {
target.setFrozenTicks(Math.max(target.getFrozenTicks(), 160));
target.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 100, 2));
});
}
case "bone_blade" -> {
player.addVelocity(0.0, 1.15, 0.0);
nearbyPlayers(world, player, 4.0, target -> {
target.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 80, 4));
target.addVelocity(0.0, 0.55, 0.0);
});
}
case "ancient_blade" -> {
int count = kills(player, ANCIENT_BLADE);
nearbyPlayers(world, player, 10.0, target -> target.addStatusEffect(new StatusEffectInstance(StatusEffects.DARKNESS, 80, 0)));
if (count >= 3) {
addEffect(player, new StatusEffectInstance(StatusEffects.SPEED, 999999, 0));
}
if (count >= 6) {
addEffect(player, new StatusEffectInstance(StatusEffects.STRENGTH, 999999, 1));
fireball(world, player, 1.5, 2);
}
}
case "dragonrend" -> {
dash(player, 2.2);
nearbyPlayers(world, player, 7.0, target -> target.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 100, 1)));
}
case "wither_symbiote" -> {
addEffect(player, new StatusEffectInstance(StatusEffects.STRENGTH, 120, 0));
addEffect(player, new StatusEffectInstance(StatusEffects.SPEED, 120, 0));
nearbyPlayers(world, player, 4.0, target -> {
target.addStatusEffect(new StatusEffectInstance(StatusEffects.WEAKNESS, 160, 0));
target.addStatusEffect(new StatusEffectInstance(StatusEffects.BLINDNESS, 60, 0));
});
}
case "tidebreaker" -> {
addEffect(player, new StatusEffectInstance(StatusEffects.JUMP_BOOST, 100, 1));
radialKnockback(world, player, 9.0, 1.8, 0.9);
nearbyPlayers(world, player, 9.0, target -> target.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 80, 1)));
}
case "omen" -> {
fireball(world, player, 1.5, 1);
addEffect(player, new StatusEffectInstance(StatusEffects.JUMP_BOOST, 80, 1));
}
case "knightfall" -> {
int count = kills(player, KNIGHTFALL);
radialKnockback(world, player, 6.0, 1.5, 0.8);
nearbyPlayers(world, player, 6.0, target -> target.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 100, 1)));
if (count >= 3) {
addEffect(player, new StatusEffectInstance(StatusEffects.INVISIBILITY, 160, 0));
}
if (count >= 7) {
addEffect(player, new StatusEffectInstance(StatusEffects.STRENGTH, 999999, 0));
addEffect(player, new StatusEffectInstance(StatusEffects.SPEED, 999999, 0));
}
}
case "eclipse" -> {
if (world.getTime() % 24000L < 13000L) {