Allow placing blocks off map bedrock sides. (Thanks MrGoober)

This commit is contained in:
UnknownShadow200 2016-01-30 21:43:11 +11:00
parent c3ffec20a2
commit 21c1c031c6
8 changed files with 19 additions and 15 deletions

View file

@ -218,10 +218,10 @@
<Compile Include="Commands\CommandManager.cs" /> <Compile Include="Commands\CommandManager.cs" />
<Compile Include="Commands\CommandReader.cs" /> <Compile Include="Commands\CommandReader.cs" />
<Compile Include="Network\Utils\NetWriter.cs" /> <Compile Include="Network\Utils\NetWriter.cs" />
<Compile Include="Physics\BoundingBox.cs" /> <Compile Include="Math\BoundingBox.cs" />
<Compile Include="Physics\IntersectionUtils.cs" /> <Compile Include="Math\IntersectionUtils.cs" />
<Compile Include="Physics\PickedPos.cs" /> <Compile Include="Math\PickedPos.cs" />
<Compile Include="Physics\Picking.cs" /> <Compile Include="Math\Picking.cs" />
<Compile Include="Platform\Font.cs" /> <Compile Include="Platform\Font.cs" />
<Compile Include="Platform\IPlatformWindow.cs" /> <Compile Include="Platform\IPlatformWindow.cs" />
<Compile Include="Platform\Platform.cs" /> <Compile Include="Platform\Platform.cs" />
@ -236,10 +236,10 @@
<Compile Include="Rendering\FrustumCulling.cs" /> <Compile Include="Rendering\FrustumCulling.cs" />
<Compile Include="Rendering\MapBordersRenderer.cs" /> <Compile Include="Rendering\MapBordersRenderer.cs" />
<Compile Include="Rendering\MapRenderer.cs" /> <Compile Include="Rendering\MapRenderer.cs" />
<Compile Include="Rendering\PickingRenderer.cs" />
<Compile Include="Rendering\StandardEnvRenderer.cs" /> <Compile Include="Rendering\StandardEnvRenderer.cs" />
<Compile Include="Rendering\WeatherRenderer.cs" /> <Compile Include="Rendering\WeatherRenderer.cs" />
<Compile Include="Selections\AxisLinesRenderer.cs" /> <Compile Include="Selections\AxisLinesRenderer.cs" />
<Compile Include="Selections\PickedPosRenderer.cs" />
<Compile Include="Selections\SelectionBox.cs" /> <Compile Include="Selections\SelectionBox.cs" />
<Compile Include="Selections\SelectionBoxComparer.cs" /> <Compile Include="Selections\SelectionBoxComparer.cs" />
<Compile Include="Selections\SelectionManager.cs" /> <Compile Include="Selections\SelectionManager.cs" />
@ -301,7 +301,7 @@
<Folder Include="TexturePack" /> <Folder Include="TexturePack" />
<Folder Include="Singleplayer" /> <Folder Include="Singleplayer" />
<Folder Include="Utils" /> <Folder Include="Utils" />
<Folder Include="Physics" /> <Folder Include="Math" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenTK\OpenTK.csproj"> <ProjectReference Include="..\OpenTK\OpenTK.csproj">

View file

@ -69,7 +69,7 @@ namespace ClassicalSharp {
public CommandManager CommandManager; public CommandManager CommandManager;
public SelectionManager SelectionManager; public SelectionManager SelectionManager;
public ParticleManager ParticleManager; public ParticleManager ParticleManager;
public PickingRenderer Picking; public PickedPosRenderer Picking;
public PickedPos SelectedPos = new PickedPos(), CameraClipPos = new PickedPos(); public PickedPos SelectedPos = new PickedPos(), CameraClipPos = new PickedPos();
public ModelCache ModelCache; public ModelCache ModelCache;
internal string skinServer, chatInInputBuffer = null; internal string skinServer, chatInInputBuffer = null;

View file

@ -144,7 +144,7 @@ namespace ClassicalSharp {
Culling = new FrustumCulling(); Culling = new FrustumCulling();
EnvRenderer.Init(); EnvRenderer.Init();
MapBordersRenderer.Init(); MapBordersRenderer.Init();
Picking = new PickingRenderer( this ); Picking = new PickedPosRenderer( this );
AudioPlayer = new AudioPlayer( this ); AudioPlayer = new AudioPlayer( this );
LiquidsBreakable = Options.GetBool( OptionsKey.LiquidsBreakable, false ); LiquidsBreakable = Options.GetBool( OptionsKey.LiquidsBreakable, false );
AxisLinesRenderer = new AxisLinesRenderer( this ); AxisLinesRenderer = new AxisLinesRenderer( this );

View file

@ -112,7 +112,7 @@ namespace ClassicalSharp {
case CpeBlockFace.ZMin: case CpeBlockFace.ZMin:
pickedPos.IntersectPoint.Z -= adjust; break; pickedPos.IntersectPoint.Z -= adjust; break;
case CpeBlockFace.ZMax: case CpeBlockFace.ZMax:
pickedPos.IntersectPoint.Z += adjust; break; pickedPos.IntersectPoint.Z += adjust; break;
} }
return; return;
} }
@ -125,7 +125,7 @@ namespace ClassicalSharp {
} }
static void CalcVectors( Vector3 origin, Vector3 dir, out Vector3I step, static void CalcVectors( Vector3 origin, Vector3 dir, out Vector3I step,
out Vector3I cellBoundary, out Vector3 tMax, out Vector3 tDelta ) { out Vector3I cellBoundary, out Vector3 tMax, out Vector3 tDelta ) {
Vector3I start = Vector3I.Floor( origin ); Vector3I start = Vector3I.Floor( origin );
// Determine which way we go. // Determine which way we go.
step.X = Math.Sign( dir.X ); step.Y = Math.Sign( dir.Y ); step.Z = Math.Sign( dir.Z ); step.X = Math.Sign( dir.X ); step.Y = Math.Sign( dir.Y ); step.Z = Math.Sign( dir.Z );
@ -174,11 +174,15 @@ namespace ClassicalSharp {
if( x >= 0 && z >= 0 && x < map.Width && z < map.Length ) { if( x >= 0 && z >= 0 && x < map.Width && z < map.Length ) {
if( y >= map.Height ) return 0; if( y >= map.Height ) return 0;
if( y >= 0 ) return map.GetBlock( x, y, z ); if( y >= 0 ) return map.GetBlock( x, y, z );
if( map.SidesBlock != Block.Air && y == -1 )
// special case: we want to be able to pick bedrock when we're standing on top of it
if( origin.Y >= 0 && y == -1 )
return (byte)Block.Bedrock; return (byte)Block.Bedrock;
} }
if( map.SidesBlock == Block.Air ) return 0;
bool validX = (x == -1 || x == map.Width) && (z >= 0 && z < map.Length);
bool validZ = (z == -1 || z == map.Length) && (x >= 0 && x < map.Width);
if( y >= 0 && y < Math.Max( 1, map.SidesHeight ) && (validX || validZ) )
return (byte)Block.Bedrock;
return 0; return 0;
} }
} }

View file

@ -4,13 +4,13 @@ using OpenTK;
namespace ClassicalSharp.Renderers { namespace ClassicalSharp.Renderers {
public class PickingRenderer : IDisposable { public sealed class PickedPosRenderer : IDisposable {
IGraphicsApi graphics; IGraphicsApi graphics;
Game game; Game game;
int vb; int vb;
public PickingRenderer( Game game ) { public PickedPosRenderer( Game game ) {
graphics = game.Graphics; graphics = game.Graphics;
vb = graphics.CreateDynamicVb( VertexFormat.Pos3fCol4b, verticesCount ); vb = graphics.CreateDynamicVb( VertexFormat.Pos3fCol4b, verticesCount );
this.game = game; this.game = game;