diff --git a/TrueCraft.API/Logic/IBlockProvider.cs b/TrueCraft.API/Logic/IBlockProvider.cs index 85e24a4..ed2d0fd 100644 --- a/TrueCraft.API/Logic/IBlockProvider.cs +++ b/TrueCraft.API/Logic/IBlockProvider.cs @@ -21,6 +21,7 @@ namespace TrueCraft.API.Logic ToolType EffectiveTools { get; } string DisplayName { get; } BoundingBox? BoundingBox { get; } // NOTE: Will this eventually need to be metadata-aware? + BoundingBox? InteractiveBoundingBox { get; } // NOTE: Will this eventually need to be metadata-aware? Tuple GetTextureMap(byte metadata); void GenerateDropEntity(BlockDescriptor descriptor, IWorld world, IMultiplayerServer server, ItemStack heldItem); void BlockLeftClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user); diff --git a/TrueCraft.Client/Modules/HighlightModule.cs b/TrueCraft.Client/Modules/HighlightModule.cs index 5934d85..d229296 100644 --- a/TrueCraft.Client/Modules/HighlightModule.cs +++ b/TrueCraft.Client/Modules/HighlightModule.cs @@ -90,8 +90,8 @@ namespace TrueCraft.Client.Modules public void Update(GameTime gameTime) { var direction = XVector3.Transform(XVector3.UnitZ, - Matrix.CreateRotationX(MathHelper.ToRadians(Game.Client.Pitch)) * - Matrix.CreateRotationY(MathHelper.ToRadians(-(Game.Client.Yaw - 180) + 180))); + Matrix.CreateRotationX(MathHelper.ToRadians(Game.Client.Pitch)) * + Matrix.CreateRotationY(MathHelper.ToRadians(-(Game.Client.Yaw - 180) + 180))); var cast = VoxelCast.Cast(Game.Client.World, new TRay(Game.Camera.Position, new TVector3(direction.X, direction.Y, direction.Z)), @@ -101,10 +101,21 @@ namespace TrueCraft.Client.Modules Game.HighlightedBlock = -Coordinates3D.One; else { - Game.HighlightedBlock = cast.Item1; - Game.HighlightedBlockFace = cast.Item2; - HighlightEffect.World = DestructionEffect.World = - Matrix.CreateTranslation(new XVector3(cast.Item1.X, cast.Item1.Y, cast.Item1.Z)); + var provider = Game.BlockRepository.GetBlockProvider(Game.Client.World.GetBlockID(cast.Item1)); + if (provider.InteractiveBoundingBox != null) + { + var box = provider.InteractiveBoundingBox.Value; + + Game.HighlightedBlock = cast.Item1; + Game.HighlightedBlockFace = cast.Item2; + + DestructionEffect.World = + Matrix.CreateTranslation(new XVector3(cast.Item1.X, cast.Item1.Y, cast.Item1.Z)); + HighlightEffect.World = Matrix.Identity + * Matrix.CreateScale(new XVector3((float)box.Width, (float)box.Height, (float)box.Depth)) + * Matrix.CreateTranslation(new XVector3((float)box.Min.X, (float)box.Min.Y, (float)box.Min.Z)) + * Matrix.CreateTranslation(new XVector3(cast.Item1.X, cast.Item1.Y, cast.Item1.Z)); + } } } diff --git a/TrueCraft.Client/VoxelCast.cs b/TrueCraft.Client/VoxelCast.cs index f9e410b..1e1c4a9 100644 --- a/TrueCraft.Client/VoxelCast.cs +++ b/TrueCraft.Client/VoxelCast.cs @@ -35,7 +35,7 @@ namespace TrueCraft.Client if (id != 0) { var provider = repository.GetBlockProvider(id); - var box = provider.BoundingBox; + var box = provider.InteractiveBoundingBox; if (box != null) { BlockFace _face; diff --git a/TrueCraft.Core/Logic/BlockProvider.cs b/TrueCraft.Core/Logic/BlockProvider.cs index 7891254..ee4544d 100644 --- a/TrueCraft.Core/Logic/BlockProvider.cs +++ b/TrueCraft.Core/Logic/BlockProvider.cs @@ -271,6 +271,14 @@ namespace TrueCraft.Core.Logic } } + public virtual BoundingBox? InteractiveBoundingBox + { + get + { + return BoundingBox; + } + } + /// /// Gets the time required to mine the given block with the given item. /// diff --git a/TrueCraft.Core/Logic/Blocks/CropsBlock.cs b/TrueCraft.Core/Logic/Blocks/CropsBlock.cs index fb84222..3e92c04 100644 --- a/TrueCraft.Core/Logic/Blocks/CropsBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/CropsBlock.cs @@ -24,7 +24,15 @@ namespace TrueCraft.Core.Logic.Blocks public override string DisplayName { get { return "Crops"; } } - public override TrueCraft.API.BoundingBox? BoundingBox { get { return null; } } + public override BoundingBox? BoundingBox { get { return null; } } + + public override BoundingBox? InteractiveBoundingBox + { + get + { + return new BoundingBox(Vector3.Zero, new Vector3(1, 3 / 16.0, 1)); + } + } public override Tuple GetTextureMap(byte metadata) { diff --git a/TrueCraft.Core/Logic/Blocks/DandelionBlock.cs b/TrueCraft.Core/Logic/Blocks/DandelionBlock.cs index d22f73b..5908371 100644 --- a/TrueCraft.Core/Logic/Blocks/DandelionBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/DandelionBlock.cs @@ -22,6 +22,14 @@ namespace TrueCraft.Core.Logic.Blocks public override BoundingBox? BoundingBox { get { return null; } } + public override BoundingBox? InteractiveBoundingBox + { + get + { + return new BoundingBox(new Vector3(4 / 16.0, 0, 4 / 16.0), new Vector3(12 / 16.0, 8 / 16.0, 12 / 16.0)); + } + } + public override bool Flammable { get { return true; } } public override Tuple GetTextureMap(byte metadata) diff --git a/TrueCraft.Core/Logic/Blocks/DeadBushBlock.cs b/TrueCraft.Core/Logic/Blocks/DeadBushBlock.cs index 41d5f32..49dd479 100644 --- a/TrueCraft.Core/Logic/Blocks/DeadBushBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/DeadBushBlock.cs @@ -22,6 +22,19 @@ namespace TrueCraft.Core.Logic.Blocks public override BoundingBox? BoundingBox { get { return null; } } + public override BoundingBox? InteractiveBoundingBox + { + get + { + return new BoundingBox(new Vector3(4 / 16.0), Vector3.One); + } + } + + public override Coordinates3D GetSupportDirection(BlockDescriptor descriptor) + { + return Coordinates3D.Down; + } + public override Tuple GetTextureMap(byte metadata) { return new Tuple(7, 3); diff --git a/TrueCraft.Core/Logic/Blocks/LadderBlock.cs b/TrueCraft.Core/Logic/Blocks/LadderBlock.cs index 22bafae..0565000 100644 --- a/TrueCraft.Core/Logic/Blocks/LadderBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/LadderBlock.cs @@ -36,6 +36,14 @@ namespace TrueCraft.Core.Logic.Blocks public override BoundingBox? BoundingBox { get { return null; } } + public override BoundingBox? InteractiveBoundingBox + { + get + { + return new BoundingBox(new Vector3(0.25, 0, 0.25), new Vector3(0.75, 0.5, 0.75)); + } + } + public override Tuple GetTextureMap(byte metadata) { return new Tuple(3, 5); diff --git a/TrueCraft.Core/Logic/Blocks/RoseBlock.cs b/TrueCraft.Core/Logic/Blocks/RoseBlock.cs index 82121dd..1a26d53 100644 --- a/TrueCraft.Core/Logic/Blocks/RoseBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/RoseBlock.cs @@ -22,6 +22,14 @@ namespace TrueCraft.Core.Logic.Blocks public override BoundingBox? BoundingBox { get { return null; } } + public override BoundingBox? InteractiveBoundingBox + { + get + { + return new BoundingBox(new Vector3(4 / 16.0, 0, 4 / 16.0), new Vector3(12 / 16.0, 8 / 16.0, 12 / 16.0)); + } + } + public override Tuple GetTextureMap(byte metadata) { return new Tuple(12, 0); diff --git a/TrueCraft.Core/Logic/Blocks/SaplingBlock.cs b/TrueCraft.Core/Logic/Blocks/SaplingBlock.cs index 6b7e4ac..b6cd475 100644 --- a/TrueCraft.Core/Logic/Blocks/SaplingBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/SaplingBlock.cs @@ -29,6 +29,14 @@ namespace TrueCraft.Core.Logic.Blocks public override BoundingBox? BoundingBox { get { return null; } } + public override BoundingBox? InteractiveBoundingBox + { + get + { + return new BoundingBox(new Vector3(1 / 16.0, 0, 1 / 16.0), new Vector3(14 / 16.0)); + } + } + public override Tuple GetTextureMap(byte metadata) { return new Tuple(15, 0); diff --git a/TrueCraft.Core/Logic/Blocks/SnowBlock.cs b/TrueCraft.Core/Logic/Blocks/SnowBlock.cs index 30d1989..4f0f3c4 100644 --- a/TrueCraft.Core/Logic/Blocks/SnowBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/SnowBlock.cs @@ -71,7 +71,21 @@ namespace TrueCraft.Core.Logic.Blocks public override string DisplayName { get { return "Snow"; } } - public override TrueCraft.API.BoundingBox? BoundingBox { get { return null; } } + public override BoundingBox? BoundingBox { get { return null; } } + + public override BoundingBox? InteractiveBoundingBox + { + get + { + // TODO: This is metadata-aware + return new BoundingBox(Vector3.Zero, new Vector3(1, 1 / 16.0, 1)); + } + } + + public override Coordinates3D GetSupportDirection(BlockDescriptor descriptor) + { + return Coordinates3D.Down; + } public override Tuple GetTextureMap(byte metadata) { diff --git a/TrueCraft.Core/Logic/Blocks/TallGrassBlock.cs b/TrueCraft.Core/Logic/Blocks/TallGrassBlock.cs index 2ade6bf..a2dec16 100644 --- a/TrueCraft.Core/Logic/Blocks/TallGrassBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/TallGrassBlock.cs @@ -32,6 +32,14 @@ namespace TrueCraft.Core.Logic.Blocks public override BoundingBox? BoundingBox { get { return null; } } + public override BoundingBox? InteractiveBoundingBox + { + get + { + return new BoundingBox(new Vector3(4 / 16.0), Vector3.One); + } + } + public override Coordinates3D GetSupportDirection(BlockDescriptor descriptor) { return Coordinates3D.Down; diff --git a/TrueCraft.Core/Logic/Blocks/UprightSignBlock.cs b/TrueCraft.Core/Logic/Blocks/UprightSignBlock.cs index a5a1b9b..97bba24 100644 --- a/TrueCraft.Core/Logic/Blocks/UprightSignBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/UprightSignBlock.cs @@ -27,6 +27,14 @@ namespace TrueCraft.Core.Logic.Blocks public override BoundingBox? BoundingBox { get { return null; } } + public override BoundingBox? InteractiveBoundingBox + { + get + { + return new BoundingBox(new Vector3(6 / 16.0, 0, 6 / 16.0), new Vector3(10 / 16.0, 10 / 16.0, 10 / 16.0)); + } + } + public override Tuple GetTextureMap(byte metadata) { return new Tuple(4, 0);