本文整理汇总了Java中net.minecraftforge.fml.common.network.internal.FMLProxyPacket类的典型用法代码示例。如果您正苦于以下问题:Java FMLProxyPacket类的具体用法?Java FMLProxyPacket怎么用?Java FMLProxyPacket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FMLProxyPacket类属于net.minecraftforge.fml.common.network.internal包,在下文中一共展示了FMLProxyPacket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: make
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
@Override
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
FMLNetworkEvent.CustomPacketEvent<?> event = null;
if (msg.handler() instanceof NetHandlerPlayClient)
{
NetHandlerPlayClient client = (NetHandlerPlayClient) msg.handler();
event = new FMLNetworkEvent.ClientCustomPacketEvent(client.getNetworkManager(), msg);
}
else if (msg.handler() instanceof NetHandlerPlayServer)
{
NetHandlerPlayServer server = (NetHandlerPlayServer) msg.handler();
event = new FMLNetworkEvent.ServerCustomPacketEvent(server.getNetworkManager(), msg);
}
return event;
}
示例2: write
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
{
if (msg instanceof FMLProxyPacket)
{
if (side == Side.CLIENT)
{
//Client to server large packets are not supported to prevent client being bad.
ctx.write(((FMLProxyPacket) msg).toC17Packet(), promise);
}
else
{
List<Packet<INetHandlerPlayClient>> parts = ((FMLProxyPacket)msg).toS3FPackets();
for (Packet<INetHandlerPlayClient> pkt : parts)
{
ctx.write(pkt, promise);
}
}
}
else
{
ctx.write(msg, promise);
}
}
示例3: channelRead0
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket msg) throws Exception
{
Side side = msg.getTarget();
NetworkManager manager = msg.getOrigin();
if (msg.channel().equals("REGISTER") || msg.channel().equals("UNREGISTER"))
{
byte[] data = new byte[msg.payload().readableBytes()];
msg.payload().readBytes(data);
String channels = new String(data,Charsets.UTF_8);
String[] split = channels.split("\0");
Set<String> channelSet = ImmutableSet.copyOf(split);
FMLCommonHandler.instance().fireNetRegistrationEvent(manager, channelSet, msg.channel(), side);
}
else
{
ctx.fireChannelRead(msg);
}
}
示例4: selectNetworks
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
int dimension = (Integer)args;
ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.builder();
for (EntityPlayerMP player : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerList())
{
if (dimension == player.dimension)
{
NetworkDispatcher dispatcher = player.connection.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
// Null dispatchers may exist for fake players - skip them
if (dispatcher != null) builder.add(dispatcher);
}
}
return builder.build();
}
示例5: encode
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
@Override
protected final void encode(ChannelHandlerContext ctx, A msg, List<Object> out) throws Exception
{
PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
byte discriminator = types.get(msg.getClass());
buffer.writeByte(discriminator);
encodeInto(ctx, msg, buffer);
FMLProxyPacket proxy = new FMLProxyPacket(buffer/*.copy()*/, ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
WeakReference<FMLProxyPacket> ref = ctx.attr(INBOUNDPACKETTRACKER).get().get();
FMLProxyPacket old = ref == null ? null : ref.get();
if (old != null)
{
proxy.setDispatcher(old.getDispatcher());
}
out.add(proxy);
}
示例6: decode
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
@Override
protected final void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception
{
testMessageValidity(msg);
ByteBuf payload = msg.payload().duplicate();
if (payload.readableBytes() < 1)
{
FMLLog.log(Level.ERROR, "The FMLIndexedCodec has received an empty buffer on channel %s, likely a result of a LAN server issue. Pipeline parts : %s", ctx.channel().attr(NetworkRegistry.FML_CHANNEL), ctx.pipeline().toString());
}
byte discriminator = payload.readByte();
Class<? extends A> clazz = discriminators.get(discriminator);
if(clazz == null)
{
throw new NullPointerException("Undefined message for discriminator " + discriminator + " in channel " + msg.channel());
}
A newMsg = clazz.newInstance();
ctx.attr(INBOUNDPACKETTRACKER).get().set(new WeakReference<FMLProxyPacket>(msg));
decodeInto(ctx, payload.slice(), newMsg);
out.add(newMsg);
}
示例7: onPacketData
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
@SuppressWarnings( "unchecked" )
public void onPacketData(
final FMLProxyPacket packet,
final INetHandler handler,
final EntityPlayerMP playerEntity )
{
if ( playerEntity == null )
{
return;
}
final PacketBuffer buffer = new PacketBuffer( packet.payload() );
final ModPacket innerPacket = parsePacket( buffer );
innerPacket.serverEntity = playerEntity;
PacketThreadUtil.checkThreadAndEnqueue( innerPacket, handler, playerEntity.getServer() );
innerPacket.server( playerEntity );
}
示例8: shareTransforms
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
void shareTransforms() {
boolean needSync = (transformSynced.getGrandUnifiedDistance(transform) != 0 || velocitySynced.getGrandUnifiedDistance(velocity) != 0) && !hasOrders();
if (!needSync) return;
try {
ByteBuf output = Unpooled.buffer();
Core.network.prefixEntityPacket(output, this, SyncMessages.TRANSFORMS);
putTransforms(new DataOutByteBuf(output, Side.SERVER));
FMLProxyPacket toSend = Core.network.entityPacket(output);
Core.network.broadcastPacket(null, new Coord(this), toSend);
} catch (IOException e) {
e.printStackTrace();
return;
}
transformSynced = transform.copy();
velocitySynced = velocity.copy();
}
示例9: getDescriptionPacket
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
@Override
public FMLProxyPacket getDescriptionPacket() {
ByteBuf buf = Unpooled.buffer();
DataOutByteBuf data = new DataOutByteBuf(buf, Side.SERVER);
try {
NetworkFactorization.writeMessage(buf, FzNetEventHandler.TO_BLOCK, StandardMessageType.TileFzType);
buf.writeInt(pos.getX());
buf.writeInt(pos.getY());
buf.writeInt(pos.getZ());
int ftId = getFactoryType().md;
buf.writeByte(ftId);
putData(data);
return FzNetDispatch.generate(buf);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
示例10: removedByPlayer
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
@Override
public boolean removedByPlayer(World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
Coord here = new Coord(world, pos);
TileEntityCommon tec = here.getTE(TileEntityCommon.class);
if (tec == null) {
if (!world.isRemote) {
new Notice(here, "There was no TileEntity!").send(player);
}
return world.setBlockToAir(pos);
}
boolean ret = tec.removedByPlayer(player, willHarvest);
if (!world.isRemote && !ret) {
FMLProxyPacket description = tec.getDescriptionPacket();
Core.network.broadcastPacket(player, here, description);
here.sendRedraw();
}
return ret;
}
示例11: tickServer
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
@SubscribeEvent
public void tickServer(TickEvent.ServerTickEvent event) {
if (event.phase != TickEvent.Phase.START) return;
MinecraftServer ms = MinecraftServer.getServer();
if (ms.getTickCounter() < ms.tickTimeArray.length) {
//Ignore startup
return;
}
if (measurements++ != FzConfig.tps_reporting_interval) {
return;
}
measurements = 0;
float tps = getTpsRatio();
if (tps != last_tps) {
FMLProxyPacket packet = MiscellaneousNonsense.net.makeTpsReportPacket(getTpsRatio());
MiscNet.channel.sendToAll(packet);
last_tps = tps;
}
}
示例12: encode
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
@Override
protected void encode (ChannelHandlerContext ctx, AbstractPacket msg, List<Object> out) throws Exception
{
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());
}
byte discriminator = (byte) this.packets.indexOf(clazz);
buffer.writeByte(discriminator);
msg.encodeInto(ctx, buffer);
FMLProxyPacket proxyPacket = new FMLProxyPacket(new PacketBuffer(buffer.copy()), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
out.add(proxyPacket);
}
示例13: encode
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, PacketAbstract msg,
List<Object> out) throws Exception {
ByteBuf buffer = Unpooled.buffer();
Class<? extends PacketAbstract> clazz = msg.getClass();
if (!packets.contains(msg.getClass())) {
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((PacketBuffer) buffer.copy(), ctx
.channel().attr(NetworkRegistry.FML_CHANNEL).get());
out.add(proxyPacket);
}
示例14: decode
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception
{
ByteBuf buf = msg.payload();
int packetId = buf.readByte();
Class pktCls = packets.get(packetId);
SasaPacketBase pkt = (SasaPacketBase)pktCls.newInstance();
pkt.fromByteBuf(ctx, buf);
if(FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
{
pkt.receiveClient(getClientPlayer());
}
else if(FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
{
INetHandler localINetHandler = (INetHandler)ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
EntityPlayer ep = ((NetHandlerPlayServer)localINetHandler).playerEntity;
pkt.receiveServer(ep);
}
}
示例15: encode
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; //导入依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, ARKMessage msg, List<Object> out) throws Exception
{
ByteBuf buffer = Unpooled.buffer();
Class<? extends ARKMessage> clazz = msg.getClass();
if (!packets.contains(msg.getClass()))
{
throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName());
}
byte discriminator = (byte) packets.indexOf(clazz);
buffer.writeByte(discriminator);
msg.encodeInto(ctx, buffer);
FMLProxyPacket proxyPacket = new FMLProxyPacket((PacketBuffer) buffer, ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
out.add(proxyPacket);
}