Exemplo n.º 1
0
        protected override void EntityInit(CompoundTag nbt)
        {
            base.EntityInit(nbt);

            this.Attributes.AddAttribute(EntityAttribute.HUNGER);
            this.Attributes.AddAttribute(EntityAttribute.SATURATION);
            this.Attributes.AddAttribute(EntityAttribute.EXHAUSTION);
            this.Attributes.AddAttribute(EntityAttribute.EXPERIENCE);
            this.Attributes.AddAttribute(EntityAttribute.EXPERIENCE_LEVEL);

            this.SetFlag(DATA_FLAGS, DATA_FLAG_BREATHING);
            this.SetFlag(DATA_FLAGS, DATA_FLAG_CAN_CLIMB);

            this.Inventory = new PlayerInventory(this);
            this.Inventory.LoadNBT(nbt);

            this.World = World.GetWorld(nbt.GetString("World")) ?? World.GetMainWorld();

            this.SpawnX = nbt.GetInt("SpawnX");
            this.SpawnY = nbt.GetInt("SpawnY");
            this.SpawnZ = nbt.GetInt("SpawnZ");

            this.AdventureSettingsEntry = new AdventureSettingsEntry();

            this.GameMode = GameModeExtention.FromIndex(nbt.GetInt("PlayerGameType"));
        }
Exemplo n.º 2
0
        protected override void EntityInit(CompoundTag nbt)
        {
            base.EntityInit(nbt);

            this.Age         = nbt.GetShort("Age");
            this.PickupDelay = nbt.GetShort("PickupDelay");
            this.Owner       = nbt.GetString("Owner");
            this.Item        = NBTIO.ReadItem(nbt.GetCompound("Item"));

            this.SetFlag(Entity.DATA_FLAGS, Entity.DATA_FLAG_IMMOBILE, true);
        }
        internal static JObject CompoundTagSerialize(CompoundTag tag)
        {
            JObject json = new JObject();

            foreach (KeyValuePair <string, Tag> kv in tag.Tags)
            {
                Tag t = kv.Value;
                if (t is ByteTag)
                {
                    json.Add(t.Name, new JValue(tag.GetByte(t.Name)));
                }
                else if (t is CompoundTag)
                {
                    json.Add(t.Name, NBTJsonSerializer.CompoundTagSerialize((CompoundTag)t));
                }
                else if (t is DoubleTag)
                {
                    json.Add(t.Name, new JValue(tag.GetDouble(t.Name)));
                }
                else if (t is FloatTag)
                {
                    json.Add(t.Name, new JValue(tag.GetFloat(t.Name)));
                }
                else if (t is IntTag)
                {
                    json.Add(t.Name, new JValue(tag.GetInt(t.Name)));
                }
                else if (t is ListTag)
                {
                    json.Add(t.Name, new JArray(NBTJsonSerializer.ListTagSerialize((ListTag)t)));
                }
                else if (t is LongTag)
                {
                    json.Add(t.Name, new JValue(tag.GetLong(t.Name)));
                }
                else if (t is ShortTag)
                {
                    json.Add(t.Name, new JValue(tag.GetShort(t.Name)));
                }
                else if (t is StringTag)
                {
                    json.Add(t.Name, new JValue(tag.GetString(t.Name)));
                }
            }

            return(json);
        }
Exemplo n.º 4
0
        public string GetCustomName()
        {
            CompoundTag tag = this.NamedTag;

            if (!tag.Exist("display"))
            {
                return("");
            }

            CompoundTag display = tag.GetCompound("display");

            if (!display.Exist("Name"))
            {
                return("");
            }
            return(display.GetString("Name"));
        }
Exemplo n.º 5
0
        public Chunk(World world, int x, int z, SubChunk[] chunkDatas = null, byte[] biomes = null,
                     short[] heightMap   = null,
                     ListTag entitiesTag = null, ListTag blockEntitiesTag = null)
        {
            this.World = world;
            this.X     = x;
            this.Z     = z;

            if (biomes != null)
            {
                this.Biomes = biomes;
            }

            if (heightMap != null)
            {
                this.HeightMap = heightMap;
            }

            if (chunkDatas != null)
            {
                this.SubChunks = chunkDatas;
            }

            for (int i = 0; i < entitiesTag?.Count; ++i)
            {
                CompoundTag entity = (CompoundTag)entitiesTag[i];
                this.AddEntity(Entity.CreateEntity(entity.GetString("id"), this, entity));
            }

            for (int i = 0; i < blockEntitiesTag?.Count; ++i)
            {
                CompoundTag blockEntity = (CompoundTag)blockEntitiesTag[i];
                this.AddBlockEntity(BlockEntity.CreateBlockEntity(blockEntity.GetString("id").ToLower(), this,
                                                                  blockEntity));
            }
        }
Exemplo n.º 6
0
        public void Convert()
        {
            for (int i = 0; i < this.BlockEntitiesTag.Length; ++i)
            {
                CompoundTag tag = this.BlockEntitiesTag[i];
                switch (tag.GetString("id"))
                {
                case "minecraft:flower_pot":
                    tag.PutShort("item", (short)Util.GetItemIdFromString(tag.GetString("Item")).Item1);
                    tag.PutInt("mData", tag.GetInt("Data"));

                    tag.Remove("Item");
                    tag.Remove("Data");
                    break;

                case "minecraft:sign":
                    string text1 = tag.GetString("Text1").Remove(0, 9);
                    text1 = text1.Remove(text1.Length - 2, 2);
                    string text2 = tag.GetString("Text2").Remove(0, 9);
                    text2 = text2.Remove(text2.Length - 2, 2);
                    string text3 = tag.GetString("Text3").Remove(0, 9);
                    text3 = text3.Remove(text3.Length - 2, 2);
                    string text4 = tag.GetString("Text4").Remove(0, 9);
                    text4 = text4.Remove(text4.Length - 2, 2);
                    string text = $"{text1}\n{text2}\n{text3}\n{text4}";
                    tag.PutString("Text", text);
                    break;
                }
            }

            for (int i = 0; i < this.SubChunks.Length; ++i)
            {
                if (this.SubChunks[i] == null)
                {
                    continue;
                }
                this.SubChunks[i].Convert();
            }
        }
        private CompoundTag ConvertSection(Tag sectionTag)
        {
            byte[]      blockData = new byte[4096];
            NibbleArray metaData  = new NibbleArray(4096);

            CompoundTag section = (CompoundTag)sectionTag;

            long[]  states  = section.GetLongArray("BlockStates");
            ListTag palette = section.GetList("Palette");
            List <RuntimeTable.Table> indexs = new List <RuntimeTable.Table>();

            foreach (Tag paletteTag in palette.Tags)
            {
                if (paletteTag is CompoundTag)
                {
                    CompoundTag pt   = (CompoundTag)paletteTag;
                    string      name = pt.GetString("Name");
                    indexs.Add(RuntimeTable.GetNameToTable(name, pt.GetCompound("Properties").Tags));
                }
            }

            int         bits      = CheckMostBit(indexs.Count - 1);
            List <byte> fixStates = new List <byte>();

            foreach (long state in states)
            {
                fixStates.AddRange(BitConverter.GetBytes((ulong)state));
            }

            BitArray stateBits = new BitArray(fixStates.ToArray());

            for (int i = 0; i < 4096; i++)
            {
                int  bitOffset = i * bits;
                uint index     = stateBits.Get(bitOffset + bits - 1) ? 1u : 0u;
                for (int j = bits - 2; j >= 0; j--)
                {
                    index <<= 1;
                    index  |= stateBits.Get(bitOffset + j) ? 1u : 0u;
                }

                try
                {
                    RuntimeTable.Table table = indexs[(int)index];
                    blockData[i] = (byte)(table.Id & 0xff);
                    metaData[i]  = (byte)(table.Data & 0xf);
                }
                catch (Exception e)
                {
                    Logger.Info(indexs.Count + " = " + states[0] + " >>> " + states[1]);
                    throw e;
                }
            }

            var newSection = (CompoundTag)section.Clone();

            newSection.Remove("BlockStates");
            newSection.Remove("Palette");

            newSection.PutByteArray("Blocks", blockData);
            newSection.PutByteArray("Data", metaData.ArrayData);

            return(newSection);
        }