-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81267ea
commit 2294415
Showing
19 changed files
with
213 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/net/worldseed/multipart/model_bones/display_entity/ModelBoneHeadDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package net.worldseed.multipart.model_bones.display_entity; | ||
|
||
import net.minestom.server.coordinate.Point; | ||
import net.minestom.server.coordinate.Vec; | ||
import net.minestom.server.entity.LivingEntity; | ||
import net.worldseed.multipart.GenericModel; | ||
import net.worldseed.multipart.ModelConfig; | ||
import net.worldseed.multipart.ModelLoader; | ||
import net.worldseed.multipart.animations.ModelAnimation; | ||
import net.worldseed.multipart.model_bones.ModelBoneHead; | ||
import net.worldseed.multipart.model_bones.ModelBoneViewable; | ||
import net.worldseed.multipart.model_bones.zombie.ModelBonePartZombie; | ||
|
||
public class ModelBoneHeadDisplay extends ModelBonePartDisplay implements ModelBoneHead, ModelBoneViewable { | ||
private double headRotation; | ||
|
||
public ModelBoneHeadDisplay(Point pivot, String name, Point rotation, GenericModel model, ModelConfig config, LivingEntity forwardTo) { | ||
super(pivot, name, rotation, model, config, forwardTo); | ||
} | ||
|
||
@Override | ||
public Point getPropogatedRotation() { | ||
Point netTransform = Vec.ZERO; | ||
|
||
for (ModelAnimation currentAnimation : this.allAnimations) { | ||
if (currentAnimation != null && currentAnimation.isPlaying()) { | ||
if (currentAnimation.getType() == ModelLoader.AnimationType.ROTATION) { | ||
Point calculatedTransform = currentAnimation.getTransform(); | ||
netTransform = netTransform.add(calculatedTransform); | ||
} | ||
} | ||
} | ||
|
||
return this.rotation.add(netTransform).add(0, this.headRotation, 0); | ||
} | ||
|
||
public void setRotation(double rotation) { | ||
this.headRotation = rotation; | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/main/java/net/worldseed/multipart/model_bones/display_entity/ModelBonePartDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package net.worldseed.multipart.model_bones.display_entity; | ||
|
||
import net.minestom.server.coordinate.Point; | ||
import net.minestom.server.coordinate.Pos; | ||
import net.minestom.server.coordinate.Vec; | ||
import net.minestom.server.entity.Entity; | ||
import net.minestom.server.entity.EntityType; | ||
import net.minestom.server.entity.LivingEntity; | ||
import net.minestom.server.entity.metadata.display.ItemDisplayMeta; | ||
import net.minestom.server.item.ItemStack; | ||
import net.worldseed.multipart.GenericModel; | ||
import net.worldseed.multipart.ModelConfig; | ||
import net.worldseed.multipart.Quaternion; | ||
import net.worldseed.multipart.model_bones.ModelBone; | ||
import net.worldseed.multipart.model_bones.ModelBoneImpl; | ||
import net.worldseed.multipart.model_bones.ModelBoneViewable; | ||
|
||
public class ModelBonePartDisplay extends ModelBoneImpl implements ModelBoneViewable { | ||
int sendTick = 0; | ||
|
||
public ModelBonePartDisplay(Point pivot, String name, Point rotation, GenericModel model, ModelConfig config, LivingEntity forwardTo) { | ||
super(pivot, name, rotation, model); | ||
|
||
if (this.offset != null) { | ||
this.stand = new Entity(EntityType.ITEM_DISPLAY) { | ||
@Override | ||
public void tick(long time) {} | ||
}; | ||
|
||
var meta = (ItemDisplayMeta) this.stand.getEntityMeta(); | ||
|
||
meta.setScale(new Vec(1, 1, 1)); | ||
meta.setDisplayContext(ItemDisplayMeta.DisplayContext.FIXED); | ||
meta.setInterpolationDuration(3); | ||
ModelBoneImpl.hookPart(this, forwardTo); | ||
} | ||
} | ||
|
||
@Override | ||
public Pos calculatePosition() { | ||
if (this.offset == null) return Pos.ZERO; | ||
|
||
Point p = this.offset; | ||
p = applyTransform(p); | ||
p = calculateGlobalRotation(p); | ||
|
||
Pos endPos = Pos.fromPoint(p); | ||
|
||
return Pos.fromPoint(endPos).div(4); | ||
} | ||
|
||
@Override | ||
public Point calculateRotation() { | ||
Quaternion q = calculateFinalAngle(new Quaternion(getPropogatedRotation())); | ||
if (model.getGlobalRotation() != 0) { | ||
Quaternion pq = new Quaternion(new Vec(0, this.model.getGlobalRotation(), 0)); | ||
q = pq.multiply(q); | ||
} | ||
|
||
return q.toEulerYZX(); | ||
} | ||
|
||
public void draw() { | ||
this.children.forEach(ModelBone::draw); | ||
if (this.offset == null) return; | ||
|
||
sendTick++; | ||
|
||
if (sendTick % 2 == 0 && this.stand != null && this.stand.getEntityMeta() instanceof ItemDisplayMeta meta) { | ||
var position = calculatePosition(); | ||
Quaternion q = calculateFinalAngle(new Quaternion(getPropogatedRotation())); | ||
if (model.getGlobalRotation() != 0) { | ||
Quaternion pq = new Quaternion(new Vec(0, this.model.getGlobalRotation(), 0)); | ||
q = pq.multiply(q); | ||
} | ||
|
||
meta.setNotifyAboutChanges(false); | ||
meta.setInterpolationStartDelta(0); | ||
meta.setRightRotation(new float[] {(float) q.x(), (float) q.y(), (float) q.z(), (float) q.w()}); | ||
meta.setTranslation(position); | ||
meta.setNotifyAboutChanges(true); | ||
} | ||
|
||
stand.teleport(Pos.fromPoint(model.getPosition())); | ||
} | ||
|
||
@Override | ||
public void setState(String state) { | ||
if (this.stand != null && this.stand.getEntityMeta() instanceof ItemDisplayMeta meta) { | ||
if (state.equals("invisible")) { | ||
meta.setItemStack(ItemStack.AIR); | ||
return; | ||
} | ||
|
||
var item = this.items.get(state); | ||
if (item != null) { | ||
meta.setItemStack(item); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.