mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-10-02 10:01:34 -04:00
Custom Models v2 (#541)
* Custom Models v2 allows for more modifiers and more animations per part * anims now use a specified axis * remove default value for a,b,c,d
This commit is contained in:
parent
824db6fa0b
commit
7bb7119d33
@ -51,24 +51,41 @@ namespace MCGalaxy {
|
||||
Y = 0.0f,
|
||||
Z = 0.0f,
|
||||
};
|
||||
public CustomModelAnim anim = CustomModelAnim.None;
|
||||
public float animModifier = 1.0f;
|
||||
public CustomModelAnim[] anims;
|
||||
public bool fullbright = false;
|
||||
public bool firstPersonArm = false;
|
||||
}
|
||||
|
||||
public enum CustomModelAnim {
|
||||
public class CustomModelAnim {
|
||||
public CustomModelAnimType type = CustomModelAnimType.None;
|
||||
public CustomModelAnimAxis axis;
|
||||
|
||||
public float a;
|
||||
public float b;
|
||||
public float c;
|
||||
public float d;
|
||||
}
|
||||
|
||||
public enum CustomModelAnimType {
|
||||
None = 0,
|
||||
Head = 1,
|
||||
LeftLeg = 2,
|
||||
RightLeg = 3,
|
||||
LeftArm = 4,
|
||||
RightArm = 5,
|
||||
SpinX = 6,
|
||||
SpinY = 7,
|
||||
SpinZ = 8,
|
||||
SpinXVelocity = 9,
|
||||
SpinYVelocity = 10,
|
||||
SpinZVelocity = 11,
|
||||
LeftLegX = 2,
|
||||
RightLegX = 3,
|
||||
LeftArmX = 4,
|
||||
LeftArmZ = 5,
|
||||
RightArmX = 6,
|
||||
RightArmZ = 7,
|
||||
Spin = 8,
|
||||
SpinVelocity = 9,
|
||||
SinRotate = 10,
|
||||
SinRotateVelocity = 11,
|
||||
SinTranslate = 12,
|
||||
SinTranslateVelocity = 13
|
||||
}
|
||||
|
||||
public enum CustomModelAnimAxis {
|
||||
X = 0,
|
||||
Y = 1,
|
||||
Z = 2,
|
||||
}
|
||||
}
|
||||
|
@ -460,6 +460,7 @@ namespace MCGalaxy.Network {
|
||||
|
||||
public const int MaxCustomModels = 64;
|
||||
public const int MaxCustomModelParts = 64;
|
||||
public const int MaxCustomModelAnims = 4;
|
||||
public static byte[] DefineModel(byte modelId, CustomModel customModel) {
|
||||
// 116 = 1 + 1 + 64 + 1 + 2*4 + 3*4 + 2*3*4 + 2*2 + 1
|
||||
byte[] buffer = new byte[116];
|
||||
@ -521,8 +522,57 @@ namespace MCGalaxy.Network {
|
||||
}
|
||||
|
||||
public static byte[] DefineModelPart(byte modelId, CustomModelPart part) {
|
||||
// 104 = 1 + 1 + 3*4 + 3*4 + 6*(2*2 + 2*2) + 3*4 + 3*4 + 1 + 4 + 1
|
||||
// v1: 104 = (1 + 1 + 3*4 + 3*4 + 6*(2*2 + 2*2) + 3*4 + 3*4) + 1 + 4 + 1
|
||||
byte[] buffer = new byte[104];
|
||||
int i = WriteDefineModelPart(buffer, modelId, part);
|
||||
|
||||
// ignore animations
|
||||
i++;
|
||||
i += 4;
|
||||
|
||||
// write bool flags
|
||||
byte flags = 0;
|
||||
flags |= (byte)((part.fullbright ? 1 : 0) << 0);
|
||||
flags |= (byte)((part.firstPersonArm ? 1 : 0) << 1);
|
||||
|
||||
buffer[i++] = flags;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static byte[] DefineModelPartV2(byte modelId, CustomModelPart part) {
|
||||
// v2: 167 = (1 + 1 + 3*4 + 3*4 + 6*(2*2 + 2*2) + 3*4 + 3*4) + 4*(1 + 4*4) + 1
|
||||
byte[] buffer = new byte[167];
|
||||
int i = WriteDefineModelPart(buffer, modelId, part);
|
||||
|
||||
for (int j = 0; j < MaxCustomModelAnims; j++) {
|
||||
var anim = part.anims[j];
|
||||
|
||||
buffer[i++] = (byte)(
|
||||
((byte)anim.type & 0x3F) | ((byte)anim.axis << 6)
|
||||
);
|
||||
|
||||
NetUtils.WriteF32(anim.a, buffer, i);
|
||||
i += 4;
|
||||
NetUtils.WriteF32(anim.b, buffer, i);
|
||||
i += 4;
|
||||
NetUtils.WriteF32(anim.c, buffer, i);
|
||||
i += 4;
|
||||
NetUtils.WriteF32(anim.d, buffer, i);
|
||||
i += 4;
|
||||
}
|
||||
|
||||
// write bool flags
|
||||
byte flags = 0;
|
||||
flags |= (byte)((part.fullbright ? 1 : 0) << 0);
|
||||
flags |= (byte)((part.firstPersonArm ? 1 : 0) << 1);
|
||||
|
||||
buffer[i++] = flags;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static int WriteDefineModelPart(byte[] buffer, byte modelId, CustomModelPart part) {
|
||||
int i = 0;
|
||||
buffer[i++] = Opcode.CpeDefineModelPart;
|
||||
buffer[i++] = modelId;
|
||||
@ -571,21 +621,7 @@ namespace MCGalaxy.Network {
|
||||
NetUtils.WriteF32(part.rotation.Z, buffer, i);
|
||||
i += 4;
|
||||
|
||||
// write anim
|
||||
buffer[i++] = (byte)part.anim;
|
||||
|
||||
// write animModifier
|
||||
NetUtils.WriteF32(part.animModifier, buffer, i);
|
||||
i += 4;
|
||||
|
||||
// write bool flags
|
||||
byte flags = 0;
|
||||
flags |= (byte)((part.fullbright ? 1 : 0) << 0);
|
||||
flags |= (byte)((part.firstPersonArm ? 1 : 0) << 1);
|
||||
|
||||
buffer[i++] = flags;
|
||||
|
||||
return buffer;
|
||||
return i;
|
||||
}
|
||||
|
||||
public static byte[] UndefineModel(byte modelId) {
|
||||
|
@ -15,9 +15,9 @@
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using MCGalaxy.Network;
|
||||
using BlockID = System.UInt16;
|
||||
using System;
|
||||
using MCGalaxy.Network;
|
||||
using BlockID = System.UInt16;
|
||||
|
||||
namespace MCGalaxy {
|
||||
public sealed class CpeExtension {
|
||||
@ -49,7 +49,7 @@ namespace MCGalaxy {
|
||||
new CpeExtension(CpeExt.InstantMOTD), new CpeExtension(CpeExt.FastMap),
|
||||
new CpeExtension(CpeExt.ExtTextures), new CpeExtension(CpeExt.SetHotbar),
|
||||
new CpeExtension(CpeExt.SetSpawnpoint), new CpeExtension(CpeExt.VelocityControl),
|
||||
new CpeExtension(CpeExt.CustomParticles), new CpeExtension(CpeExt.CustomModels),
|
||||
new CpeExtension(CpeExt.CustomParticles), new CpeExtension(CpeExt.CustomModels, 2),
|
||||
#if TEN_BIT_BLOCKS
|
||||
new CpeExtension(CpeExt.ExtBlocks),
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user