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:
parent
fe479d1e49
commit
14aa3ce07a
@ -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);
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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>
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user