public GuiBlockElement(string name, Vector2 position, Vector3 size, BlockSnapshot snapshot, AspectRatioMode aspectRatioMode) { _name = name; _position = position; _size = size; _snapshot = snapshot; _aspectRatioMode = aspectRatioMode; _textureIndices = new int[6]; RefreshTextures(); GenerateMatrix(); }
private BlockSnapshot UpdateSnapshot(BlockSnapshot snapshot, Vector3i position, World2dRegion region) { if (!(snapshot is IGrass grass)) { return(snapshot); } var pos2d = new Vector2i(position.X, position.Z); var relative = pos2d - (region.Position << World2dRegion.WorldPositionShift); grass.GrassColor = region.InterpolatedGrassColors[relative.X, relative.Y]; return(snapshot); }
public void AddBlock(Vector3i position, BlockSnapshot snapshot, bool overrideBlocks) { if (overrideBlocks) { _data[position.X, position.Y, position.Z] = new UnloadedChunkGenerationBlock(snapshot, true); } else { var old = _data[position.X, position.Y, position.Z]; if (old == null || old.Snapshot is BlockSnapshotAir || old.Snapshot is BlockSnapshotTallGrass || old.Snapshot is BlockSnapshotOakLeaves) { _data[position.X, position.Y, position.Z] = new UnloadedChunkGenerationBlock(snapshot, false); } } }
public void AddBlock(Vector3i position, BlockSnapshot snapshot, bool overrideBlocks) { var chunkPosition = position >> Chunk.WorldPositionShift; var chunkWorldPosition = chunkPosition << Chunk.WorldPositionShift; if (_generations.TryGetValue(chunkPosition, out var generation)) { generation.AddBlock(position - chunkWorldPosition, snapshot, overrideBlocks); return; } var newGeneration = new UnloadedChunkGeneration(); newGeneration.AddBlock(position - chunkWorldPosition, snapshot, overrideBlocks); _generations.TryAdd(chunkPosition, newGeneration); }
public Block SetBlock(BlockSnapshot snapshot, Vector3i position, Func <Block, bool> canBeReplaced) { var regionPosition = position >> 6; var chunkPosition = position >> 4; var region = GetChunkRegion(regionPosition); if (region == null) { region = new ChunkRegion(this, regionPosition); region.LoadIfDeleted(); _chunkRegions[regionPosition] = region; } var chunk = region.GetChunkFromChunkPosition(chunkPosition); if (chunk != null) { return(chunk.SetBlockFromWorldPosition(snapshot, position, canBeReplaced)); } _unloadedChunkGenerationManager.AddBlock(position, snapshot, true); return(null); }
public UnloadedChunkGenerationBlock(BlockSnapshot snapshot, bool overrideBlocks) { _snapshot = snapshot; _overrideBlocks = overrideBlocks; }
public Block SetBlock(BlockSnapshot snapshot, Vector3i position) { return(SetBlock(snapshot, position, b => true)); }
public static bool TryGet(string id, out BlockSnapshot snapshot) { return(Blocks.TryGetValue(id, out snapshot)); }
public static void Register(BlockSnapshot snapshot) { Blocks.Add(snapshot.Id, snapshot); }