Skip to content

Commit

Permalink
merge with dev
Browse files Browse the repository at this point in the history
  • Loading branch information
BiConsumer committed Oct 14, 2023
2 parents ea5dc38 + ef605b9 commit 59dc3c8
Show file tree
Hide file tree
Showing 49 changed files with 43,518 additions and 1,117 deletions.
14 changes: 0 additions & 14 deletions api/src/main/java/team/unnamed/hephaestus/Bone.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,19 @@ public class Bone implements Examinable {

private final Map<String, Bone> children;

private final boolean small;
private final int customModelData;

public Bone(
String name,
Vector3Float position,
Vector3Float rotation,
Map<String, Bone> children,
boolean small,
int customModelData
) {
this.name = name;
this.position = position;
this.rotation = rotation;
this.children = children;
this.small = small;
this.customModelData = customModelData;
}

Expand Down Expand Up @@ -113,16 +110,6 @@ public int customModelData() {
return customModelData;
}

/**
* Determines whether to use small armor stands
* for this bone
*
* @return True to use small armor stands
*/
public boolean small() {
return small;
}

/**
* Returns this bone child bones
*
Expand All @@ -149,7 +136,6 @@ public Map<String, Bone> childrenMap() {
ExaminableProperty.of("rotation", rotation),
ExaminableProperty.of("bones", children),
ExaminableProperty.of("offset", position),
ExaminableProperty.of("small", small),
ExaminableProperty.of("customModelData", customModelData)
);
}
Expand Down
3 changes: 0 additions & 3 deletions api/src/main/java/team/unnamed/hephaestus/Minecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
@ApiStatus.Internal
public final class Minecraft {

public static final float ARMOR_STAND_SMALL_VERTICAL_OFFSET = 0.63F;
public static final float ARMOR_STAND_DEFAULT_VERTICAL_OFFSET = 1.452F; // todo: this must be tested

public static final float PLAYER_CREATIVE_PICK_RANGE = 5.0F;
public static final float PLAYER_DEFAULT_PICK_RANGE = 4.5F;

Expand Down
174 changes: 105 additions & 69 deletions api/src/main/java/team/unnamed/hephaestus/animation/Animation.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,48 @@
package team.unnamed.hephaestus.animation;

import net.kyori.examination.Examinable;
import net.kyori.examination.ExaminableProperty;
import net.kyori.examination.string.StringExaminer;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import team.unnamed.hephaestus.view.BaseModelView;
import team.unnamed.hephaestus.view.animation.AnimationController;
import team.unnamed.hephaestus.animation.timeline.BoneTimeline;

import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;

/**
* Represents a Model animation, applicable to
* {@link BaseModelView} instances via their
* {@link AnimationController} reference
* Represents a Model animation. Animations are a compound
* of keyframes by bone that modify the bone position,
* rotation and/or scale at a specific time.
*
* @since 1.0.0
*/
public final class Animation implements Examinable {

private final String name;
private final int length;
private final LoopMode loopMode;
private final Map<String, Timeline> timelines;

public Animation(
String name,
int length,
LoopMode loopMode,
Map<String, Timeline> timelines
public interface Animation extends Examinable {
/**
* Creates a new animation with the given
* name, length, loop mode and bone timelines
*
* @param name The animation name
* @param length The animation length, in ticks
* @param loopMode The animation loop mode
* @param timelines The animation bone timelines
* @return The created animation
* @since 1.0.0
*/
static @NotNull Animation animation(
final @NotNull String name,
final int length,
final @NotNull LoopMode loopMode,
final @NotNull Map<String, BoneTimeline> timelines
) {
this.name = Objects.requireNonNull(name, "name");
this.length = length;
this.loopMode = Objects.requireNonNull(loopMode, "loopMode");
this.timelines = Objects.requireNonNull(timelines, "timelines");
return new AnimationImpl(name, length, loopMode, timelines);
}

/**
* Creates a new animation builder
*
* @return The created animation builder
* @since 1.0.0
*/
static @NotNull Builder animation() {
return new AnimationImpl.BuilderImpl();
}

/**
Expand All @@ -66,9 +74,7 @@ public Animation(
* @return The animation name
* @since 1.0.0
*/
public String name() {
return name;
}
@NotNull String name();

/**
* Returns the animation length, in
Expand All @@ -77,9 +83,7 @@ public String name() {
* @return The animation length
* @since 1.0.0
*/
public int length() {
return length;
}
int length();

/**
* Returns the animation loop mode,
Expand All @@ -90,9 +94,7 @@ public int length() {
* @return The animation loop mode
* @since 1.0.0
*/
public LoopMode loopMode() {
return loopMode;
}
@NotNull LoopMode loopMode();

/**
* Returns the animation bone timelines,
Expand All @@ -106,40 +108,7 @@ public LoopMode loopMode() {
* @return The animation bone timelines
* @since 1.0.0
*/
public Map<String, Timeline> timelines() {
return timelines;
}

@Override
public @NotNull Stream<? extends ExaminableProperty> examinableProperties() {
return Stream.of(
ExaminableProperty.of("name", name),
ExaminableProperty.of("length", length),
ExaminableProperty.of("loopMode", loopMode),
ExaminableProperty.of("timelines", timelines)
);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Animation that = (Animation) o;
return name.equals(that.name)
&& length == that.length
&& loopMode == that.loopMode
&& timelines.equals(that.timelines);
}

@Override
public int hashCode() {
return Objects.hash(name, length, loopMode, timelines);
}

@Override
public String toString() {
return examine(StringExaminer.simpleEscaping());
}
@NotNull Map<String, BoneTimeline> timelines();

/**
* An enum containing all the possible
Expand All @@ -149,7 +118,7 @@ public String toString() {
*
* @since 1.0.0
*/
public enum LoopMode {
enum LoopMode {

/**
* ONCE, makes the animation play once
Expand Down Expand Up @@ -177,4 +146,71 @@ public enum LoopMode {
LOOP
}

/**
* A builder for animations
*
* @since 1.0.0
*/
interface Builder {

/**
* Sets the animation name
*
* @param name The animation name
* @return This builder
* @since 1.0.0
*/
@Contract("_ -> this")
@NotNull Builder name(@NotNull String name);

/**
* Sets the animation length, in ticks
*
* @param length The animation length
* @return This builder
* @since 1.0.0
*/
@Contract("_ -> this")
@NotNull Builder length(final int length);

/**
* Sets the animation loop mode
*
* @param loopMode The animation loop mode
* @return This builder
* @since 1.0.0
*/
@Contract("_ -> this")
@NotNull Builder loopMode(final @NotNull LoopMode loopMode);

/**
* Sets the animation bone timelines
*
* @param timelines The animation bone timelines
* @return This builder
* @since 1.0.0
*/
@NotNull Builder timelines(final @NotNull Map<String, BoneTimeline> timelines);

/**
* Adds a bone timeline to the animation
*
* @param boneName The bone name
* @param timeline The bone timeline
* @return This builder
* @since 1.0.0
*/
@Contract("_, _ -> this")
@NotNull Builder timeline(final @NotNull String boneName, final @NotNull BoneTimeline timeline);

/**
* Builds the animation
*
* @return The built animation
* @since 1.0.0
*/
@Contract("-> new")
@NotNull Animation build();

}
}
Loading

0 comments on commit 59dc3c8

Please sign in to comment.