public virtual void BlockUpdate(World world, BlockCoordinates position, BlockCoordinates updatedBlock) { if (BlockState.VariantMapper.IsMultiPart) { BlockStateResource blockStateResource; if (Alex.Instance.Resources.TryGetBlockState(BlockState.Name, out blockStateResource)) { var state = MultiPartModelHelper.GetBlockState(world, position, BlockState, blockStateResource); if (state != BlockState) { world.SetBlockState(position, state); } } } }
public virtual BlockState BlockPlaced(IBlockAccess world, BlockState state, BlockCoordinates position) { //return state; if (state.VariantMapper.IsMultiPart) { BlockStateResource blockStateResource; if (Alex.Instance.Resources.TryGetBlockState(state.Name, out blockStateResource)) { return(MultiPartModelHelper.GetBlockState(world, position, state, blockStateResource)); } } return(state); }
public void UpdateBuffer(GraphicsDevice device, IBlockAccess world, bool keepInMemory) { if (!Monitor.TryEnter(_dataLock, 0)) { return; } try { //var chunkData = ChunkData; if (ChunkData == null) { return; } var chunkPosition = new Vector3(X << 4, 0, Z << 4); for (int sectionIndex = 0; sectionIndex < 16; sectionIndex++) { var section = Sections[sectionIndex]; if (section == null) { continue; } //var sectionY = (sectionIndex << 4); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < 16; y++) { var blockCoordinates = new BlockCoordinates(x, y + (sectionIndex * 16), z); bool scheduled = section.IsScheduled(x, y, z); bool blockLightUpdate = section.IsBlockLightScheduled(x, y, z); bool skyLightUpdate = section.IsSkylightUpdateScheduled(x, y, z); if ((!IsNew && !scheduled && !blockLightUpdate && !skyLightUpdate)) { continue; } try { //ChunkData?.Remove(device, blockCoordinates); var blockPosition = new BlockCoordinates( (int)(chunkPosition.X + x), y + (sectionIndex << 4), (int)(chunkPosition.Z + z)); foreach (var state in section.GetAll(x, y, z)) { var blockState = state.State; if (blockState == null || blockState.Model == null || blockState.Block == null || !blockState.Block.Renderable) { continue; } var model = blockState.Model; if (blockState.Block.RequiresUpdate) { var newblockState = blockState.Block.BlockPlaced( world, blockState, blockPosition); if (newblockState != blockState) { blockState = newblockState; section.Set(state.Storage, x, y, z, blockState); model = blockState.Model; } } if (blockState.IsMultiPart) { var newBlockState = MultiPartModelHelper.GetBlockState( world, blockPosition, blockState, blockState.MultiPartHelper); if (newBlockState != blockState) { blockState = newBlockState; section.Set(state.Storage, x, y, z, blockState); model = blockState.Model; } } ChunkData?.Remove(device, blockCoordinates); model.GetVertices(world, ChunkData, blockCoordinates, blockPosition, blockState.Block); } } finally { if (scheduled) { section.SetScheduled(x, y, z, false); } if (blockLightUpdate) { section.SetBlockLightScheduled(x, y, z, false); } if (skyLightUpdate) { section.SetSkyLightUpdateScheduled(x, y, z, false); } } } } } } ChunkData?.ApplyChanges(device, true); IsNew = false; } finally { _previousKeepInMemory = keepInMemory; Monitor.Exit(_dataLock); } }