public void OnBlockPlaced(BlockEventData data, params int[] args) { if (data.blockType == BlockType.AIR) { return; } World.ParticleManager.InstantiateBlockParticle(ParticleType.BLOCK_PLACE, data.WorldPosition, data.blockType, true); }
public void OnBlockDestroy(BlockEventData data, params int[] args) { BlockPosition above = data.LocalPosition.Above(); if (data.chunk.GetBlock(above) == BlockType.GRASS) { data.chunk.AddBlockToBuildList(new BlockData(BlockType.AIR, above)); World.ParticleManager.InstantiateBlockParticle(ParticleType.BLOCK_DESTROY, Utils.LocalToWorldPositionVector3Int(data.chunk.ChunkPosition, above), BlockType.GRASS, true); } }
public void OnBlockDestroy(BlockEventData data, params int[] args) { if (data.blockType == BlockType.AIR) { return; } BlockType type = data.blockType == BlockType.GRASS_BLOCK ? BlockType.DIRT : data.blockType; World.SoundManager.PlaySound(type, data.WorldPosition, destroySoundSettings); World.ParticleManager.InstantiateBlockParticle(ParticleType.BLOCK_DESTROY, data.WorldPosition, type, true); }
public void OnBlockPlaced(BlockEventData data, params int[] args) { if (data.blockType == BlockType.STONE) { posOne = data.WorldPosition + Vector3Int.up; } else { posTwo = data.WorldPosition + Vector3Int.up; } // BlockPosition blockPosition = World.GetTopSolidBlock(new Vector2Int(data.WorldPosition.x, data.WorldPosition.z), out Chunk chunk); // blockPosition.y += 2; // chunk.SetBlock(blockPosition, BlockType.OAK_LEAVES, SetBlockSettings.PLACE); }
public void OnBlockUpdate(BlockEventData data, Dictionary <BlockFace, BlockEventData> neighbours, params int[] args) { // if above block is solid block BlockState aboveBlockState = WorldData.GetBlockState(neighbours[BlockFace.TOP].blockType); if (aboveBlockState == BlockState.SOLID) { // replace current block with dirt in next update data.chunk.AddBlockToBuildList(data.LocalPosition, BlockType.DIRT); } else if (aboveBlockState == BlockState.LIQUID) { if (args.Length > 0 && args[0] == 1) { data.chunk.AddBlockToBuildList(data.LocalPosition, BlockType.DIRT); } else { World.ScheduleUpdate(data.chunk, data.LocalPosition, 200, 1); } } }
public void OnBlockUpdate(BlockEventData data, Dictionary <BlockFace, BlockEventData> neighbours, params int[] args) { BlockState aboveBlockState = WorldData.GetBlockState(neighbours[BlockFace.TOP].blockType); // if above block is not solid and there is grass block nearby - build grass block if (aboveBlockState != BlockState.SOLID && aboveBlockState != BlockState.LIQUID && ( neighbours[BlockFace.BACK].blockType == BlockType.GRASS_BLOCK || neighbours[BlockFace.FRONT].blockType == BlockType.GRASS_BLOCK || neighbours[BlockFace.LEFT].blockType == BlockType.GRASS_BLOCK || neighbours[BlockFace.RIGHT].blockType == BlockType.GRASS_BLOCK)) { // if args[0] == 1 build grass block if (args.Length > 0 && args[0] == 1) { data.chunk.AddBlockToBuildList(data.LocalPosition, BlockType.GRASS_BLOCK); } else { // schedule grass build and pass args[0] = 1 World.ScheduleUpdate(data.chunk, data.LocalPosition, Random.Range(100, 200), 1); } } }
public void OnBlockUpdate(BlockEventData data, Dictionary <BlockFace, BlockEventData> neighbours, params int[] args) { //data.chunk.AddBlockToBuildList(data.position + BlockPosition.up * 2, BlockType.COBBLESTONE); }
/// <summary> /// Call BlockDestroyEvent /// </summary> /// <param name="blockEventData">data of block that is calling update</param> public static void InvokeBlockPlaceEvent(BlockEventData blockEventData, params int[] args) { OnBlockPlaceEvents[blockEventData.blockType]?.Invoke(blockEventData, args); }
/// <summary> /// Call BlockUpdateEvent /// </summary> /// <param name="blockEventData">data of block that is calling update</param> /// <param name="neighbourBlocksData">data of neighbour blocks</param> public static void InvokeBlockUpdateEvent(BlockEventData blockEventData, Dictionary <BlockFace, BlockEventData> neighbourBlocksData, params int[] args) { OnBlockUpdateEvents[blockEventData.blockType]?.Invoke(blockEventData, neighbourBlocksData, args); }
// TODO: some cleaning? public void OnBlockUpdate(BlockEventData data, Dictionary <BlockFace, BlockEventData> neighbours, params int[] args) { short sourceDistance = data.chunk.GetParameterValue(new BlockParameter(data.LocalPosition, ParameterType.WATER_SOURCE_DISTANCE)); BlockType belowBlock = neighbours[BlockFace.BOTTOM].blockType; // checl for WATER_SOURCE_DISTANCE in neighbour blocks short biggestSourceDistance = 0; for (int i = 2; i < 6; i++) { BlockEventData blockUpdateEventData = neighbours[(BlockFace)i]; int index = Utils.BlockPosition3DtoIndex(blockUpdateEventData.LocalPosition); BlockType type = blockUpdateEventData.chunk.blocks[index]; if (type == BlockType.WATER) { BlockParameter param = new BlockParameter(blockUpdateEventData.LocalPosition, ParameterType.WATER_SOURCE_DISTANCE); short neighbourSourceDistance = blockUpdateEventData.chunk.GetParameterValue(param); if (neighbourSourceDistance > biggestSourceDistance) { biggestSourceDistance = neighbourSourceDistance; } } } if (WorldData.GetBlockState(belowBlock) == BlockState.SOLID) { // check only side blocks for (int i = 2; i < 6; i++) { BlockEventData blockUpdateEventData = neighbours[(BlockFace)i]; Chunk chunk = blockUpdateEventData.chunk; BlockParameter param = new BlockParameter(blockUpdateEventData.LocalPosition, ParameterType.WATER_SOURCE_DISTANCE); int index = Utils.BlockPosition3DtoIndex(blockUpdateEventData.LocalPosition); BlockType type = chunk.blocks[index]; if (sourceDistance > 0) { if (type == BlockType.AIR || WorldData.GetBlockState(type) == BlockState.PLANTS) { chunk.AddParameterToList(param, (short)(sourceDistance - 1)); chunk.AddBlockToBuildList(new BlockData(BlockType.WATER, blockUpdateEventData.LocalPosition)); World.ScheduleUpdate(chunk, blockUpdateEventData.LocalPosition, 2); } if (type == BlockType.WATER) { // if neighbour block is WATER and neighbour sourceDistance is smaller, update neighbour sourceDistance if (chunk.GetParameterValue(param) < sourceDistance - 1) { chunk.AddParameterToList(param, (short)(sourceDistance - 1)); chunk.AddBlockToBuildList(new BlockData(BlockType.WATER, blockUpdateEventData.LocalPosition)); } } } } } // if block below is AIR or WATER or PLANTS, replace block with full WATER block else if (belowBlock == BlockType.AIR || belowBlock == BlockType.WATER || WorldData.GetBlockState(belowBlock) == BlockState.PLANTS) { data.chunk.AddParameterToList(new BlockParameter(neighbours[BlockFace.BOTTOM].LocalPosition, ParameterType.WATER_SOURCE_DISTANCE), 8); data.chunk.AddBlockToBuildList(new BlockData(BlockType.WATER, neighbours[BlockFace.BOTTOM].LocalPosition)); } // if water is not full block, check if has neighbour with bigger SourceDistance if (sourceDistance != 8 && biggestSourceDistance <= sourceDistance) { // if sourceDistance == 0, replace block with air if (sourceDistance == 0) { data.chunk.ClearParameters(data.LocalPosition); data.chunk.AddBlockToBuildList(new BlockData(BlockType.AIR, data.LocalPosition)); if (belowBlock == BlockType.WATER) { BlockEventData blockUpdateEventData = neighbours[BlockFace.BOTTOM]; data.chunk.AddParameterToList(new BlockParameter(blockUpdateEventData.LocalPosition, ParameterType.WATER_SOURCE_DISTANCE), (short)7); World.ScheduleUpdate(blockUpdateEventData.chunk, blockUpdateEventData.LocalPosition, 1); } } // else, decrease sourceDistance by 1 else { data.chunk.AddParameterToList(new BlockParameter(data.LocalPosition, ParameterType.WATER_SOURCE_DISTANCE), (short)(sourceDistance - 1)); data.chunk.AddBlockToBuildList(new BlockData(BlockType.WATER, data.LocalPosition)); } } }