public IPacketWithSize ReadPacket(IProtocolDataReader reader) { Coordinates = Position.FromReaderShort(reader); Mode = (SetBlockMode)reader.ReadByte(); BlockType = reader.ReadByte(); return(this); }
public IPacketWithSize ReadPacket(IMinecraftDataReader reader) { Coordinates = Position.FromReaderShort(reader); Mode = (SetBlockMode) reader.ReadByte(); BlockType = reader.ReadByte(); return this; }
public static string GetSetBlockModeString(SetBlockMode mode) { switch (mode) { case SetBlockMode.Destroy: return("destroy"); case SetBlockMode.Keep: return("keep"); default: return("replace"); } }
public SetBlockCommand(Position position, string id, SetBlockMode mode = SetBlockMode.Replace) { this.str = $"setblock {position} {id} {Util.GetSetBlockModeString(mode)}"; }
public void SetBlocks (int x, int y, int z, byte type=0, int extend=0, bool spherify=false, SetBlockMode mode=SetBlockMode.none) //x,y,z are center, extend is half size (radius) { //registering undo if (recordUndo && mode != SetBlockMode.none) { undoSteps.Add( data.GetColumnMatrix(x-extend, z-extend, extend*2+1, extend*2+1) ); //Debug.Log(undoSteps[undoSteps.Count-1].array.Length); if (undoSteps.Count > 32) { undoSteps.RemoveAt(0); undoSteps.RemoveAt(0); } //removing two steps...just to be sure } //starting timer #if UNITY_EDITOR timerSinceSetBlock.Reset(); timerSinceSetBlock.Start(); #endif //setting if (mode == SetBlockMode.standard || mode == SetBlockMode.replace) { //dconstructor //if (types[type].constructor != null) Scaffolding.Add(x,y,z); //else Scaffolding.Remove(x,y,z); for (int xi = x-extend; xi<= x+extend; xi++) for (int yi = y-extend; yi<= y+extend; yi++) for (int zi = z-extend; zi<= z+extend; zi++) { if (spherify && Mathf.Abs(Mathf.Pow(xi-x,2)) + Mathf.Abs(Mathf.Pow(yi-y,2)) + Mathf.Abs(Mathf.Pow(zi-z,2)) - 1 > extend*extend) continue; if (mode==SetBlockMode.replace && !types[ data.GetBlock(xi,yi,zi) ].filledTerrain) continue; if(yi > 2) data.SetBlock(xi, yi, zi, type); } } //blurring if (mode == SetBlockMode.blur) { bool[] refExist = new bool[types.Length]; for (int i=0; i<types.Length; i++) refExist[i] = types[i].filledTerrain; data.Blur(x,y,z, extend, spherify, refExist); } //mark areas as 'saved' for (int xi = x-extend; xi<= x+extend; xi++) for (int zi = z-extend; zi<= z+extend; zi++) data.areas[ data.GetAreaNum(xi,zi) ].save = true; //resetting progress //ambient for (int cx = Mathf.FloorToInt(1f*(x-extend-ambientMargins)/chunkSize); cx <= Mathf.FloorToInt(1f*(x+extend+ambientMargins)/chunkSize); cx++) for (int cz = Mathf.FloorToInt(1f*(z-extend-ambientMargins)/chunkSize); cz <= Mathf.FloorToInt(1f*(z+extend+ambientMargins)/chunkSize); cz++) { if (!chunks.CheckInRange(cx,cz)) continue; Chunk chunk = chunks[cx,cz]; if (chunk!=null) chunk.stage = Chunk.Stage.forceAmbient; } //terrain for (int cx = Mathf.FloorToInt(1f*(x-extend-terrainMargins)/chunkSize); cx <= Mathf.FloorToInt(1f*(x+extend+terrainMargins)/chunkSize); cx++) for (int cz = Mathf.FloorToInt(1f*(z-extend-terrainMargins)/chunkSize); cz <= Mathf.FloorToInt(1f*(z+extend+terrainMargins)/chunkSize); cz++) { if (!chunks.CheckInRange(cx,cz)) continue; Chunk chunk = chunks[cx,cz]; if (chunk!=null) chunk.stage = Chunk.Stage.forceAll; //and then calculating grass, prefabs, etc. Just because grass should change with land geometry } }