Add "InteractiveBoundingBox" to IBlockProvider

This is used to determine the bounding box for interaction in the client
(the ray that's cast from your camera interacts with it to determine the
highlighted block).

TODO: Make it work better with metadata.

This commit also fixes one of the issues with snow: ref #194
This commit is contained in:
Drew DeVault 2015-10-02 08:15:29 -04:00
parent fe479d1e49
commit 14aa3ce07a
13 changed files with 112 additions and 9 deletions

View File

@ -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<int, int> GetTextureMap(byte metadata);
void GenerateDropEntity(BlockDescriptor descriptor, IWorld world, IMultiplayerServer server, ItemStack heldItem);
void BlockLeftClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user);

View File

@ -101,10 +101,21 @@ namespace TrueCraft.Client.Modules
Game.HighlightedBlock = -Coordinates3D.One;
else
{
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;
HighlightEffect.World = DestructionEffect.World =
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));
}
}
}

View File

@ -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;

View File

@ -271,6 +271,14 @@ namespace TrueCraft.Core.Logic
}
}
public virtual BoundingBox? InteractiveBoundingBox
{
get
{
return BoundingBox;
}
}
/// <summary>
/// Gets the time required to mine the given block with the given item.
/// </summary>

View File

@ -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<int, int> GetTextureMap(byte metadata)
{

View File

@ -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<int, int> GetTextureMap(byte metadata)

View File

@ -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<int, int> GetTextureMap(byte metadata)
{
return new Tuple<int, int>(7, 3);

View File

@ -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<int, int> GetTextureMap(byte metadata)
{
return new Tuple<int, int>(3, 5);

View File

@ -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<int, int> GetTextureMap(byte metadata)
{
return new Tuple<int, int>(12, 0);

View File

@ -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<int, int> GetTextureMap(byte metadata)
{
return new Tuple<int, int>(15, 0);

View File

@ -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<int, int> GetTextureMap(byte metadata)
{

View File

@ -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;

View File

@ -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<int, int> GetTextureMap(byte metadata)
{
return new Tuple<int, int>(4, 0);