Skip to content

Commit

Permalink
v1.0.1.1 - Implemented emitter removal for MP
Browse files Browse the repository at this point in the history
* Added mod icon
* Implemented emitter removal for MP
  • Loading branch information
hamstar0 committed Apr 30, 2020
1 parent 59e1195 commit fee3875
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Emitters/Items/EmitterItem_Interactivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,17 @@ private static bool AttemptEmitterRemove( Vector2 worldPos ) {
return false;
}

return myworld.RemoveEmitter( tileX, tileY );
if( !myworld.RemoveEmitter( tileX, tileY ) ) {
return false;
}

if( Main.netMode == 1 ) {
EmitterRemoveProtocol.BroadcastFromClient( tileX, tileY );
} else if( Main.netMode == 2 ) {
EmitterRemoveProtocol.BroadcastFromServer( tileX, tileY );
}

return true;
}


Expand Down
63 changes: 63 additions & 0 deletions Emitters/NetProtocols/EmitterRemoveProtocol.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using HamstarHelpers.Classes.Errors;
using HamstarHelpers.Classes.Protocols.Packet.Interfaces;


namespace Emitters.NetProtocols {
class EmitterRemoveProtocol : PacketProtocolBroadcast {
public static void BroadcastFromClient( ushort tileX, ushort tileY ) {
if( Main.netMode != 1 ) { throw new ModHelpersException("Not client."); }

var protocol = new EmitterRemoveProtocol( tileX, tileY );

protocol.SendToServer( true );
}

public static void BroadcastFromServer( ushort tileX, ushort tileY ) {
if( Main.netMode != 2 ) { throw new ModHelpersException("Not server."); }

var protocol = new EmitterRemoveProtocol( tileX, tileY );

protocol.SendToClient( -1, -1 );
}



////////////////

public ushort TileX;
public ushort TileY;



////////////////

private EmitterRemoveProtocol() { }

private EmitterRemoveProtocol( ushort tileX, ushort tileY ) {
this.TileX = tileX;
this.TileY = tileY;
}


////////////////

protected override void ReceiveOnClient() {
var myworld = ModContent.GetInstance<EmittersWorld>();

Main.PlaySound( SoundID.Item108, new Vector2(this.TileX<<4, this.TileY<<4) );

myworld.RemoveEmitter( this.TileX, this.TileY );
}

protected override void ReceiveOnServer( int fromWho ) {
var myworld = ModContent.GetInstance<EmittersWorld>();

myworld.RemoveEmitter( this.TileX, this.TileY );
}
}
}
2 changes: 1 addition & 1 deletion Emitters/build.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
displayName = Emitters
author = hamstar
version = 1.0.1
version = 1.0.1.1
modReferences = [email protected]
buildIgnore = *.csproj, *.user, *.bat, obj\*, bin\*, .vs\*, .git\*
homepage = https://forums.terraria.org/index.php?threads/emitters.87584/
Binary file added Emitters/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Image Sources/icon.pdn
Binary file not shown.

0 comments on commit fee3875

Please sign in to comment.