Skip to content

Commit b8be148

Browse files
committed
fix full-entity rotation of the model
1 parent 7fc7743 commit b8be148

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

DenizenModelsConverter/MinecraftModelMaker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static string CreateModelFor(BBModel model, BBModel.Outliner outline)
8282
group.Add("color", 0);
8383
group.Add("children", childrenList);
8484
groups.Add(group);
85-
head.Add("translation", new JArray(8 * Program.SCALE, 2 * Program.SCALE, 8 * Program.SCALE));
85+
head.Add("translation", new JArray(8 * Program.SCALE, 3.75 * Program.SCALE, 8 * Program.SCALE));
8686
head.Add("scale", new JArray(Program.SCALE, Program.SCALE, Program.SCALE));
8787
display.Add("head", head);
8888
jout.Add("textures", textures);

scripts/dmodels.dsc

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
#
1616
# Usage:
1717
# 1: Create a model using blockbench - https://www.blockbench.net/
18-
# Create as a 'Generic Model'
19-
# Make basically anything you want
20-
# Make sure pivot points are as centered as possible to minimize glitchiness from animations
21-
# (animations around a distant pivot point require the armor stand move and turn at the same time, which can lose sync with itself)
22-
# Animate freely, make sure the animation names are clear
18+
# 1.1 Create as a 'Generic Model'
19+
# 1.2 Make basically anything you want
20+
# 1.3 Note that each block cannot have a coordinate value beyond 32 (Minecraft limitation)
21+
# 1.4 Make sure pivot points are as correct as possible to minimize glitchiness from animations
22+
# (for example, if you have a bone pivot point in the center of a block, but the block's own pivot point is left at default 0,0,0, this can lead to the armor stand having to move and rotate at the same time, and lose sync when doing so)
23+
# 1.5 Animate freely, make sure the animation names are clear
2324
# 2: Save the ".bbmodel" file
2425
# 3: Use the DenizenModelsConverter program to convert the bbmodel to a ".dmodel.yml" and a resource pack
2526
# 4: Save the ".dmodel.yml" file into "plugins/Denizen/data/models"
@@ -41,6 +42,8 @@
4142
# - run dmodels_end_animation def.root_entity:<[root]>
4243
# # To move the entity to a single frame of an animation (timespot is a decimal number of seconds from the start of the animation)
4344
# - run dmodels_move_to_frame def.root_entity:<[root]> def.animation:idle def.timespot:0.5
45+
#
46+
################################################
4447

4548

4649

@@ -90,7 +93,9 @@ dmodels_spawn_model:
9093
- if !<server.has_flag[dmodels_data.model_<[model_name]>]>:
9194
- debug error "[DModels] cannot spawn model <[model_name]>, model not loaded"
9295
- stop
93-
- define location <[location].center.with_yaw[180]>
96+
# 0.72 is arbitrary but seems to align the bottom to the ground from visual testing
97+
- define center <[location].with_pitch[0].below[0.72]>
98+
- define yaw_mod <[location].yaw.add[180].to_radians>
9499
- spawn dmodel_part_stand <[location]> save:root
95100
- flag <entry[root].spawned_entity> dmodel_model_id:<[model_name]>
96101
- foreach <server.flag[dmodels_data.model_<[model_name]>]> key:id as:part:
@@ -99,10 +104,11 @@ dmodels_spawn_model:
99104
# Idk wtf is with the scale here. It's somewhere in the range of 25 to 26. 25.45 seems closest in one of my tests,
100105
# but I think that's minecraft packet location imprecision at fault so it's possibly just 26?
101106
# Supposedly it's 25.6 according to external docs (16 * 1.6), but that also is wrong in my testing.
102-
- define offset <location[<[part.origin]>].div[25.6]>
107+
# 24.5 is closest in my testing thus far.
108+
- define offset <location[<[part.origin]>].div[24.5]>
103109
- define rots <[part.rotation].split[,].parse[to_radians]>
104110
- define pose <[rots].get[1].mul[-1]>,<[rots].get[2].mul[-1]>,<[rots].get[3]>
105-
- spawn dmodel_part_stand[equipment=[helmet=<[part.item]>];armor_pose=[head=<[pose]>]] <[location].add[<[offset]>]> save:spawned
111+
- spawn dmodel_part_stand[equipment=[helmet=<[part.item]>];armor_pose=[head=<[pose]>]] <[center].add[<[offset].rotate_around_y[<[yaw_mod].mul[-1]>]>]> save:spawned
106112
- flag <entry[spawned].spawned_entity> dmodel_def_pose:<[pose]>
107113
- flag <entry[spawned].spawned_entity> dmodel_def_offset:<[offset]>
108114
- flag <entry[spawned].spawned_entity> dmodel_root:<entry[root].spawned_entity>
@@ -115,9 +121,11 @@ dmodels_reset_model_position:
115121
debug: false
116122
definitions: root_entity
117123
script:
124+
- define center <[root_entity].location.with_pitch[0].below[0.72]>
125+
- define yaw_mod <[root_entity].location.yaw.add[180].to_radians>
118126
- foreach <[root_entity].flag[dmodel_parts]> as:part:
119127
- adjust <[part]> armor_pose:[head=<[part].flag[dmodel_def_pose]>]
120-
- teleport <[part]> <[root_entity].location.add[<[part].flag[dmodel_def_offset]>]>
128+
- teleport <[part]> <[center].add[<[part].flag[dmodel_def_offset].rotate_around_y[<[yaw_mod].mul[-1]>]>]>
121129

122130
dmodels_end_animation:
123131
type: task
@@ -164,6 +172,8 @@ dmodels_move_to_frame:
164172
- case hold:
165173
- define timespot <[animation_data.length]>
166174
- flag server dmodels_anim_active.<[root_entity].uuid>:!
175+
- define center <[root_entity].location.with_pitch[0].below[0.72]>
176+
- define yaw_mod <[root_entity].location.yaw.add[180].to_radians>
167177
- define parentage <map>
168178
- foreach <[animation_data.animators]> key:part_id as:animator:
169179
- define framedata.position 0,0,0
@@ -218,7 +228,8 @@ dmodels_move_to_frame:
218228
- define parentage.<[part_id]>.rotation:<[new_rot]>
219229
- define parentage.<[part_id]>.offset:<[rot_offset].add[<[parent_offset]>]>
220230
- foreach <[root_entity].flag[dmodel_anim_part.<[part_id]>]||<list>> as:ent:
221-
- teleport <[ent]> <[root_entity].location.add[<[new_pos].div[25.6]>]>
231+
# Note: 24.5 is the offset multiplifer explained in the comments of dmodels_spawn_model
232+
- teleport <[ent]> <[center].add[<[new_pos].div[24.5].rotate_around_y[<[yaw_mod].mul[-1]>]>]>
222233
- define radian_rot <[new_rot].add[<[pose]>].xyz.split[,]>
223234
- define pose <[radian_rot].get[1]>,<[radian_rot].get[2]>,<[radian_rot].get[3]>
224235
- adjust <[ent]> armor_pose:[head=<[pose]>]

0 commit comments

Comments
 (0)