示例#1
0
        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);
        }
示例#2
0
        public static int WriteDefineModelPart(byte[] buffer, byte modelId, CustomModelPart part)
        {
            int i = 0;

            buffer[i++] = Opcode.CpeDefineModelPart;
            buffer[i++] = modelId;

            /* write min, max vec3 coords */
            NetUtils.WriteF32(part.min.X, buffer, i);
            i += 4;
            NetUtils.WriteF32(part.min.Y, buffer, i);
            i += 4;
            NetUtils.WriteF32(part.min.Z, buffer, i);
            i += 4;

            NetUtils.WriteF32(part.max.X, buffer, i);
            i += 4;
            NetUtils.WriteF32(part.max.Y, buffer, i);
            i += 4;
            NetUtils.WriteF32(part.max.Z, buffer, i);
            i += 4;

            /* write u, v coords for our 6 faces */
            for (int j = 0; j < 6; j++)
            {
                NetUtils.WriteU16(part.u1[j], buffer, i);
                i += 2;
                NetUtils.WriteU16(part.v1[j], buffer, i);
                i += 2;

                NetUtils.WriteU16(part.u2[j], buffer, i);
                i += 2;
                NetUtils.WriteU16(part.v2[j], buffer, i);
                i += 2;
            }

            /* write rotation origin point */
            NetUtils.WriteF32(part.rotationOrigin.X, buffer, i);
            i += 4;
            NetUtils.WriteF32(part.rotationOrigin.Y, buffer, i);
            i += 4;
            NetUtils.WriteF32(part.rotationOrigin.Z, buffer, i);
            i += 4;

            /* write rotation angles */
            NetUtils.WriteF32(part.rotation.X, buffer, i);
            i += 4;
            NetUtils.WriteF32(part.rotation.Y, buffer, i);
            i += 4;
            NetUtils.WriteF32(part.rotation.Z, buffer, i);
            i += 4;

            return(i);
        }
示例#3
0
        public static byte[] DefineModelPart(byte modelId, CustomModelPart part)
        {
            // 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);
        }