
sirati97
Members-
Posts
6 -
Joined
-
Last visited
Everything posted by sirati97
-
[1.8.9/Solved] PluginChannel is only working on first login.
sirati97 replied to sirati97's topic in Modder Support
I changed a lot of the code and it works now. sadly i dont know what broke it. I also updated my forge maybe that was the reason. -
[1.7.10] [UNSOLVED] How to use a semi-transparent item texture
sirati97 replied to Silly511's topic in Modder Support
If we already discuss this piece of java code, you should consider the oracle java code conventions paragraph 10.5.2 That states: if (type != ItemRenderType.INVENTORY) { return true; } else { return false; } } should be written as return type != ItemRenderType.INVENTORY; Also i am sorry that i cannot help you with your problem, but anyway in 1.8 IItemRenderer is deprecated/removed (depending on which version of forge you use) -
[1.8.9/Solved] PluginChannel is only working on first login.
sirati97 replied to sirati97's topic in Modder Support
But that would not explain why they work at the first login on a server with the client. Anyway i am no longer using the SimpleNetworkWrapper. I implemented my own PluginChannel handler. Its code is based on the SimpleNetworkWrapper, but it doesnt converts the FMLProxyPacket to an IMessage, because i dont need it anyway. I just need the byte[] payload. My Channel works fine, but it still only works on the first login. Maybe this is actually a forge bug?! If you are interested here is the code: package de.sirati97.oilmod.forge; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFutureListener; import net.minecraft.network.INetHandler; import net.minecraft.network.PacketBuffer; import net.minecraftforge.fml.common.network.FMLEmbeddedChannel; import net.minecraftforge.fml.common.network.FMLOutboundHandler; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; import net.minecraftforge.fml.relauncher.Side; import java.util.EnumMap; /** * Created by sirati97 on 16.03.2016. */ public abstract class PluginChannel { private String name; private EnumMap<Side, FMLEmbeddedChannel> channels; private PluginChannelInboundHandler handler = new PluginChannelInboundHandler(this); public PluginChannel(String name) { this.name = name; channels = NetworkRegistry.INSTANCE.newChannel(name, handler); } public void sendToServer(byte[] out) { FMLProxyPacket message = encode(out); channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER); channels.get(Side.CLIENT).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); } public String getName() { return name; } public abstract byte[] onMessage(byte[] in, INetHandler netHandler); public FMLProxyPacket encode(byte[] out) { PacketBuffer buffer = new PacketBuffer(Unpooled.buffer()); buffer.writeBytes(out); FMLProxyPacket proxy = new FMLProxyPacket(buffer, getName()); return proxy; } public byte[] decode(FMLProxyPacket msg) { ByteBuf buf = msg.payload().copy(); byte[] stream = new byte[buf.array().length-buf.arrayOffset()]; buf.readBytes(stream); return stream; } } and the imbound handler: package de.sirati97.oilmod.forge; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import net.minecraft.network.INetHandler; import net.minecraftforge.fml.common.FMLLog; import net.minecraftforge.fml.common.network.FMLOutboundHandler; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; import org.apache.logging.log4j.Level; /** * Created by sirati97 on 16.03.2016. */ @ChannelHandler.Sharable public class PluginChannelInboundHandler extends SimpleChannelInboundHandler<FMLProxyPacket> { private final PluginChannel pluginChannel; public PluginChannelInboundHandler(PluginChannel pluginChannel) { this.pluginChannel = pluginChannel; } @Override protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket msg) throws Exception { INetHandler iNetHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); byte[] out = pluginChannel.onMessage(pluginChannel.decode(msg), iNetHandler); if (out != null) { FMLProxyPacket result = pluginChannel.encode(out); ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.REPLY); ctx.writeAndFlush(result).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); } } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { FMLLog.log(Level.ERROR, cause, "PluginChannelInboundHandler exception"); super.exceptionCaught(ctx, cause); } } That should not be an issue because NetworkRegistry.INSTANCE.newChannel(String name, ChannelHandler... handlers) puts them in there map on both sides: public EnumMap<Side,FMLEmbeddedChannel> newChannel(String name, ChannelHandler... handlers) { if (channels.get(Side.CLIENT).containsKey(name) || channels.get(Side.SERVER).containsKey(name) || name.startsWith("MC|") || name.startsWith("\u0001") || name.startsWith("FML")) { throw new RuntimeException("That channel is already registered"); } EnumMap<Side,FMLEmbeddedChannel> result = Maps.newEnumMap(Side.class); for (Side side : Side.values()) { FMLEmbeddedChannel channel = new FMLEmbeddedChannel(name, side, handlers); channels.get(side).put(name,channel); result.put(side, channel); } return result; } -
[1.8.9/Solved] PluginChannel is only working on first login.
sirati97 replied to sirati97's topic in Modder Support
My server doesnt require a custom client. The client is completely optional and i dont want to rely on forge. I only use forge as a base for the client mod because i want to be compertible with other mods. After that i am going to communicate over another pluginchannel. When the clients send pack the packet, the server is going to open a connection to the client that is tunnelt through the pluginchannel. So i need functioning plugin channels. -
Hey guys, I am sirati97 and i am still a forge noob. (I am more that type of guy that forks NMS or Spigot ) So anyway i am trying to communicate with my minecraft server over two plugin channels. I got them registered and receiving works fine. But somehow there are two things that doesnt work: On the first channel i am just sending back the packet when i receive it. Its just a check if the client has my mod installed. That's my code: public static class Handler implements IMessageHandler<InitMessage, IMessage> { private SimpleNetworkWrapper network; public Handler(SimpleNetworkWrapper network) { this.network = network; } @Override public IMessage onMessage(final InitMessage message, final MessageContext ctx) { System.out.println("received init"); return message; } } It always receives the packet but it the answer arrives the server in only 1 of 10 tries. Because i dont make anything different i think it has something to do with multi-threading inside the client. Maybe the clients only allows you to send packets pack at the server, if he completely logged in. But that should be the case as the server sends the init packet as soon as the player logged in. Anyway i was annoyed of this and just tried it like this to be sure that the server receives the packet. So i made this rather stupid code: public static class Handler implements IMessageHandler<InitMessage, IMessage> { private SimpleNetworkWrapper network; public Handler(SimpleNetworkWrapper network) { this.network = network; } @Override public IMessage onMessage(final InitMessage message, final MessageContext ctx) { System.out.println("received init"); network.sendToServer(new InitMessage()); Thread t = new Thread() { @Override public void run() { for (int i=0;i<20;i++) { try { Thread.sleep(150); } catch (InterruptedException e) { e.printStackTrace(); } network.sendToServer(new InitMessage()); } } }; t.start(); return message; } } Now the server gets spammed with init packets. And it works. But only on the first log in. When you leave the server and log in again it doesnt work anymore. There is no error, but my server doesnt receive any pluginchannelpackets. My first guess was that i need to register the packet on every login so i did that but it fails, because it is already registered. So i searched for an unregister method but as there is no method like this i assume that you just need to register it once. SO my registering code looks like this: @EventHandler public void init(FMLInitializationEvent event) { MinecraftForge.EVENT_BUS.register(this); SimpleNetworkWrapper network = NetworkRegistry.INSTANCE.newSimpleChannel("{name removed}|INIT"); InitMessage.Handler handler = new InitMessage.Handler(network); network.registerMessage(handler, InitMessage.class, 0, Side.CLIENT); } Anyway i know that it is not the servers fault because i monitor every incoming packet. Thanks in advance, sirati97