private float[] GetScaledNoise(PositionBlock pos, float scale, int offset = 0) { pos.X += offset; pos.Z += offset; float x = pos.X * scale; float y = pos.Y * scale; float z = pos.Z * scale; float x2 = (pos.X + 16f) * scale; float y2 = (pos.Y + 16f) * scale; float z2 = (pos.Z + 16f) * scale; float[] noise = new float[] { Noise.Generate(x, y, z2), Noise.Generate(x, y, z), Noise.Generate(x2, y, z), Noise.Generate(x2, y, z2), Noise.Generate(x, y2, z2), Noise.Generate(x, y2, z), Noise.Generate(x2, y2, z), Noise.Generate(x2, y2, z2), }; return(noise); }
internal override bool OnActivate(PositionBlock position) { Furnace furnace = (Furnace)World.Instance.GetBlockEntity(position); TheGame.Instance.OpenGui(new GuiFurnaceForm(furnace)); return(true); }
internal void RenderBlock(PositionBlock positionBlock, Chunk chunk) { int blockId = chunk.SafeGetLocalBlock(positionBlock.X, positionBlock.Y, positionBlock.Z); if (blockId == 0) { return; } PositionBlock globalPosition; chunk.Position.GetGlobalPositionBlock(out globalPosition, positionBlock.X, positionBlock.Y, positionBlock.Z); Block block = BlockRepository.Blocks[blockId]; if (block.Id == BlockRepository.TallGrass.Id) { RenderCross(block, globalPosition, positionBlock, chunk); } else if (block.Id == BlockRepository.Wheat.Id) { RenderHash(block, globalPosition, positionBlock, chunk); } else if (block.Id == BlockRepository.Water.Id) { RenderWater(block, globalPosition, positionBlock, chunk); } else { RenderCube(block, globalPosition, positionBlock, chunk, 1f); } }
protected virtual void Dispose(bool disposing) { if (disposing && _positionBlock != null) { _nativeOperator.Close(_positionBlock); _positionBlock = null; } }
internal void SetBlock(PositionBlock pos, int blockId) { PositionChunk positionChunk = PositionChunk.CreateFrom(pos); Chunk chunk = GetChunk(positionChunk); positionChunk.ConvertToLocalPosition(ref pos); chunk.SetLocalBlock(pos.X, pos.Y, pos.Z, blockId); }
public override bool OnUseOnBlock(PositionBlock pos) { int sourceBlockId = World.Instance.GetBlock(pos); if (sourceBlockId != BlockRepository.FarmlandDry.Id && sourceBlockId != BlockRepository.FarmlandWet.Id) return false; World.Instance.SetBlock(pos.X, pos.Y+1, pos.Z, BlockRepository.Wheat.Id); return true; }
internal bool ReplaceBlock(PositionBlock pos, int oldId, int newId) { if (GetBlock(pos) == oldId) { SetBlock(pos, newId); return(true); } return(false); }
public override bool OnUseOnBlock(PositionBlock pos) { int sourceBlockId = World.Instance.GetBlock(pos); if (sourceBlockId == BlockRepository.DirtWithGrass.Id || sourceBlockId == BlockRepository.Dirt.Id) { World.Instance.SetBlock(pos, BlockRepository.FarmlandDry.Id); } return(true); }
private float WaterLevel(Chunk chunk, PositionBlock positionBlock, int offsetX, int offsetY, int offsetZ) { Water water = chunk.GetBlockEntityFromPosition(new PositionBlock(positionBlock.X + offsetX, positionBlock.Y + offsetY, positionBlock.Z + offsetZ)) as Water; float thisLevel = water == null ? 0 : water.GetWaterLevel(); water = chunk.GetBlockEntityFromPosition(new PositionBlock(positionBlock.X + offsetX, positionBlock.Y + offsetY + 1, positionBlock.Z + offsetZ)) as Water; float topLevel = water == null ? 0 : 1; return(Math.Max(thisLevel, topLevel)); }
internal override void OnDestroy(PositionBlock pos) { // drop furnace content Furnace furnace = (Furnace)World.Instance.GetBlockEntity(pos); DropStack(furnace.Product.Content, pos); DropStack(furnace.Input.Content, pos); DropStack(furnace.Fuel.Content, pos); base.OnDestroy(pos); }
internal Entity GetBlockEntity(PositionBlock position) { PositionChunk positionChunk = PositionChunk.CreateFrom(position); Chunk chunk = GetChunk(positionChunk); positionChunk.ConvertToLocalPosition(ref position); Entity entity = chunk.GetBlockEntity(position); return(entity); }
public override bool OnUseOnBlock(PositionBlock pos) { int sourceBlockId = World.Instance.GetBlock(pos); if (sourceBlockId != BlockRepository.FarmlandDry.Id && sourceBlockId != BlockRepository.FarmlandWet.Id) { return(false); } World.Instance.SetBlock(pos.X, pos.Y + 1, pos.Z, BlockRepository.Wheat.Id); return(true); }
internal virtual void OnDestroy(PositionBlock pos) { int[] droppedIds = OnDroppedIds(); if (droppedIds.Length > 0) { foreach (int id in droppedIds) { EntityStack stack = new EntityStack(id, 1); DropStack(stack, pos); } } }
internal void UpdateBlock(Chunk chunk, PositionBlock pos) { Entity entity = this.CreateEntity(); if (entity != null) { entity.Parent = chunk; entity.BlockPosition = pos; entity.OnUpdate(); } }
internal override void OnDestroy(PositionBlock pos) { Chunk chunk = World.Instance.GetChunk(PositionChunk.CreateFrom(pos)); PositionBlock localpos = pos; chunk.Position.ConvertToLocalPosition(ref localpos); float stage = (float)chunk.GetBlockMetaData(localpos, "stage"); if (stage != 1f) { DropStack(new EntityStack(ItemRepository.SeedsWheat.Id, 1), pos); return; } base.OnDestroy(pos); }
public void Open(Path path = null) { var filePath = Path.Merge(path, this.Path).GetFilePath(); _positionBlock = _nativeOperator.Open(filePath, this.OwnerName ?? this.RecordInfo.OwnerName, this.OpenMode ?? this.RecordInfo.OpenMode); if (this.Stat == null) { this.Stat = _nativeOperator.Stat(_positionBlock, this.TemporaryBuffer); if (this.RecordInfo.FixedLength != this.Stat.FileSpec.RecordLength || this.RecordInfo.VariableOption != this.Stat.FileSpec.VariableOption) { throw new InvalidDefinitionException(); } } }
public void Close() { if (IsClosable) { if (_positionBlock != null) { _nativeOperator.Close(_positionBlock); _positionBlock = null; } } else { throw new InvalidOperationException(); } }
internal object GetBlockMetaData(PositionBlock pos, string variable) { if (pos.Y < 0) { return(null); } if (pos.Y >= Chunk.MaxSizeY) { return(null); } PositionChunk positionChunk = PositionChunk.CreateFrom(pos); Chunk chunk = GetChunk(positionChunk); positionChunk.ConvertToLocalPosition(ref pos); return(chunk.GetBlockMetaData(pos, variable)); }
internal void SetBlockMetaData(PositionBlock pos, string variable, object value) { if (pos.Y < 0) { return; } if (pos.Y >= Chunk.MaxSizeY) { return; } PositionChunk positionChunk = PositionChunk.CreateFrom(pos); Chunk chunk = GetChunk(positionChunk); positionChunk.ConvertToLocalPosition(ref pos); chunk.SetBlockMetaData(pos, variable, value); }
internal Entity GetBlockEntityFromPosition(PositionBlock pos) { if (pos.Y < 0) { return(null); } if (pos.Y >= Chunk.MaxSizeY) { return(null); } PositionChunk positionChunk = PositionChunk.CreateFrom(pos); Chunk chunk = GetChunk(positionChunk); positionChunk.ConvertToLocalPosition(ref pos); return(chunk.GetBlockEntityFromPosition(pos)); }
internal OperationResult( Operation operationType, PositionBlock positionBlock, byte[] dataBuffer, int dataBufferLength, byte[] keyBuffer, sbyte keyNumber, ClientId clientId) { this.OperationType = operationType; this.PositionBlock = positionBlock; this.DataBuffer = dataBuffer; this.DataBufferLength = dataBufferLength; this.KeyBuffer = keyBuffer; this.KeyNumber = keyNumber; this.ClientId = clientId; }
internal int GetBlock(PositionBlock pos) { if (pos.Y < 0) { return(0); } if (pos.Y >= Chunk.MaxSizeY) { return(0); } PositionChunk positionChunk = PositionChunk.CreateFrom(pos); Chunk chunk = GetChunk(positionChunk); positionChunk.ConvertToLocalPosition(ref pos); int blockId = chunk.GetLocalBlock(pos.X, pos.Y, pos.Z); return(blockId); }
public void Update(Vector3 point, Vector3 direction) { var voxels = TraceLine(point, direction); Hit = false; for (int i = 1; i < voxels.Count; i++) { var v = voxels[i]; int impactBlockId = World.Instance.GetBlock(PositionBlock.FromVector(v)); ImpactBlock = Block.FromId(impactBlockId); if (impactBlockId != 0 && impactBlockId != BlockRepository.Water.Id) { ImpactPosition = voxels[i]; BuildPosition = voxels[i - 1]; Hit = true; return; } } }
private void RenderCross(Block block, PositionBlock globalPosition, PositionBlock positionBlock, Chunk chunk) { Vector4 c1, c2, c3, c4, c5, c6; int blockId = block.Id; Vector4[] blockColors = block.BlockColors; c1 = blockColors[0]; c2 = blockColors[1]; c3 = blockColors[2]; c4 = blockColors[3]; c5 = blockColors[4]; c6 = blockColors[5]; float vx = globalPosition.X; float vy = globalPosition.Y; float vz = globalPosition.Z; int x = positionBlock.X; int y = positionBlock.Y; int z = positionBlock.Z; t.ArrayIndex = TileTextures.Instance.FrontIndex(blockId); Vector3 normal = new Vector3(-0.7f, 0, 0.7f); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 0f, vz + 0.0f, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 1f, vz + 0.0f, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 1f, vz + 1f, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 0f, vz + 1f, 1.0f), c1, normal); normal = new Vector3(0.7f, 0, -0.7f); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 0f, vz + 1f, 1.0f), c2, normal); t.AddVertexWithColor(new Vector4(vx + 1, vy + 1f, vz + 1f, 1.0f), c2, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 1f, vz + 0f, 1.0f), c2, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 0f, vz + 0f, 1.0f), c2, normal); normal = new Vector3(0.7f, 0, 0.7f); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 0f, vz + 1f, 1.0f), c3, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 1f, vz + 1f, 1.0f), c3, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 1f, vz + 0f, 1.0f), c3, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 0f, vz + 0f, 1.0f), c3, normal); normal = new Vector3(-0.7f, 0, -0.7f); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 0f, vz + 0f, 1.0f), c4, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 1f, vz + 0f, 1.0f), c4, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 1f, vz + 1f, 1.0f), c4, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 0f, vz + 1f, 1.0f), c4, normal); t.ArrayIndex = -1; }
private String MakePositionString(position firstBlockPos, position lastBlockPos, int[,] matrix) { String outputStr; position tempPos; PositionBlock positionBlock = new PositionBlock(firstBlockPos, lastBlockPos); outputStr = firstBlockPos.GetPositionString() + ":" + lastBlockPos.GetPositionString(); for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLUMNS; j++) { if (matrix[i, j] > -1) { tempPos = new position(i, j); if (!positionBlock.IsInside(tempPos)) { outputStr = outputStr + "," + tempPos.GetPositionString(); } } } } return(outputStr); }
internal override void Generate(Chunk chunk) { this.chunk = chunk; PositionBlock pos; chunk.Position.GetGlobalPositionBlock(out pos, 0, 0, 0); noise3D = GetScaledNoise(pos, 0.04f); PositionBlock pos2 = pos; pos2.Y = 0; noise2D = GetScaledNoise(pos2, 0.01f); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < 16; y++) { float height = pos.Y + y; if (height == 0) { chunk.SetLocalBlock(x, y, z, BlockRepository.BedRock.Id); } else if (height <= 60) { chunk.SetLocalBlock(x, y, z, BlockRepository.Stone.Id); } else if (height <= 80) { float limit = CalcOffset(height, 60, 80) * 2f - 1f; Magic(height, x, y, z, BlockRepository.Stone.Id, limit); } } } } }
internal virtual bool OnActivate(PositionBlock position) { return(false); }
internal int GetBlock(int x, int y, int z) { PositionBlock pos = new PositionBlock(x, y, z); return(GetBlock(pos)); }
internal override void OnDestroy(PositionBlock pos) { }
private void RenderWater(Block block, PositionBlock globalPosition, PositionBlock positionBlock, Chunk chunk) { Vector4 c1, c2, c3, c4, c5, c6; int blockId = block.Id; float vx = globalPosition.X; float vy = globalPosition.Y; float vz = globalPosition.Z; int x = positionBlock.X; int y = positionBlock.Y; int z = positionBlock.Z; // front float height0 = WaterLevel(chunk, positionBlock, -1, 0, -1); float height1 = WaterLevel(chunk, positionBlock, 0, 0, -1); float height2 = WaterLevel(chunk, positionBlock, 1, 0, -1); float height3 = WaterLevel(chunk, positionBlock, -1, 0, 0); float height4 = WaterLevel(chunk, positionBlock, 0, 0, 0); float height5 = WaterLevel(chunk, positionBlock, 1, 0, 0); float height6 = WaterLevel(chunk, positionBlock, -1, 0, 1); float height7 = WaterLevel(chunk, positionBlock, 0, 0, 1); float height8 = WaterLevel(chunk, positionBlock, 1, 0, 1); float height10 = WaterLevel(chunk, positionBlock, -1, 1, -1); float height11 = WaterLevel(chunk, positionBlock, 0, 1, -1); float height12 = WaterLevel(chunk, positionBlock, 1, 1, -1); float height13 = WaterLevel(chunk, positionBlock, -1, 1, 0); float height14 = WaterLevel(chunk, positionBlock, 0, 1, 0); float height15 = WaterLevel(chunk, positionBlock, 1, 1, 0); float height16 = WaterLevel(chunk, positionBlock, -1, 1, 1); float height17 = WaterLevel(chunk, positionBlock, 0, 1, 1); float height18 = WaterLevel(chunk, positionBlock, 1, 1, 1); float h1 = WaterAvg(height3, height4, height6, height7); float h2 = WaterAvg(height0, height1, height3, height4); float h3 = WaterAvg(height1, height2, height4, height5); float h4 = WaterAvg(height4, height5, height7, height8); if (height13 + height14 + height16 + height17 > 0) { h1 = 1f; } if (height10 + height11 + height13 + height14 > 0) { h2 = 1f; } if (height11 + height12 + height14 + height15 > 0) { h3 = 1f; } if (height14 + height15 + height17 + height18 > 0) { h4 = 1f; } Water water = chunk.GetBlockEntityFromPosition(new PositionBlock(positionBlock.X, positionBlock.Y, positionBlock.Z)) as Water; bool waterMainSource = water == null ? false : water.GetWaterLevel() == 1f; Vector4[] blockColors = block.BlockColors; if (waterMainSource) { Vector4 newcol = new Vector4(0.2f, 0.2f, 0.2f, 1f); blockColors = new Vector4[] { newcol, newcol, newcol, newcol, newcol, newcol }; } c1 = blockColors[0]; c2 = blockColors[1]; c3 = blockColors[2]; c4 = blockColors[3]; c5 = blockColors[4]; c6 = blockColors[5]; bool renderFront = block.FaceVisibleByNeighbor(chunk.SafeGetLocalBlock(x, y, z + 1)); bool renderBack = block.FaceVisibleByNeighbor(chunk.SafeGetLocalBlock(x, y, z - 1)); bool renderLeft = block.FaceVisibleByNeighbor(chunk.SafeGetLocalBlock(x - 1, y, z)); bool renderRight = block.FaceVisibleByNeighbor(chunk.SafeGetLocalBlock(x + 1, y, z)); bool renderTop = block.FaceVisibleByNeighbor(chunk.SafeGetLocalBlock(x, y + 1, z)); bool renderBottom = block.FaceVisibleByNeighbor(chunk.SafeGetLocalBlock(x, y - 1, z)); Vector3 normal; if (renderFront) { t.ArrayIndex = TileTextures.Instance.FrontIndex(blockId); normal = new Vector3(0, 0, 1); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 0f, vz + 1f, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + h1, vz + 1f, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + h4, vz + 1f, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 0f, vz + 1f, 1.0f), c1, normal); } if (renderBack) { // back t.ArrayIndex = TileTextures.Instance.SideIndex(blockId); normal = new Vector3(0, 0, -1); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 0f, vz + 0f, 1.0f), c2, normal); t.AddVertexWithColor(new Vector4(vx + 1, vy + h3, vz + 0f, 1.0f), c2, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + h2, vz + 0f, 1.0f), c2, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 0f, vz + 0f, 1.0f), c2, normal); } if (renderLeft) { //left t.ArrayIndex = TileTextures.Instance.SideIndex(blockId); normal = new Vector3(-1, 0, 0); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 0f, vz + 0f, 1.0f), c3, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + h2, vz + 0f, 1.0f), c3, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + h1, vz + 1f, 1.0f), c3, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 0f, vz + 1f, 1.0f), c3, normal); } if (renderRight) { //right t.ArrayIndex = TileTextures.Instance.SideIndex(blockId); normal = new Vector3(1, 0, 0); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 0f, vz + 1f, 1.0f), c4, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + h4, vz + 1f, 1.0f), c4, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + h3, vz + 0f, 1.0f), c4, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 0f, vz + 0f, 1.0f), c4, normal); } if (renderTop) { //top t.ArrayIndex = TileTextures.Instance.TopIndex(blockId); normal = new Vector3(0, 1, 0); t.AddVertexWithColor(new Vector4(vx + 0f, vy + h1, vz + 1f, 1.0f), c5, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + h2, vz + 0f, 1.0f), c5, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + h3, vz + 0f, 1.0f), c5, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + h4, vz + 1f, 1.0f), c5, normal); } if (renderBottom) { //bottom t.ArrayIndex = TileTextures.Instance.BottomIndex(blockId); normal = new Vector3(0, -1, 0); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 0f, vz + 0f, 1.0f), c6, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 0f, vz + 1f, 1.0f), c6, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 0f, vz + 1f, 1.0f), c6, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 0f, vz + 0f, 1.0f), c6, normal); } t.ArrayIndex = -1; }
// // events / default behaviour // public virtual bool OnUseOnBlock(PositionBlock pos) { return false; }
private void RenderHash(Block block, PositionBlock globalPosition, PositionBlock positionBlock, Chunk chunk) { Vector4 c1, c2, c3, c4, c5, c6; int blockId = block.Id; Vector4[] blockColors = block.BlockColors; c1 = blockColors[0]; c2 = blockColors[1]; c3 = blockColors[2]; c4 = blockColors[3]; c5 = blockColors[4]; c6 = blockColors[5]; float vx = globalPosition.X; float vy = globalPosition.Y; float vz = globalPosition.Z; int x = positionBlock.X; int y = positionBlock.Y; int z = positionBlock.Z; if (block.HasStages) { int stage = (int)((float)chunk.GetBlockMetaData(positionBlock, "stage") * block.MaxStage); t.ArrayIndex = TileTextures.Instance.GetStage(blockId, stage); } else { t.ArrayIndex = TileTextures.Instance.FrontIndex(blockId); } float margin = 0.2f; Vector3 normal = new Vector3(0, 0, 1); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 0f, vz + 1f - margin, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 1f, vz + 1f - margin, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 1f, vz + 1f - margin, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 0f, vz + 1f - margin, 1.0f), c1, normal); normal = new Vector3(0, 0, 1); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 0f, vz + 0f + margin, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 1f, vz + 0f + margin, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 1f, vz + 0f + margin, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 0f, vz + 0f + margin, 1.0f), c1, normal); normal = new Vector3(0, 0, -1); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 0f, vz + 1f - margin, 1.0f), c2, normal); t.AddVertexWithColor(new Vector4(vx + 1, vy + 1f, vz + 1f - margin, 1.0f), c2, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 1f, vz + 1f - margin, 1.0f), c2, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 0f, vz + 1f - margin, 1.0f), c2, normal); normal = new Vector3(0, 0, -1); t.AddVertexWithColor(new Vector4(vx + 1f, vy + 0f, vz + 0f + margin, 1.0f), c2, normal); t.AddVertexWithColor(new Vector4(vx + 1, vy + 1f, vz + 0f + margin, 1.0f), c2, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 1f, vz + 0f + margin, 1.0f), c2, normal); t.AddVertexWithColor(new Vector4(vx + 0f, vy + 0f, vz + 0f + margin, 1.0f), c2, normal); normal = new Vector3(-1, 0, 0); t.AddVertexWithColor(new Vector4(vx + margin, vy + 0f, vz + 0f, 1.0f), c3, normal); t.AddVertexWithColor(new Vector4(vx + margin, vy + 1f, vz + 0f, 1.0f), c3, normal); t.AddVertexWithColor(new Vector4(vx + margin, vy + 1f, vz + 1f, 1.0f), c3, normal); t.AddVertexWithColor(new Vector4(vx + margin, vy + 0f, vz + 1f, 1.0f), c3, normal); normal = new Vector3(-1, 0, 0); t.AddVertexWithColor(new Vector4(vx + 1f - margin, vy + 0f, vz + 0f, 1.0f), c3, normal); t.AddVertexWithColor(new Vector4(vx + 1f - margin, vy + 1f, vz + 0f, 1.0f), c3, normal); t.AddVertexWithColor(new Vector4(vx + 1f - margin, vy + 1f, vz + 1f, 1.0f), c3, normal); t.AddVertexWithColor(new Vector4(vx + 1f - margin, vy + 0f, vz + 1f, 1.0f), c3, normal); normal = new Vector3(1, 0, 0); t.AddVertexWithColor(new Vector4(vx + margin, vy + 0f, vz + 1f, 1.0f), c4, normal); t.AddVertexWithColor(new Vector4(vx + margin, vy + 1f, vz + 1f, 1.0f), c4, normal); t.AddVertexWithColor(new Vector4(vx + margin, vy + 1f, vz + 0f, 1.0f), c4, normal); t.AddVertexWithColor(new Vector4(vx + margin, vy + 0f, vz + 0f, 1.0f), c4, normal); normal = new Vector3(1, 0, 0); t.AddVertexWithColor(new Vector4(vx + 1f - margin, vy + 0f, vz + 1f, 1.0f), c4, normal); t.AddVertexWithColor(new Vector4(vx + 1f - margin, vy + 1f, vz + 1f, 1.0f), c4, normal); t.AddVertexWithColor(new Vector4(vx + 1f - margin, vy + 1f, vz + 0f, 1.0f), c4, normal); t.AddVertexWithColor(new Vector4(vx + 1f - margin, vy + 0f, vz + 0f, 1.0f), c4, normal); t.ArrayIndex = -1; }
internal void SetBlock(int x, int y, int z, int blockId) { PositionBlock pos = new PositionBlock(x, y, z); SetBlock(pos, blockId); }
internal override bool OnActivate(PositionBlock position) { Furnace furnace = (Furnace)World.Instance.GetBlockEntity(position); TheGame.Instance.OpenGui(new GuiFurnaceForm(furnace)); return true; }
internal virtual bool OnActivate(PositionBlock position) { return false; }
internal bool Render(bool forceCachedRendering) { // check if this is inside frustum RenewLease(); bool rebuildOccured = false; if ((pass1VertexBuffer.Disposed || chunk.IsDirty) && !forceCachedRendering) { // pass1 VertexBuffer.Dispose(ref pass1VertexBuffer); VertexBuffer.Dispose(ref pass2VertexBuffer); chunk.IsDirty = true; // rebuild vertices for cunk BlockRenderer blockRenderer = new BlockRenderer(); PositionBlock startCorner; chunk.Position.GetMinCornerBlock(out startCorner); int minX = startCorner.X; int minY = startCorner.Y; int minZ = startCorner.Z; int maxX = startCorner.X + 16; int maxY = startCorner.Y + 16; int maxZ = startCorner.Z + 16; PositionBlock blockPos = new PositionBlock(0, 0, 0); List <PositionBlock> pass2Blocks = new List <PositionBlock>(); t.StartDrawingTiledQuads(); for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { blockPos.X = x; blockPos.Y = y; blockPos.Z = z; Block block = Block.FromId(chunk.SafeGetLocalBlock(x, y, z)); if (!block.IsTransparent) { blockRenderer.RenderBlock(blockPos, chunk); } else if (block.Id != BlockRepository.Air.Id) { pass2Blocks.Add(blockPos); } } } } pass1VertexBuffer = t.GetVertexBuffer(); // generate vertex buffer for pass2 t.StartDrawingTiledQuadsPass2(); foreach (PositionBlock pass2BlockPos in pass2Blocks) { blockRenderer.RenderBlock(pass2BlockPos, chunk); } pass2VertexBuffer = t.GetVertexBuffer(); chunk.IsDirty = false; rebuildOccured = true; } // draw chunk if drawbuffer has been calculated t.ResetTransformation(); if (pass1VertexBuffer.Vertices != null) { t.StartDrawingTiledQuads(); t.Draw(pass1VertexBuffer); } // draw entities in chunk foreach (EntityStack stack in chunk.StackEntities) { int entitiesToDraw = stack.Count > 2 ? 2 : stack.Count; if (stack.AsBlock != null) { t.Translate = stack.Position; t.Scale = new Vector3(0.5f, 0.5f, 0.5f); t.Rotate = new Vector3(stack.Pitch, stack.Yaw, 0); for (int i = 0; i < entitiesToDraw; i++) { t.StartDrawingTiledQuads(); t.Draw(TileTextures.Instance.GetBlockVertexBuffer(stack.Id)); t.Translate += new Vector3(0.05f, 0.05f, 0.05f); } } else if (stack.AsItem != null) { t.Translate = stack.Position; t.Scale = new Vector3(0.5f, 0.5f, 0.5f); for (int i = 0; i < entitiesToDraw; i++) { Player p = World.Instance.Player; t.Rotate = new Vector3(-p.Pitch, p.Yaw + (float)Math.PI, 0); t.StartDrawingTiledQuadsPass2(); t.Draw(TileTextures.Instance.GetItemVertexBuffer(stack.Id)); t.Translate += new Vector3(0.2f, 0.2f, 0.2f); } } } return(rebuildOccured); }
internal override bool OnActivate(PositionBlock position) { TheGame.Instance.OpenGui(new GuiCraftingForm()); return true; }