Skip to content

Commit cec06e7

Browse files
committed
Added simple waypoints [WIP]
press P to place one
1 parent 022f94c commit cec06e7

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

SharpCraft/SharpCraft.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,13 @@ protected override void OnKeyDown(KeyboardKeyEventArgs e)
750750

751751
switch (e.Key)
752752
{
753+
case Key.P:
754+
var vec = new BlockPos(Player.pos).ToVec() + Vector3.One * 0.5f;
755+
vec.Y = Player.pos.Y;
756+
Player.TeleportTo(vec);
757+
758+
Player?.world?.AddWaypoint(new BlockPos(Player.pos).Offset(FaceSides.Up), new OpenTK.Color(255, 0, 0, 127), "TEST");
759+
break;
753760
case Key.Escape:
754761
if (GuiScreen is GuiScreenMainMenu || KeyboardState.IsKeyDown(Key.Escape))
755762
return;

SharpCraft/render/ParticleRenderer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public void SpawnDestroyParticles(BlockPos pos, EnumBlock block, int meta)
121121
var vec = localPos - halfVec;
122122
var motion = vec.Normalized() * 0.2f;
123123

124+
motion.X += MathUtil.NextFloat(-0.05f, 0.05f);
125+
motion.Y += MathUtil.NextFloat(-0.05f, 0.05f);
126+
motion.Z += MathUtil.NextFloat(-0.05f, 0.05f);
127+
124128
var particle = new ParticleDigging(SharpCraft.Instance.World, posVec + worldPos, motion, MathUtil.NextFloat(1, 1.5f), block, meta);
125129

126130
AddParticle(particle);

SharpCraft/render/WorldRenderer.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public void Render(World world, float partialTicks)
9696
RenderChunks(world);
9797
RenderSelectedItemBlock(partialTicks);
9898
RenderDestroyProgress(world);
99+
RenderWorldWaypoints(world);
99100

100101
var partialFov = lastFov + (fov - lastFov) * partialTicks;
101102
var partialMotion = lastMotion + (motion - lastMotion) * partialTicks;
@@ -118,6 +119,32 @@ private void RenderChunks(World world)
118119
}
119120
}
120121

122+
private void RenderWorldWaypoints(World world)
123+
{
124+
var wps = world.GetWaypoints();
125+
126+
foreach (var wp in wps)
127+
{
128+
var model = ModelRegistry.GetModelForBlock(EnumBlock.RARE, 0);
129+
130+
var size = 0.25f;
131+
132+
GL.DepthRange(0, 0.1f);
133+
134+
model.Bind();
135+
136+
model.Shader.UpdateGlobalUniforms();
137+
model.Shader.UpdateModelUniforms(model.RawModel);
138+
model.Shader.UpdateInstanceUniforms(MatrixHelper.CreateTransformationMatrix(wp.Pos.ToVec() + Vector3.One / 2 * (1 - size), (Vector3.UnitX + Vector3.UnitZ) * 42.5f, size), model);
139+
140+
model.RawModel.Render(PrimitiveType.Quads);
141+
142+
model.Unbind();
143+
144+
GL.DepthRange(0, 1);
145+
}
146+
}
147+
121148
private void RenderDestroyProgress(World world)
122149
{
123150
var progresses = SharpCraft.Instance.DestroyProgresses;

SharpCraft/world/Waypoint.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using OpenTK;
2+
using SharpCraft.block;
3+
4+
namespace SharpCraft.world
5+
{
6+
public class Waypoint
7+
{
8+
public BlockPos Pos;
9+
public Color Color;
10+
public string Name;
11+
12+
public Waypoint(BlockPos pos, Color color, string name)
13+
{
14+
Pos = pos;
15+
Color = color;
16+
Name = name;
17+
}
18+
}
19+
}

SharpCraft/world/World.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class World
3131

3232
public ChunkLoadManager LoadManager { get; } = new ChunkLoadManager();
3333

34+
//TODO - clientside only
35+
private Dictionary<BlockPos, Waypoint> _waypoints = new Dictionary<BlockPos, Waypoint>();
36+
3437
public World(string saveName, string levelName, int seed)
3538
{
3639
_noiseUtil = new NoiseUtil(Seed = seed);
@@ -341,5 +344,29 @@ public void Update(EntityPlayerSP player, int renderDistance)
341344

342345
UpdateEntities();
343346
}
347+
348+
public void AddWaypoint(BlockPos pos, Color color, string name)
349+
{
350+
_waypoints.TryAdd(pos, new Waypoint(pos, color, name));
351+
}
352+
353+
public void RemoveWaypoint(BlockPos pos)
354+
{
355+
_waypoints.Remove(pos);
356+
}
357+
358+
public void EditWaypoint(BlockPos pos, Color color, string name)
359+
{
360+
if (_waypoints.TryGetValue(pos, out var wp))
361+
{
362+
wp.Color = color;
363+
wp.Name = name;
364+
}
365+
}
366+
367+
public Dictionary<BlockPos, Waypoint>.ValueCollection GetWaypoints()
368+
{
369+
return _waypoints.Values;
370+
}
344371
}
345372
}

0 commit comments

Comments
 (0)