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
4 changes: 2 additions & 2 deletions src/main/java/net/worldseed/gestures/ModelBoneEmote.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ModelBoneEmote(Point pivot, String name, Point rotation, GenericModel mod
});
}

switch(this.name) {
switch (this.name) {
case "Head" -> {
this.diff = this.pivot.add(0, 0, 0);
}
Expand Down Expand Up @@ -207,6 +207,6 @@ public void detachModel(GenericModel model) {
}

@Override
public void setGlobalRotation(double rotation) {
public void setGlobalRotation(double yaw, double pitch) {
}
}
17 changes: 17 additions & 0 deletions src/main/java/net/worldseed/multipart/GenericModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public interface GenericModel extends Viewable, EventHandler<ModelEvent>, Shape
*/
Point getPivot();

/**
* Get the rotation of the model on the X axis
*
* @return the pitch
*/
double getPitch();

/**
* Get the rotation of the model on the Y axis
*
Expand All @@ -50,6 +57,14 @@ public interface GenericModel extends Viewable, EventHandler<ModelEvent>, Shape
*/
void setGlobalRotation(double rotation);

/**
* Set the rotation of the model on the Y and X axis
*
* @param yaw new global rotation
* @param pitch new pitch
*/
void setGlobalRotation(double yaw, double pitch);

/**
* Get the postion offset for drawing the model
*
Expand Down Expand Up @@ -140,6 +155,8 @@ public interface GenericModel extends Viewable, EventHandler<ModelEvent>, Shape
@Nullable BoneEntity generateRoot();

void bindNametag(String name, Entity nametag);

void unbindNametag(String name);

@Nullable Entity getNametag(String name);
}
24 changes: 19 additions & 5 deletions src/main/java/net/worldseed/multipart/GenericModelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ public abstract class GenericModelImpl implements GenericModel {
protected Instance instance;
private Pos position;
private double globalRotation;
private double pitch;

protected record ModelBoneInfo(String name, Point pivot, Point rotation, JsonArray cubes, GenericModel model,
float scale) {
}

protected record ModelBoneInfo(String name, Point pivot, Point rotation, JsonArray cubes, GenericModel model, float scale) {}
protected final Map<Predicate<String>, Function<ModelBoneInfo, @Nullable ModelBone>> boneSuppliers = new LinkedHashMap<>();
Function<ModelBoneInfo, ModelBone> defaultBoneSupplier = (info) -> new ModelBonePartDisplay(info.pivot, info.name, info.rotation, info.model, info.scale);

Expand All @@ -80,11 +84,21 @@ public double getGlobalRotation() {
return globalRotation;
}

public void setGlobalRotation(double rotation) {
this.globalRotation = rotation;
@Override
public double getPitch(){
return pitch;
}

public void setGlobalRotation(double yaw) {
setGlobalRotation(yaw, 0.0f);
}

public void setGlobalRotation(double yaw, double pitch) {
this.globalRotation = yaw;
this.pitch = pitch;

this.viewableBones.forEach(part -> {
part.setGlobalRotation(rotation);
part.setGlobalRotation(yaw, pitch);
});
}

Expand Down Expand Up @@ -485,4 +499,4 @@ public Entity getNametag(String name) {
if (this.parts.get(name) instanceof ModelBoneNametag nametagBone) return nametagBone.getNametag();
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public interface ModelBone {

void detachModel(GenericModel model);

void setGlobalRotation(double rotation);
void setGlobalRotation(double yaw, double pitch);

default void teleport(Point position) {}

default @NotNull Collection<ModelBone> getChildren() {
return List.of();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,11 @@ public void detachModel(GenericModel model) {
}

@Override
public void setGlobalRotation(double rotation) {
public void setGlobalRotation(double yaw, double pitch) {
if (this.stand != null) {
var correctLocation = (180 + this.model.getGlobalRotation() + 360) % 360;
this.stand.setView((float) correctLocation, 0);
var correctYaw = (180 + yaw + 360) % 360;
var correctPitch = (pitch + 360) % 360;
this.stand.setView((float) correctYaw, (float) correctPitch);
}
}

Expand Down Expand Up @@ -249,4 +250,4 @@ public void setState(String state) {
public Point getPosition() {
return calculatePositionInternal().add(model.getPosition());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void detachModel(GenericModel model) {
}

@Override
public void setGlobalRotation(double rotation) {
public void setGlobalRotation(double yaw, double pitch) {
}

public void generateStands(JsonArray cubes, Point pivotPos, String name, Point boneRotation, GenericModel genericModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void detachModel(GenericModel model) {
}

@Override
public void setGlobalRotation(double rotation) {
public void setGlobalRotation(double yaw, double pitch) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void detachModel(GenericModel model) {
}

@Override
public void setGlobalRotation(double rotation) {
public void setGlobalRotation(double yaw, double pitch) {

}

Expand Down Expand Up @@ -159,4 +159,4 @@ public void removePassenger(Entity entity) {
public Set<Entity> getPassengers() {
return this.stand.getPassengers();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void detachModel(GenericModel model) {
}

@Override
public void setGlobalRotation(double rotation) {
public void setGlobalRotation(double yaw, double pitch) {

}

Expand Down