mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-10-03 10:33:29 -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,
|
Y = 0.0f,
|
||||||
Z = 0.0f,
|
Z = 0.0f,
|
||||||
};
|
};
|
||||||
public CustomModelAnim anim = CustomModelAnim.None;
|
public CustomModelAnim[] anims;
|
||||||
public float animModifier = 1.0f;
|
|
||||||
public bool fullbright = false;
|
public bool fullbright = false;
|
||||||
public bool firstPersonArm = 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,
|
None = 0,
|
||||||
Head = 1,
|
Head = 1,
|
||||||
LeftLeg = 2,
|
LeftLegX = 2,
|
||||||
RightLeg = 3,
|
RightLegX = 3,
|
||||||
LeftArm = 4,
|
LeftArmX = 4,
|
||||||
RightArm = 5,
|
LeftArmZ = 5,
|
||||||
SpinX = 6,
|
RightArmX = 6,
|
||||||
SpinY = 7,
|
RightArmZ = 7,
|
||||||
SpinZ = 8,
|
Spin = 8,
|
||||||
SpinXVelocity = 9,
|
SpinVelocity = 9,
|
||||||
SpinYVelocity = 10,
|
SinRotate = 10,
|
||||||
SpinZVelocity = 11,
|
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 MaxCustomModels = 64;
|
||||||
public const int MaxCustomModelParts = 64;
|
public const int MaxCustomModelParts = 64;
|
||||||
|
public const int MaxCustomModelAnims = 4;
|
||||||
public static byte[] DefineModel(byte modelId, CustomModel customModel) {
|
public static byte[] DefineModel(byte modelId, CustomModel customModel) {
|
||||||
// 116 = 1 + 1 + 64 + 1 + 2*4 + 3*4 + 2*3*4 + 2*2 + 1
|
// 116 = 1 + 1 + 64 + 1 + 2*4 + 3*4 + 2*3*4 + 2*2 + 1
|
||||||
byte[] buffer = new byte[116];
|
byte[] buffer = new byte[116];
|
||||||
@ -521,8 +522,57 @@ namespace MCGalaxy.Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] DefineModelPart(byte modelId, CustomModelPart part) {
|
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];
|
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;
|
int i = 0;
|
||||||
buffer[i++] = Opcode.CpeDefineModelPart;
|
buffer[i++] = Opcode.CpeDefineModelPart;
|
||||||
buffer[i++] = modelId;
|
buffer[i++] = modelId;
|
||||||
@ -571,21 +621,7 @@ namespace MCGalaxy.Network {
|
|||||||
NetUtils.WriteF32(part.rotation.Z, buffer, i);
|
NetUtils.WriteF32(part.rotation.Z, buffer, i);
|
||||||
i += 4;
|
i += 4;
|
||||||
|
|
||||||
// write anim
|
return i;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] UndefineModel(byte modelId) {
|
public static byte[] UndefineModel(byte modelId) {
|
||||||
|
@ -49,7 +49,7 @@ namespace MCGalaxy {
|
|||||||
new CpeExtension(CpeExt.InstantMOTD), new CpeExtension(CpeExt.FastMap),
|
new CpeExtension(CpeExt.InstantMOTD), new CpeExtension(CpeExt.FastMap),
|
||||||
new CpeExtension(CpeExt.ExtTextures), new CpeExtension(CpeExt.SetHotbar),
|
new CpeExtension(CpeExt.ExtTextures), new CpeExtension(CpeExt.SetHotbar),
|
||||||
new CpeExtension(CpeExt.SetSpawnpoint), new CpeExtension(CpeExt.VelocityControl),
|
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
|
#if TEN_BIT_BLOCKS
|
||||||
new CpeExtension(CpeExt.ExtBlocks),
|
new CpeExtension(CpeExt.ExtBlocks),
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user