コード例 #1
0
ファイル: NetworkUtils.cs プロジェクト: lvyitian1/Alex
 /// <inheritdoc />
 public override void FromStream(BinaryReader reader)
 {
     Nbt = NetworkUtils.ReadNbt(reader.BaseStream, true);
 }
コード例 #2
0
ファイル: StartGame.cs プロジェクト: lvyitian1/Alex
		public BlockPalette ReadAlternateBlockPalette()
		{
			var  result = new BlockPalette();
			uint count  = ReadUnsignedVarInt();
			
			//Log.Info($"Block count startgame: {count}");
			for (int runtimeId = 0; runtimeId < count; runtimeId++)
			{
				var record = new BlockStateContainer();
				record.RuntimeId = runtimeId;
				record.Id = record.RuntimeId;
				record.Name = ReadString();
				record.States = new List<IBlockState>();
				
				
				var nbt     = NetworkUtils.ReadNewNbt(_reader);
				var rootTag = nbt.NbtFile.RootTag;

				if (rootTag is NbtList nbtList)
				{
					foreach (NbtTag tag in nbtList)
					{
						var s = tag["states"];

						if (s is NbtCompound compound)
						{
							foreach (NbtTag stateTag in compound)
							{
								IBlockState state = null;

								switch (stateTag.TagType)
								{
									case NbtTagType.Byte:
										state = new BlockStateByte() {Name = stateTag.Name, Value = stateTag.ByteValue};

										break;

									case NbtTagType.Int:
										state = new BlockStateInt() {Name = stateTag.Name, Value = stateTag.IntValue};

										break;

									case NbtTagType.String:
										state = new BlockStateString()
										{
											Name = stateTag.Name, Value = stateTag.StringValue
										};

										break;

									default:
										throw new ArgumentOutOfRangeException();
								}

								record.States.Add(state);
							}
						}
						else if (s is NbtList list)
						{
							foreach (NbtTag stateTag in list)
							{
								IBlockState state = null;

								switch (stateTag.TagType)
								{
									case NbtTagType.Byte:
										state = new BlockStateByte() {Name = stateTag.Name, Value = stateTag.ByteValue};

										break;

									case NbtTagType.Int:
										state = new BlockStateInt() {Name = stateTag.Name, Value = stateTag.IntValue};

										break;

									case NbtTagType.String:
										state = new BlockStateString()
										{
											Name = stateTag.Name, Value = stateTag.StringValue
										};

										break;

									default:
										throw new ArgumentOutOfRangeException();
								}

								record.States.Add(state);
							}
						}

						result.Add(record);
					}
				}
				else if (rootTag is NbtCompound c)
				{
					foreach (NbtTag tag in c)
					{
						var s = tag["states"];

						if (s is NbtCompound compound)
						{
							foreach (NbtTag stateTag in compound)
							{
								IBlockState state = null;
								switch (stateTag.TagType)
								{
									case NbtTagType.Byte:
										state = new BlockStateByte()
										{
											Name = stateTag.Name,
											Value = stateTag.ByteValue
										};
										break;
									case NbtTagType.Int:
										state = new BlockStateInt()
										{
											Name = stateTag.Name,
											Value = stateTag.IntValue
										};
										break;
									case NbtTagType.String:
										state = new BlockStateString()
										{
											Name = stateTag.Name,
											Value = stateTag.StringValue
										};
										break;
									default:
										throw new ArgumentOutOfRangeException();
								}
								record.States.Add(state);
							}
						}
						else if (s is NbtList list)
						{
							foreach (NbtTag stateTag in list)
							{
								IBlockState state = null;
								switch (stateTag.TagType)
								{
									case NbtTagType.Byte:
										state = new BlockStateByte()
										{
											Name = stateTag.Name,
											Value = stateTag.ByteValue
										};
										break;
									case NbtTagType.Int:
										state = new BlockStateInt()
										{
											Name = stateTag.Name,
											Value = stateTag.IntValue
										};
										break;
									case NbtTagType.String:
										state = new BlockStateString()
										{
											Name = stateTag.Name,
											Value = stateTag.StringValue
										};
										break;
									default:
										throw new ArgumentOutOfRangeException();
								}
								record.States.Add(state);
							}
						}

						result.Add(record);
					}
				}
			}
			return result;
		}