Put both LogicalSides on NetworkDirection:

Origination (where it came from) and Reception (where it arrived at).

Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
cpw committed 2019-02-28 21:39:36 -05:00
1 parent 58494f8878
commit 3c73dc2d0b
3 files changed
+11 -9

No files matched your search

@@ -131,7 +131,7 @@ public class FMLPlayMessages
throw new RuntimeException(String.format("Could not spawn entity (id %d) with unknown type at (%f, %f, %f)", msg.entityId, msg.posX, msg.posY, msg.posZ));
}
Optional<World> world = LogicalSidedProvider.CLIENTWORLD.get(ctx.get().getDirection().getLogicalSide());
Optional<World> world = LogicalSidedProvider.CLIENTWORLD.get(ctx.get().getDirection().getReceptionSide());
Entity e = world.map(w->type.handleSpawnMessage(w, msg)).orElse(null);
if (e == null)
{
@@ -79,11 +79,13 @@ public enum NetworkDirection
return this.eventSupplier.apply(buffer, manager);
}
public LogicalSide getLogicalSide()
public LogicalSide getOriginationSide()
{
return logicalSide;
}
public LogicalSide getReceptionSide() { return reply().logicalSide; };
@SuppressWarnings("unchecked")
public <T extends Packet<?>> ICustomPacket<T> buildPacket(Pair<PacketBuffer,Integer> packetData, ResourceLocation channelName)
{
@@ -129,7 +129,7 @@ public class NetworkEvent extends Event
/**
* The {@link NetworkDirection} this message has been received on.
*/
private final NetworkDirection side;
private final NetworkDirection networkDirection;
/**
* The packet dispatcher for this event. Sends back to the origin.
@@ -137,19 +137,19 @@ public class NetworkEvent extends Event
private final PacketDispatcher packetDispatcher;
private boolean packetHandled;
Context(NetworkManager netHandler, NetworkDirection side, int index)
Context(NetworkManager netHandler, NetworkDirection networkDirection, int index)
{
this(netHandler, side, new PacketDispatcher.NetworkManagerDispatcher(netHandler, index, side.reply()::buildPacket));
this(netHandler, networkDirection, new PacketDispatcher.NetworkManagerDispatcher(netHandler, index, networkDirection.reply()::buildPacket));
}
Context(NetworkManager networkManager, NetworkDirection side, PacketDispatcher dispatcher) {
Context(NetworkManager networkManager, NetworkDirection networkDirection, PacketDispatcher dispatcher) {
this.networkManager = networkManager;
this.side = side;
this.networkDirection = networkDirection;
this.packetDispatcher = dispatcher;
}
public NetworkDirection getDirection() {
return side;
return networkDirection;
}
public PacketDispatcher getPacketDispatcher() {
@@ -171,7 +171,7 @@ public class NetworkEvent extends Event
@SuppressWarnings("unchecked")
public <V> ListenableFuture<V> enqueueWork(Runnable runnable) {
return (ListenableFuture<V>)LogicalSidedProvider.WORKQUEUE.<IThreadListener>get(getDirection().reply().getLogicalSide()).addScheduledTask(runnable);
return (ListenableFuture<V>)LogicalSidedProvider.WORKQUEUE.<IThreadListener>get(getDirection().getReceptionSide()).addScheduledTask(runnable);
}
/**