Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.minestom.codegen;

import net.minestom.codegen.attribute.AttributeGenerator;
import net.minestom.codegen.color.DyeColorGenerator;
import net.minestom.codegen.feature.FeatureFlagGenerator;
import net.minestom.codegen.fluid.FluidGenerator;
Expand Down Expand Up @@ -41,15 +40,11 @@ public static void main(String[] args) {
generator.generate(resource("trim_materials.json"), "net.minestom.server.item.armor", "TrimMaterial", "TrimMaterialImpl", "TrimMaterials");
generator.generate(resource("trim_patterns.json"), "net.minestom.server.item.armor", "TrimPattern", "TrimPatternImpl", "TrimPatterns");
generator.generate(resource("banner_patterns.json"), "net.minestom.server.item.banner", "BannerPattern", "BannerPatternImpl", "BannerPatterns"); // Microtus - Banner and Shield Meta
generator.generate(resource("attributes.json"), "net.minestom.server.attribute", "Attribute", "AttributeImpl", "Attributes");


// Generate fluids
new FluidGenerator(resource("fluids.json"), outputFolder).generate();

new AttributeGenerator(
resource("attributes.json"),
outputFolder
).generate();
// TODO: Generate villager professions
// new VillagerProfessionGenerator(
// new File(inputFolder, targetVersion + "_villager_professions.json"),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.minestom.demo.entity;

import net.minestom.server.attribute.Attribute;
import net.minestom.server.attribute.Attributes;
import net.minestom.server.attribute.VanillaAttribute;
import net.minestom.server.entity.EntityCreature;
import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.ai.goal.RandomStrollGoal;
Expand Down Expand Up @@ -36,7 +35,7 @@ public ChickenCreature() {
// .build()
// );

getAttribute(Attributes.GENERIC_MOVEMENT_SPEED.attribute()).setBaseValue(0.1f);
getAttribute(VanillaAttribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.1f);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,61 +1,35 @@
package net.minestom.server.attribute;

import net.minestom.server.MinecraftServer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* AUTOGENERATED by AttributeGenerator
* Code autogenerated, do not edit!
*/
public enum Attributes {
GENERIC_ARMOR(new Attribute("minecraft:generic.armor", 0.0f, 30.0f)),

GENERIC_ARMOR_TOUGHNESS(new Attribute("minecraft:generic.armor_toughness", 0.0f, 20.0f)),

GENERIC_ATTACK_DAMAGE(new Attribute("minecraft:generic.attack_damage", 2.0f, 2048.0f)),

GENERIC_ATTACK_KNOCKBACK(new Attribute("minecraft:generic.attack_knockback", 0.0f, 5.0f)),

GENERIC_ATTACK_SPEED(new Attribute("minecraft:generic.attack_speed", 4.0f, 1024.0f)),

GENERIC_FLYING_SPEED(new Attribute("minecraft:generic.flying_speed", 0.4f, 1024.0f)),

GENERIC_FOLLOW_RANGE(new Attribute("minecraft:generic.follow_range", 32.0f, 2048.0f)),
@SuppressWarnings("unused")
interface Attributes {
Attribute GENERIC_ARMOR = AttributeImpl.get("minecraft:generic.armor");

HORSE_JUMP_STRENGTH(new Attribute("minecraft:horse.jump_strength", 0.7f, 2.0f)),
Attribute GENERIC_ARMOR_TOUGHNESS = AttributeImpl.get("minecraft:generic.armor_toughness");

GENERIC_KNOCKBACK_RESISTANCE(new Attribute("minecraft:generic.knockback_resistance", 0.0f, 1.0f)),
Attribute GENERIC_ATTACK_DAMAGE = AttributeImpl.get("minecraft:generic.attack_damage");

GENERIC_LUCK(new Attribute("minecraft:generic.luck", 0.0f, 1024.0f)),
Attribute GENERIC_ATTACK_KNOCKBACK = AttributeImpl.get("minecraft:generic.attack_knockback");

GENERIC_MAX_ABSORPTION(new Attribute("minecraft:generic.max_absorption", 0.0f, 2048.0f)),
Attribute GENERIC_ATTACK_SPEED = AttributeImpl.get("minecraft:generic.attack_speed");

GENERIC_MAX_HEALTH(new Attribute("minecraft:generic.max_health", 20.0f, 1024.0f)),
Attribute GENERIC_FLYING_SPEED = AttributeImpl.get("minecraft:generic.flying_speed");

GENERIC_MOVEMENT_SPEED(new Attribute("minecraft:generic.movement_speed", 0.7f, 1024.0f)),
Attribute GENERIC_FOLLOW_RANGE = AttributeImpl.get("minecraft:generic.follow_range");

ZOMBIE_SPAWN_REINFORCEMENTS(new Attribute("minecraft:zombie.spawn_reinforcements", 0.0f, 1.0f));
Attribute HORSE_JUMP_STRENGTH = AttributeImpl.get("minecraft:horse.jump_strength");

private static final Attributes[] VALUES = values();
Attribute GENERIC_KNOCKBACK_RESISTANCE = AttributeImpl.get("minecraft:generic.knockback_resistance");

private final Attribute attribute;
Attribute GENERIC_LUCK = AttributeImpl.get("minecraft:generic.luck");

Attributes(@NotNull Attribute attribute) {
this.attribute = attribute;
}
Attribute GENERIC_MAX_ABSORPTION = AttributeImpl.get("minecraft:generic.max_absorption");

public @NotNull Attribute attribute() {
return this.attribute;
}
Attribute GENERIC_MAX_HEALTH = AttributeImpl.get("minecraft:generic.max_health");

@Nullable
public static Attribute getValue(int id) {
return VALUES[id].attribute;
}
Attribute GENERIC_MOVEMENT_SPEED = AttributeImpl.get("minecraft:generic.movement_speed");

public static void registerAttributes() {
for (var v : VALUES) {
MinecraftServer.getAttributeManager().register(v.attribute());
}
}
Attribute ZOMBIE_SPAWN_REINFORCEMENTS = AttributeImpl.get("minecraft:zombie.spawn_reinforcements");
}
5 changes: 2 additions & 3 deletions src/main/java/net/minestom/server/ServerProcessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.minestom.server.advancements.AdvancementManager;
import net.minestom.server.adventure.bossbar.BossBarManager;
import net.minestom.server.attribute.AttributeManager;
import net.minestom.server.attribute.Attributes;
import net.minestom.server.command.CommandManager;
import net.minestom.server.entity.Entity;
import net.minestom.server.event.EventDispatcher;
Expand Down Expand Up @@ -258,9 +257,9 @@ public void start(@NotNull SocketAddress socketAddress) {
LOGGER.info(MinecraftServer.getBrandName() + " server started successfully.");

if (ServerFlag.ATTRIBUTES_ENABLED) {
Attributes.registerAttributes();
attribute.loadVanillaAttributes();
}
LOGGER.info("Register Attributes({})", attribute.values().size());
LOGGER.info("Register Attributes({})", attribute.unmodifiableCollection().size());

if (ServerFlag.BIOMES_ENABLED) {
biome.loadVanillaBiomes();
Expand Down
32 changes: 22 additions & 10 deletions src/main/java/net/minestom/server/attribute/Attribute.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
package net.minestom.server.attribute;

/**
* Represents a {@link net.minestom.server.entity.LivingEntity living entity} attribute.
*/
public record Attribute(String key, float defaultValue, float maxValue) {

public Attribute {
if (defaultValue > maxValue) {
throw new IllegalArgumentException("Default value cannot be greater than the maximum allowed");
}
}
import net.minestom.server.registry.ProtocolObject;
import net.minestom.server.registry.Registry;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public sealed interface Attribute extends ProtocolObject permits AttributeImpl {
@Contract(pure = true)
@Nullable
Registry.AttributeEntry registry();

@Override
@NotNull
NamespaceID namespace();

float defaultValue();
float maxValue();
float mineValue();
boolean clientSync();
@NotNull
String translationKey();
}
64 changes: 64 additions & 0 deletions src/main/java/net/minestom/server/attribute/AttributeImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package net.minestom.server.attribute;

import net.minestom.server.registry.ProtocolObject;
import net.minestom.server.registry.Registry;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;

/**
* Represents a {@link net.minestom.server.entity.LivingEntity living entity} attribute.
*/
public record AttributeImpl(Registry.AttributeEntry registry, int id) implements Attribute, ProtocolObject {

private static final Registry.DynamicContainer<Attribute> CONTAINER = Registry.createDynamicContainer(Registry.Resource.ATTRIBUTES, AttributeImpl::createImpl);

private static Attribute createImpl(String namespace, Registry.Properties properties) {
Registry.AttributeEntry attributeEntry = Registry.attribute(namespace, properties);
return new AttributeImpl(attributeEntry, attributeEntry.id());
}

static Collection<Attribute> values() {
return CONTAINER.values();
}

static Attribute get(@NotNull String namespace) {
return CONTAINER.get(namespace);
}

static Attribute getSafe(@NotNull String namespace) {
return CONTAINER.getSafe(namespace);
}

@Override
public @NotNull NamespaceID namespace() {
return this.registry.namespace();
}

@Override
public float defaultValue() {
return this.registry.defaultValue();
}

@Override
public float maxValue() {
return this.registry.maxValue();
}

@Override
public float mineValue() {
return this.registry.maxValue();
}

@Override
public boolean clientSync() {
return this.registry.clientSync();
}

@Override
public @NotNull String translationKey() {
return this.registry.translationKey();
}
}
Loading