Files
src
build.gradle
gradle.properties
settings.gradle
Code
30 160
src/main/java/com/frostking/FrostKing.java
package com.frostking;
import java.util.Map;
import java.util.function.Function;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.creativetab.v1.CreativeModeTabEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ToolMaterial;
import net.minecraft.world.item.equipment.ArmorMaterial;
import net.minecraft.world.item.equipment.ArmorType;
import net.minecraft.world.item.equipment.EquipmentAssets;
public class FrostKing implements ModInitializer {
private static final ArmorMaterial ARMOR = new ArmorMaterial(
37, Map.of(ArmorType.HELMET, 20, ArmorType.CHESTPLATE, 20, ArmorType.LEGGINGS, 20, ArmorType.BOOTS, 20, ArmorType.BODY, 20),
15, SoundEvents.ARMOR_EQUIP_NETHERITE, 3.0F, 0.1F, ItemTags.REPAIRS_IRON_ARMOR,
ResourceKey.create(EquipmentAssets.ROOT_ID, id("frostking"))
);
private static final Item HELMET = armor("frostking_helmet", ArmorType.HELMET);
private static final Item CHESTPLATE = armor("frostking_chestplate", ArmorType.CHESTPLATE);
private static final Item LEGGINGS = armor("frostking_leggings", ArmorType.LEGGINGS);
private static final Item BOOTS = armor("frostking_boots", ArmorType.BOOTS);
private static final Item SWORD = register("frost_sorrow", p -> new Item(p.sword(ToolMaterial.IRON, 67.0F, -2.4F).durability(2031)) {
@Override
public void hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
target.addEffect(new MobEffectInstance(MobEffects.SLOWNESS, 100, 1), attacker);
target.addEffect(new MobEffectInstance(MobEffects.POISON, 100, 1), attacker);
}
});
private static Identifier id(String path) {
return Identifier.fromNamespaceAndPath("frostking", path);
}
private static Item register(String name, Function<Item.Properties, Item> factory) {
ResourceKey<Item> key = ResourceKey.create(Registries.ITEM, id(name));
return Registry.register(BuiltInRegistries.ITEM, key, factory.apply(new Item.Properties().setId(key)));
}
private static Item armor(String name, ArmorType type) {
return register(name, p -> new Item(p.humanoidArmor(ARMOR, type)));
}
@Override
public void onInitialize() {
CreativeModeTabEvents.modifyOutputEvent(ResourceKey.create(Registries.CREATIVE_MODE_TAB, Identifier.withDefaultNamespace("combat")))
.register(output -> {
output.accept(HELMET);
output.accept(CHESTPLATE);
output.accept(LEGGINGS);
output.accept(BOOTS);
output.accept(SWORD);
});
ServerTickEvents.END_SERVER_TICK.register(server -> {
for (var player : server.getPlayerList().getPlayers()) {
if (player.getItemBySlot(EquipmentSlot.HEAD).getItem() == HELMET
&& player.getItemBySlot(EquipmentSlot.CHEST).getItem() == CHESTPLATE
&& player.getItemBySlot(EquipmentSlot.LEGS).getItem() == LEGGINGS
&& player.getItemBySlot(EquipmentSlot.FEET).getItem() == BOOTS) {
player.addEffect(new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 40, 0, true, false));
player.addEffect(new MobEffectInstance(MobEffects.WATER_BREATHING, 40, 0, true, false));
player.addEffect(new MobEffectInstance(MobEffects.SPEED, 40, 1, true, false));
}
}
});
}
}