private void DestroyBlock(Vector4 pos) { PositionBlock posBlock = PositionBlock.FromVector(pos); Block block = Block.FromId(World.Instance.GetBlock(posBlock)); block.OnDestroy(posBlock); World.Instance.SetBlock(posBlock, 0); PositionChunk posChunk = PositionChunk.CreateFrom(posBlock); Chunk chunk = World.Instance.GetChunk(posChunk); chunk.InvalidateMeAndNeighbors(); }
private void UseBlockOnBlock() { Vector4 pos = World.Instance.PlayerVoxelTrace.BuildPosition; PositionBlock posBlock = new PositionBlock((int)pos.X, (int)pos.Y, (int)pos.Z); World.Instance.SetBlock(posBlock, SelectedStack.Id); PositionChunk posChunk = PositionChunk.CreateFrom(posBlock); Chunk chunk = World.Instance.GetChunk(posChunk); chunk.InvalidateMeAndNeighbors(); SelectedStack.Remove(1); NeedsRest(); }
private void UseItemOnBlock() { // used on a block! Vector4 pos = World.Instance.PlayerVoxelTrace.ImpactPosition; PositionBlock posBlock = new PositionBlock((int)pos.X, (int)pos.Y, (int)pos.Z); Item item = Item.FromId(SelectedStack.Id); if (item.OnUseOnBlock(posBlock)) { // here if world is changed PositionChunk posChunk = PositionChunk.CreateFrom(posBlock); Chunk chunk = World.Instance.GetChunk(posChunk); chunk.InvalidateMeAndNeighbors(); if (item.Consumable) { SelectedStack.Remove(1); } } }
private void CollectNearbyEntities() { if (throwStackDelay > 0) { throwStackDelay--; return; } AxisAlignedBoundingBox collectArea = AABB; collectArea.Translate(Position); float radius = 0.5f; collectArea.Min -= new Vector3(radius, radius, radius); collectArea.Max += new Vector3(radius, radius, radius); collectArea.CapToWorldBounds(); PositionChunk minChunk = PositionChunk.CreateFrom(collectArea.Min); PositionChunk maxChunk = PositionChunk.CreateFrom(collectArea.Max); PositionChunk chunkPos; for (int x = minChunk.X; x <= maxChunk.X; x++) { for (int y = minChunk.Y; y <= maxChunk.Y; y++) { for (int z = minChunk.Z; z <= maxChunk.Z; z++) { chunkPos = new PositionChunk(x, y, z); Chunk chunk = World.Instance.GetChunk(chunkPos); foreach (EntityStack stack in chunk.EntitiesInArea(collectArea)) { // transfer items Inventory.CollectStack(stack); // if stack is empty remove it if (stack.IsEmpty) { chunk.RemoveEntity(stack); } } } } } }