public void Put(ChunkManager manager) { VoxelChunk chunk = manager.ChunkData.ChunkMap[Vox.ChunkID]; Voxel v = chunk.MakeVoxel((int)Vox.GridPosition.X, (int)Vox.GridPosition.Y, (int)Vox.GridPosition.Z); v.Type = Type; v.Water = new WaterCell(); v.Health = Type.StartingHealth; chunk.NotifyTotalRebuild(!v.IsInterior); PlayState.ParticleManager.Trigger("puff", v.Position, Color.White, 20); List <Body> components = new List <Body>(); manager.Components.GetBodiesIntersecting(Vox.GetBoundingBox(), components, CollisionManager.CollisionType.Dynamic); foreach (Physics phys in components.OfType <Physics>()) { phys.ApplyForce((phys.GlobalTransform.Translation - (Vox.Position + new Vector3(0.5f, 0.5f, 0.5f))) * 100, 0.01f); BoundingBox box = v.GetBoundingBox(); Physics.Contact contact = new Physics.Contact(); Physics.TestStaticAABBAABB(box, phys.GetBoundingBox(), ref contact); if (!contact.IsIntersecting) { continue; } Vector3 diff = contact.NEnter * contact.Penetration; Matrix m = phys.LocalTransform; m.Translation += diff; phys.LocalTransform = m; } }
public override void OnVoxelsSelected(SpellTree tree, List <Voxel> voxels) { HashSet <Point3> chunksToRebuild = new HashSet <Point3>(); bool placed = false; foreach (Voxel selected in voxels) { if (selected != null && ((!Transmute && selected.IsEmpty) || Transmute && !selected.IsEmpty) && OnCast(tree)) { Vector3 p = selected.Position + Vector3.One * 0.5f; IndicatorManager.DrawIndicator("-" + ManaCost + " M", p, 1.0f, Color.Red); World.ParticleManager.Trigger("star_particle", p, Color.White, 4); VoxelLibrary.PlaceType(VoxelLibrary.GetVoxelType(VoxelType), selected); if (VoxelType == "Magic") { new VoxelListener(World.ComponentManager, World.ComponentManager.RootComponent, World.ChunkManager, selected) { DestroyOnTimer = true, DestroyTimer = new Timer(5.0f + MathFunctions.Rand(-0.5f, 0.5f), true) }; } placed = true; chunksToRebuild.Add(selected.ChunkID); } } foreach (Point3 point in chunksToRebuild) { VoxelChunk chunk = World.ChunkManager.ChunkData.ChunkMap[point]; chunk.ShouldRebuild = true; chunk.NotifyTotalRebuild(true); } if (placed) { SoundManager.PlaySound(ContentPaths.Audio.tinkle, World.CursorLightPos, true, 1.0f); } RechargeTimer.Reset(RechargeTimer.TargetTimeSeconds); base.OnVoxelsSelected(tree, voxels); }