Created
January 28, 2014 23:13
-
-
Save MrBluePotato/8678634 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ProcessSetBlockPacket() | |
{ | |
BytesReceived += 9; | |
if (World == null || World.Map == null) return; | |
ResetIdleTimer(); | |
short x = IPAddress.NetworkToHostOrder(reader.ReadInt16()); | |
short z = IPAddress.NetworkToHostOrder(reader.ReadInt16()); | |
short y = IPAddress.NetworkToHostOrder(reader.ReadInt16()); | |
ClickAction action = (reader.ReadByte() == 1) ? ClickAction.Build : ClickAction.Delete; | |
byte type = reader.ReadByte(); | |
// if a player is using InDev or SurvivalTest client, they may try to | |
// place blocks that are not found in MC Classic. Convert them! | |
if (type > 65) | |
{ | |
type = MapDat.MapBlock(type); | |
} | |
Vector3I coords = new Vector3I(x, y, z); | |
// If block is in bounds, count the click. | |
// Sometimes MC allows clicking out of bounds, | |
// like at map transitions or at the top layer of the world. | |
// Those clicks should be simply ignored. | |
if (World.Map.InBounds(coords)) | |
{ | |
var e = new PlayerClickingEventArgs(this, coords, action, (Block)type); | |
if (RaisePlayerClickingEvent(e)) | |
{ | |
RevertBlockNow(coords); | |
} | |
else | |
{ | |
RaisePlayerClickedEvent(this, coords, e.Action, e.Block); | |
PlaceBlock(coords, e.Action, e.Block); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment