diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj
index f4b59650a..2cf2eb609 100644
--- a/ClassicalSharp/ClassicalSharp.csproj
+++ b/ClassicalSharp/ClassicalSharp.csproj
@@ -165,6 +165,7 @@
+
diff --git a/ClassicalSharp/Events/UserEvents.cs b/ClassicalSharp/Events/UserEvents.cs
new file mode 100644
index 000000000..269893cf0
--- /dev/null
+++ b/ClassicalSharp/Events/UserEvents.cs
@@ -0,0 +1,38 @@
+// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
+using System;
+
+namespace ClassicalSharp.Events {
+
+ public class UserEvents {
+
+ /// Raised when the user changes a block in the world.
+ public event EventHandler BlockChanged;
+ internal void RaiseBlockChanged( Vector3I coords, byte old, byte block ) {
+ blockArgs.Coords = coords; blockArgs.OldBlock = old; blockArgs.Block = block;
+ Raise( BlockChanged, blockArgs );
+ }
+
+ BlockChangedEventArgs blockArgs = new BlockChangedEventArgs();
+ protected void Raise( EventHandler handler ) {
+ if( handler != null )
+ handler( this, EventArgs.Empty );
+ }
+
+ protected void Raise( EventHandler handler, T args ) where T : EventArgs {
+ if( handler != null )
+ handler( this, args );
+ }
+ }
+
+ public sealed class BlockChangedEventArgs : EventArgs {
+
+ /// Location within the world the block was updated at.
+ public Vector3I Coords;
+
+ /// Block ID that was at the given location before.
+ public byte OldBlock;
+
+ /// Block ID that is now at the given location.
+ public byte Block;
+ }
+}
diff --git a/ClassicalSharp/Game/Game.Properties.cs b/ClassicalSharp/Game/Game.Properties.cs
index 1a55598e6..7dc6e746e 100644
--- a/ClassicalSharp/Game/Game.Properties.cs
+++ b/ClassicalSharp/Game/Game.Properties.cs
@@ -105,6 +105,7 @@ namespace ClassicalSharp {
public OtherEvents Events = new OtherEvents();
public EntityEvents EntityEvents = new EntityEvents();
public WorldEvents WorldEvents = new WorldEvents();
+ public UserEvents UserEvents = new UserEvents();
public InputHandler InputHandler;
public Chat Chat;
public BlockHandRenderer BlockHandRenderer;
diff --git a/ClassicalSharp/Game/PickingHandler.cs b/ClassicalSharp/Game/PickingHandler.cs
index 3edf8bee9..79a55b520 100644
--- a/ClassicalSharp/Game/PickingHandler.cs
+++ b/ClassicalSharp/Game/PickingHandler.cs
@@ -13,7 +13,7 @@ namespace ClassicalSharp {
public PickingHandler( Game game, InputHandler input ) {
this.game = game;
this.input = input;
- }
+ }
internal DateTime lastClick = DateTime.MinValue;
public void PickBlocks( bool cooldown, bool left, bool middle, bool right ) {
@@ -32,47 +32,51 @@ namespace ClassicalSharp {
}
int buttonsDown = (left ? 1 : 0) + (right ? 1 : 0) + (middle ? 1 : 0);
- if( buttonsDown > 1 || game.ActiveScreen.HandlesAllInput ||
+ if( buttonsDown > 1 || game.ActiveScreen.HandlesAllInput ||
inv.HeldBlock == Block.Air ) return;
// always play delete animations, even if we aren't picking a block.
if( left ) game.BlockHandRenderer.SetAnimationClick( true );
if( !game.SelectedPos.Valid ) return;
+ BlockInfo info = game.BlockInfo;
if( middle ) {
Vector3I pos = game.SelectedPos.BlockPos;
- byte block = 0;
- if( game.World.IsValidPos( pos ) && (block = game.World.GetBlock( pos )) != 0
- && (inv.CanPlace[block] || inv.CanDelete[block]) ) {
-
+ if( !game.World.IsValidPos( pos ) ) return;
+ byte old = game.World.GetBlock( pos );
+
+ if( !info.IsAir[old] && (inv.CanPlace[old] || inv.CanDelete[old]) ) {
for( int i = 0; i < inv.Hotbar.Length; i++ ) {
- if( inv.Hotbar[i] == (Block)block ) {
+ if( inv.Hotbar[i] == (Block)old ) {
inv.HeldBlockIndex = i; return;
}
}
- inv.HeldBlock = (Block)block;
+ inv.HeldBlock = (Block)old;
}
} else if( left ) {
Vector3I pos = game.SelectedPos.BlockPos;
- byte block = 0;
- if( game.World.IsValidPos( pos ) && (block = game.World.GetBlock( pos )) != 0
- && inv.CanDelete[block] ) {
- game.ParticleManager.BreakBlockEffect( pos, block );
- game.AudioPlayer.PlayDigSound( game.BlockInfo.DigSounds[block] );
+ if( !game.World.IsValidPos( pos ) ) return;
+ byte old = game.World.GetBlock( pos );
+
+ if( !info.IsAir[old] && inv.CanDelete[old] ) {
+ game.ParticleManager.BreakBlockEffect( pos, old );
+ game.AudioPlayer.PlayDigSound( game.BlockInfo.DigSounds[old] );
game.UpdateBlock( pos.X, pos.Y, pos.Z, 0 );
game.Network.SendSetBlock( pos.X, pos.Y, pos.Z, false, (byte)inv.HeldBlock );
+ game.UserEvents.RaiseBlockChanged( pos, old, 0 );
}
} else if( right ) {
Vector3I pos = game.SelectedPos.TranslatedPos;
if( !game.World.IsValidPos( pos ) ) return;
-
+ byte old = game.World.GetBlock( pos );
byte block = (byte)inv.HeldBlock;
- if( !game.CanPick( game.World.GetBlock( pos ) ) && inv.CanPlace[block]
- && CheckIsFree( game.SelectedPos, block ) ) {
+
+ if( !game.CanPick( old ) && inv.CanPlace[block] && CheckIsFree( game.SelectedPos, block ) ) {
game.UpdateBlock( pos.X, pos.Y, pos.Z, block );
game.AudioPlayer.PlayDigSound( game.BlockInfo.StepSounds[block] );
game.Network.SendSetBlock( pos.X, pos.Y, pos.Z, true, block );
game.BlockHandRenderer.SetAnimationClick( false );
+ game.UserEvents.RaiseBlockChanged( pos, old, block );
}
}
}
diff --git a/ClassicalSharp/Program.cs b/ClassicalSharp/Program.cs
index ffed8654e..6b3fc410e 100644
--- a/ClassicalSharp/Program.cs
+++ b/ClassicalSharp/Program.cs
@@ -52,10 +52,10 @@ namespace ClassicalSharp {
width = 640; height = 480;
if( device.Width >= 1024 && device.Height >= 768 ) {
- //width = 800; height = 600;
+ width = 800; height = 600;
}
if( device.Width >= 1920 && device.Height >= 1080 ) {
- //width = 1600; height = 900;
+ width = 1600; height = 900;
}
}