mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-22 13:09:53 +00:00
[ci skip] spotlessApply with the new settings
This commit is contained in:
1 parent
83698cb73c
commit
84c2239244
561 files changed
+8872
-9300
No files matched your search
@@ -1,5 +1,13 @@
|
||||
package tconstruct.util.network;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import mantle.common.network.*;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.*;
|
||||
import net.minecraft.network.*;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.*;
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
@@ -7,15 +15,9 @@ import cpw.mods.fml.relauncher.*;
|
||||
import io.netty.buffer.*;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.handler.codec.MessageToMessageCodec;
|
||||
import java.util.*;
|
||||
import mantle.common.network.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.*;
|
||||
import net.minecraft.network.*;
|
||||
|
||||
/**
|
||||
* Packet pipeline class. Directs all registered packet data to be handled by
|
||||
* the packets themselves.
|
||||
* Packet pipeline class. Directs all registered packet data to be handled by the packets themselves.
|
||||
*
|
||||
* @author sirgingalot some code from: cpw
|
||||
*/
|
||||
@@ -27,15 +29,12 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
||||
private boolean isPostInitialised = false;
|
||||
|
||||
/**
|
||||
* Register your packet with the pipeline. Discriminators are automatically
|
||||
* set.
|
||||
* Register your packet with the pipeline. Discriminators are automatically set.
|
||||
*
|
||||
* @param clazz
|
||||
* the class to register
|
||||
* @param clazz the class to register
|
||||
*
|
||||
* @return whether registration was successful. Failure may occur if 256
|
||||
* packets have been registered or if the registry already contains
|
||||
* this packet
|
||||
* @return whether registration was successful. Failure may occur if 256 packets have been registered or if the
|
||||
* registry already contains this packet
|
||||
*/
|
||||
public boolean registerPacket(Class<? extends AbstractPacket> clazz) {
|
||||
if (this.packets.size() > 256) {
|
||||
@@ -63,15 +62,15 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
Class<? extends AbstractPacket> clazz = msg.getClass();
|
||||
if (!this.packets.contains(msg.getClass())) {
|
||||
throw new NullPointerException(
|
||||
"No Packet Registered for: " + msg.getClass().getCanonicalName());
|
||||
throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
byte discriminator = (byte) this.packets.indexOf(clazz);
|
||||
buffer.writeByte(discriminator);
|
||||
msg.encodeInto(ctx, buffer);
|
||||
FMLProxyPacket proxyPacket = new FMLProxyPacket(
|
||||
buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
|
||||
buffer.copy(),
|
||||
ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
|
||||
out.add(proxyPacket);
|
||||
}
|
||||
|
||||
@@ -96,8 +95,7 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
||||
break;
|
||||
|
||||
case SERVER:
|
||||
INetHandler netHandler =
|
||||
ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
|
||||
INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
|
||||
player = ((NetHandlerPlayServer) netHandler).playerEntity;
|
||||
pkt.handleServerSide(player);
|
||||
break;
|
||||
@@ -155,16 +153,12 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
||||
/**
|
||||
* Send this message to everyone.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in
|
||||
* cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
* Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message
|
||||
* The message to send
|
||||
* @param message The message to send
|
||||
*/
|
||||
public void sendToAll(AbstractPacket message) {
|
||||
this.channels
|
||||
.get(Side.SERVER)
|
||||
.attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||
.set(FMLOutboundHandler.OutboundTarget.ALL);
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
@@ -172,87 +166,57 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
||||
/**
|
||||
* Send this message to the specified player.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in
|
||||
* cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
* Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message
|
||||
* The message to send
|
||||
* @param player
|
||||
* The player to send it to
|
||||
* @param message The message to send
|
||||
* @param player The player to send it to
|
||||
*/
|
||||
public void sendTo(AbstractPacket message, EntityPlayerMP player) {
|
||||
this.channels
|
||||
.get(Side.SERVER)
|
||||
.attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||
.set(FMLOutboundHandler.OutboundTarget.PLAYER);
|
||||
this.channels
|
||||
.get(Side.SERVER)
|
||||
.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS)
|
||||
.set(player);
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to everyone within a certain range of a point.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in
|
||||
* cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
* Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message
|
||||
* The message to send
|
||||
* @param point
|
||||
* The
|
||||
* {@link cpw.mods.fml.common.network.NetworkRegistry.TargetPoint}
|
||||
* around which to send
|
||||
* @param message The message to send
|
||||
* @param point The {@link cpw.mods.fml.common.network.NetworkRegistry.TargetPoint} around which to send
|
||||
*/
|
||||
public void sendToAllAround(AbstractPacket message, NetworkRegistry.TargetPoint point) {
|
||||
this.channels
|
||||
.get(Side.SERVER)
|
||||
.attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||
.set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT);
|
||||
this.channels
|
||||
.get(Side.SERVER)
|
||||
.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS)
|
||||
.set(point);
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point);
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to everyone within the supplied dimension.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in
|
||||
* cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
* Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message
|
||||
* The message to send
|
||||
* @param dimensionId
|
||||
* The dimension id to target
|
||||
* @param message The message to send
|
||||
* @param dimensionId The dimension id to target
|
||||
*/
|
||||
public void sendToDimension(AbstractPacket message, int dimensionId) {
|
||||
this.channels
|
||||
.get(Side.SERVER)
|
||||
.attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||
.set(FMLOutboundHandler.OutboundTarget.DIMENSION);
|
||||
this.channels
|
||||
.get(Side.SERVER)
|
||||
.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS)
|
||||
.set(dimensionId);
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimensionId);
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to the server.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in
|
||||
* cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
* Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message
|
||||
* The message to send
|
||||
* @param message The message to send
|
||||
*/
|
||||
public void sendToServer(AbstractPacket message) {
|
||||
this.channels
|
||||
.get(Side.CLIENT)
|
||||
.attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||
this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET)
|
||||
.set(FMLOutboundHandler.OutboundTarget.TOSERVER);
|
||||
this.channels.get(Side.CLIENT).writeAndFlush(message);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user