Skip to content

Commit

Permalink
chore: added equipment and handle attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
RealBauHD committed May 17, 2024
1 parent 52ef2d9 commit 08d57f1
Show file tree
Hide file tree
Showing 30 changed files with 668 additions and 375 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
package io.github.sculkpowered.server.attribute;

import io.github.sculkpowered.server.registry.Registry.Entry;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import org.intellij.lang.annotations.Subst;
import org.jetbrains.annotations.NotNull;

public record Attribute(@NotNull String key, int id, float def, float max) {
public record Attribute(
@NotNull Key key,
int id,
float def,
float min,
float max
) implements Entry {

public Attribute(@Subst("value") String key, int id, float def, float min, float max) {
this(Key.key(Key.MINECRAFT_NAMESPACE, key), id, def, min, max);
}

@Override
public @NotNull CompoundBinaryTag asNBT() {
return CompoundBinaryTag.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

public record AttributeModifier(
@NotNull UUID uniqueId,
@NotNull AttributeOperation operation,
String slot,
double amount
@NotNull String name,
double amount,
@NotNull AttributeOperation operation
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

public enum AttributeOperation {

ADD,
ADD_VALUE,
MULTIPLY_BASE,
MULTIPLY

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
package io.github.sculkpowered.server.attribute;

import io.github.sculkpowered.server.container.equipment.EquipmentSlot;

public enum AttributeSlot {

ANY("any"),
MAIN_HAND("mainhand"),
OFF_HAND("offhand"),
FEET("feet"),
LEGS("legs"),
CHEST("chest"),
HEAD("head"),
ARMOR("armor"),
BODY("body");
ANY("any", null),
MAIN_HAND("mainhand", EquipmentSlot.MAIN_HAND),
OFF_HAND("offhand", EquipmentSlot.OFF_HAND),
HAND("hand", null),
FEET("feet", EquipmentSlot.FEET),
LEGS("legs", EquipmentSlot.LEGS),
CHEST("chest", EquipmentSlot.CHEST),
HEAD("head", null),
ARMOR("armor", null),
BODY("body", null);

private final String key;
private final EquipmentSlot equipmentSlot;

AttributeSlot(final String key) {
AttributeSlot(final String key, final EquipmentSlot equipmentSlot) {
this.key = key;
this.equipmentSlot = equipmentSlot;
}

public String key() {
return this.key;
}

public EquipmentSlot equipmentSlot() {
return this.equipmentSlot;
}

public boolean is(final EquipmentSlot slot) {
return (this == AttributeSlot.ANY ||
(this == AttributeSlot.ARMOR && slot.isArmor()) ||
(this == AttributeSlot.HAND && slot.isHand()) ||
this.equipmentSlot() == slot);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@
public final class GenericAttribute {

public static final Attribute ARMOR =
new Attribute("generic.armor", 0, 0F, 30F);
new Attribute("generic.armor", 0, 0F, 0F, 30F);
public static final Attribute ARMOR_TOUGHNESS =
new Attribute("generic.armor_toughness", 1, 0F, 20F);
new Attribute("generic.armor_toughness", 1, 0F, 0F, 20F);
public static final Attribute ATTACK_DAMAGE =
new Attribute("generic.attack_damage", 2, 2F, 2048F);
new Attribute("generic.attack_damage", 2, 2F, 0F, 2048F);
public static final Attribute ATTACK_KNOCKBACK =
new Attribute("generic.attack_knockback", 3, 0F, 5F);
new Attribute("generic.attack_knockback", 3, 0F, 0F, 5F);
public static final Attribute ATTACK_SPEED =
new Attribute("generic.attack_speed", 4, 4F, 1024F);
new Attribute("generic.attack_speed", 4, 4F, 0F, 1024F);
public static final Attribute FALL_DAMAGE_MULTIPLIER =
new Attribute("generic.fall_damage_multiplier", 8, 1F, 100F);
new Attribute("generic.fall_damage_multiplier", 8, 1F, 0F, 100F);
public static final Attribute FLYING_SPEED =
new Attribute("generic.flying_speed", 9, 0.4F, 1024F);
new Attribute("generic.flying_speed", 9, 0.4F, 0F, 1024F);
public static final Attribute FOLLOW_RANGE =
new Attribute("generic.follow_range", 10, 32F, 2048F);
new Attribute("generic.follow_range", 10, 32F, 0F, 2048F);
public static final Attribute GRAVITY =
new Attribute("generic.gravity", 11, 0.08F, 1F);
new Attribute("generic.gravity", 11, 0.08F, -1F, 1F);
public static final Attribute JUMP_STRENGTH =
new Attribute("generic.jump_strength", 12, 0.42F, 32F);
new Attribute("generic.jump_strength", 12, 0.42F, 0F, 32F);
public static final Attribute KNOCKBACK_RESISTANCE =
new Attribute("generic.knockback_resistance", 13, 0F, 1F);
new Attribute("generic.knockback_resistance", 13, 0F, 0F, 1F);
public static final Attribute LUCK =
new Attribute("generic.luck", 14, 0F, 1024F);
new Attribute("generic.luck", 14, 0F, -1024F, 1024F);
public static final Attribute MAX_ABSORPTION =
new Attribute("generic.max_health", 15, 0F, 2048F);
new Attribute("generic.max_health", 15, 0F, 0F, 2048F);
public static final Attribute MAX_HEALTH =
new Attribute("generic.max_health", 16, 20F, 1024F);
new Attribute("generic.max_health", 16, 20F, 1F, 1024F);
public static final Attribute MOVEMENT_SPEED =
new Attribute("generic.movement_speed", 17, 0.7F, 1024F);
new Attribute("generic.movement_speed", 17, 0.7F, 0F, 1024F);
public static final Attribute SAFE_FALL_DISTANCE =
new Attribute("generic.safe_fall_distance", 18, 3F, 1024F);
new Attribute("generic.safe_fall_distance", 18, 3F, -1024F, 1024F);
public static final Attribute SCALE =
new Attribute("generic.scale", 19, 1, 16F);
new Attribute("generic.scale", 19, 1, 0.0625F, 16F);
public static final Attribute STEP_HEIGHT =
new Attribute("generic.step_height", 21, 0.6F, 10F);
new Attribute("generic.step_height", 21, 0.6F, 0F, 10F);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public interface Container {
*
* @param index the index of the item
* @param item the item to set
* @return the item previously at the index
* @since 1.0.0
*/
void item(int index, @NotNull ItemStack item);
@NotNull ItemStack item(int index, @NotNull ItemStack item);

/**
* Gets an item by its index.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,72 +1,11 @@
package io.github.sculkpowered.server.container;

import io.github.sculkpowered.server.container.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import io.github.sculkpowered.server.container.equipment.EntityEquipment;

/**
* Represents an inventory of a player.
*/
public interface Inventory extends Container {

/**
* @since 1.0.0
*/
@NotNull ItemStack itemInMainHand();

/**
* @since 1.0.0
*/
void itemInMainHand(@NotNull ItemStack item);

/**
* @since 1.0.0
*/
@NotNull ItemStack itemInOffHand();

/**
* @since 1.0.0
*/
void itemInOffHand(@NotNull ItemStack item);

/**
* @since 1.0.0
*/
void helmet(@NotNull ItemStack helmet);

/**
* @since 1.0.0
*/
@NotNull ItemStack helmet();

/**
* @since 1.0.0
*/
void chestplate(@NotNull ItemStack chestplate);

/**
* @since 1.0.0
*/
@NotNull ItemStack chestplate();

/**
* @since 1.0.0
*/
void leggings(@NotNull ItemStack leggings);

/**
* @since 1.0.0
*/
@NotNull ItemStack leggings();

/**
* @since 1.0.0
*/
void boots(@NotNull ItemStack boots);

/**
* @since 1.0.0
*/
@NotNull ItemStack boots();
public interface Inventory extends Container, EntityEquipment {

/**
* Resends the full inventory to the player.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package io.github.sculkpowered.server.container.equipment;

import io.github.sculkpowered.server.container.item.ItemStack;
import java.util.Map;
import org.jetbrains.annotations.NotNull;

/**
* Represents the equipment of an entity.
*/
public interface EntityEquipment {

/**
* Gets the equipment at the specified equipment slot.
* @param slot the slot
* @return the item at the specified equipment slot
* @since 1.0.0
*/
@NotNull ItemStack get(@NotNull EquipmentSlot slot);

/**
* Sets the equipment at the specified equipment slot.
* @param slot the slot
* @param equipment the item to set
* @return the previous item
* @since 1.0.0
*/
@NotNull ItemStack set(@NotNull EquipmentSlot slot, @NotNull ItemStack equipment);

/**
* @since 1.0.0
*/
default @NotNull ItemStack itemInMainHand() {
return this.get(EquipmentSlot.MAIN_HAND);
}

/**
* @since 1.0.0
*/
default void itemInMainHand(@NotNull ItemStack item) {
this.set(EquipmentSlot.MAIN_HAND, item);
}

/**
* @since 1.0.0
*/
default @NotNull ItemStack itemInOffHand() {
return this.get(EquipmentSlot.OFF_HAND);
}

/**
* @since 1.0.0
*/
default void itemInOffHand(@NotNull ItemStack item) {
this.set(EquipmentSlot.OFF_HAND, item);
}

/**
* @since 1.0.0
*/
default @NotNull ItemStack helmet() {
return this.get(EquipmentSlot.HEAD);
}

/**
* @since 1.0.0
*/
default void helmet(@NotNull ItemStack item) {
this.set(EquipmentSlot.HEAD, item);
}

/**
* @since 1.0.0
*/
default @NotNull ItemStack chestplate() {
return this.get(EquipmentSlot.CHEST);
}

/**
* @since 1.0.0
*/
default void chestplate(@NotNull ItemStack item) {
this.set(EquipmentSlot.CHEST, item);
}

/**
* @since 1.0.0
*/
default @NotNull ItemStack leggings() {
return this.get(EquipmentSlot.LEGS);
}

/**
* @since 1.0.0
*/
default void leggings(@NotNull ItemStack item) {
this.set(EquipmentSlot.LEGS, item);
}

/**
* @since 1.0.0
*/
default @NotNull ItemStack boots() {
return this.get(EquipmentSlot.FEET);
}

/**
* @since 1.0.0
*/
default void boots(@NotNull ItemStack item) {
this.set(EquipmentSlot.FEET, item);
}

/**
* Gets the equipment as a map.
* @return a map that contains the equipment, empty stacks are not stored
*/
Map<EquipmentSlot, ItemStack> asMap();
}
Loading

0 comments on commit 08d57f1

Please sign in to comment.