public BlockStorage() { _bits = 8; Storage = new FlexibleStorage(_bits, 4096); Pallette = new IntIdentityHashBiMap <BlockState>((1 << _bits)); Pallette.Add(Air); }
public void Read(MinecraftStream ms) { var blockCount = ms.ReadShort(); var bitsPerBlock = (byte)ms.ReadByte(); int palleteLength = 0;// = ms.ReadVarInt(); if (bitsPerBlock <= 4) { bitsPerBlock = 4; } if (bitsPerBlock <= 8) { _bits = bitsPerBlock; palleteLength = ms.ReadVarInt(); Pallette = new IntIdentityHashBiMap(palleteLength); Pallette.Add(Air); for (int id = 0; id < palleteLength; id++) { uint stateId = (uint)ms.ReadVarInt(); BlockState state = BlockFactory.GetBlockState(stateId); Pallette.Put(state, (uint)id); } } else { _bits = (int)Math.Ceiling(Math.Log2(BlockFactory.AllBlockstates.Count)); Pallette = new DirectPallete(); } int length = ms.ReadVarInt(); long[] dataArray = new long[length]; for (int i = 0; i < dataArray.Length; i++) { dataArray[i] = ms.ReadLong(); } Storage = new FlexibleStorage(_bits, 4096); var valueMask = (uint)((1L << _bits) - 1); for (int index = 0; index < 4096; index++) { var state = index / (64 / _bits); var data = dataArray[state]; var shiftedData = data >> (index % (64 / _bits) * _bits); Storage[index] = (uint)(shiftedData & valueMask); } }
public void Read(MinecraftStream ms) { var blockCount = ms.ReadShort(); var bitsPerBlock = (byte)ms.ReadByte(); int palleteLength = 0;// = ms.ReadVarInt(); if (bitsPerBlock <= 4) { bitsPerBlock = 4; } if (bitsPerBlock <= 8) { _bits = bitsPerBlock; palleteLength = ms.ReadVarInt(); Pallette = new IntIdentityHashBiMap <BlockState>(palleteLength); Pallette.Add(Air); //else // palleteLength = for (int id = 0; id < palleteLength; id++) { uint stateId = (uint)ms.ReadVarInt(); BlockState state = BlockFactory.GetBlockState(stateId); Pallette.Put(state, (uint)id); // idToState.Set(id, state); // stateToId.Set(state, id); } } else { _bits = (int)Math.Ceiling(Math.Log2(BlockFactory.AllBlockstates.Count)); Pallette = new DirectPallete(); } int length = ms.ReadVarInt(); long[] dataArray = new long[length]; for (int i = 0; i < dataArray.Length; i++) { dataArray[i] = ms.ReadLong(); } Storage = new FlexibleStorage(_bits, dataArray); //Storage._data = dataArray; }