Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm getting this in my console:

[09:55:14] [server thread/ERROR] [FML]: Detected ongoing potential memory leak. 100 packets have leaked. Top offenders
[09:55:14] [server thread/ERROR] [FML]: 	 ttm : 100

 

I'm partially worried, because this packet is from the client to the server, and is gonna be sent a lot.

 

Packet:

package ttm.network;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.ForgeHooks;
import ttm.Reference;

public class PacketMessage extends AbstractPacket {
public int msgID;

public PacketMessage(int msgID) {
	super();
	this.msgID = msgID;
}

public PacketMessage() {
	this(0);
}

@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	buffer.writeInt(msgID);
}

@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	msgID = buffer.readInt();
}

@Override
public void handleClientSide(EntityPlayer player) {
}

@Override
public void handleServerSide(EntityPlayer player) {
	switch(msgID) {
	case Reference.PacketMessages.JUMP: {
		ForgeHooks.onLivingJump(player);
		break;
	}
	}
}
}

 

Should I be worried about this?

Kain

Is your packet system based on this tutorial?  http://www.minecraftforge.net/wiki/Netty_Packet_Handling

 

You'll see that there is now a warning on that tutorial saying it creates memory leaks and should not be used

 

Instead you need to use the new SimpleNetworkWrapper system: http://www.minecraftforge.net/forum/index.php/topic,20135.0.html

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

  • Author

I've run into a problem.

 

Whenever I send the message to the server, it never arrives. It only writes to the byte buffer.

 

Message:

package ttm.network;

import io.netty.buffer.ByteBuf;
import net.minecraftforge.common.ForgeHooks;
import ttm.Reference;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public class SimpleServerMessage extends AbstractMessage {
public int msgID;

public SimpleServerMessage(int msgID) {
	super();
	this.msgID = msgID;
}

public SimpleServerMessage() {
	this(0);
}

@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(msgID);
}

@Override
public void fromBytes(ByteBuf buf) {
	msgID = buf.readInt();
}

public static class Handler implements IMessageHandler<SimpleServerMessage, IMessage> {
	public IMessage onMessage(SimpleServerMessage message, MessageContext ctx) {
		switch(message.msgID) {
		case Reference.PacketMessages.JUMP: {
			ForgeHooks.onLivingJump(ctx.getServerHandler().playerEntity);
			break;
		}
		}

		return null;
	}
}
}

 

Basic Message:

package ttm.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import ttm.TtM;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public abstract class BasicMessage implements IMessage {
@Override
public abstract void fromBytes(ByteBuf buf);

@Override
public abstract void toBytes(ByteBuf buf);

public void sendToAll() {
	TtM.networkChannel.sendToAll(this);
}

public void sendTo(EntityPlayerMP player) {
	TtM.networkChannel.sendTo(this, player);
}

public void sendToServer() {
	TtM.networkChannel.sendToServer(this);
	System.err.println("TO THE SERVER!");
}
}

Kain

  • Author

Ok, I only had the IDs because that message class was only for short messages.

 

None of my other messages are being received either.

 

Mod:

package ttm;

import static ttm.Reference.ID;
import static ttm.Reference.NAME;
import static ttm.Reference.VERSION;
import ttm.handler.GuiHandler;
import ttm.network.MessageJump;
import ttm.network.MessageOpenGui;
import ttm.network.MessageQuickStack;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;

@Mod(name = NAME, modid = ID, version = VERSION)
public class TtM {
@Instance(ID)
public static TtM instance;
@SidedProxy(serverSide = ID + ".ServerProxy", clientSide = ID + ".ClientProxy")
public static ServerProxy proxy;

public static GuiHandler guiHandler = new GuiHandler();
public static SimpleNetworkWrapper networkChannel;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
	NetworkRegistry.INSTANCE.registerGuiHandler(this, guiHandler);
	networkChannel = NetworkRegistry.INSTANCE.newSimpleChannel("TtM");
	loadPackets();

	proxy.loadServer();
	proxy.loadClient();
}

public void loadPackets() {
	networkChannel.registerMessage(MessageJump.Handler.class, MessageJump.class, 0, Side.SERVER);
	networkChannel.registerMessage(MessageOpenGui.Handler.class, MessageOpenGui.class, 0, Side.SERVER);
	networkChannel.registerMessage(MessageQuickStack.Handler.class, MessageQuickStack.class, 0, Side.SERVER);
}
}

 

Message:

package ttm.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import ttm.TtM;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public class MessageOpenGui extends BasicMessage {
public int guiID;

public MessageOpenGui(int guiID) {
	super();
	this.guiID = guiID;
}

public MessageOpenGui() {
	this(0);
}

@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(guiID);

	System.err.println("HI2");
}

@Override
public void fromBytes(ByteBuf buf) {
	guiID = buf.readInt();

	System.err.println("HI");
}

public static class Handler implements IMessageHandler<MessageOpenGui, IMessage> {
	public IMessage onMessage(MessageOpenGui message, MessageContext ctx) {
		EntityPlayer player = ctx.getServerHandler().playerEntity;

		player.openGui(TtM.instance, message.guiID, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);

		return null;
	}
}
}

 

BasicMessage:

package ttm.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import ttm.TtM;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public abstract class BasicMessage implements IMessage {
@Override
public abstract void fromBytes(ByteBuf buf);

@Override
public abstract void toBytes(ByteBuf buf);

public void sendToAll() {
	TtM.networkChannel.sendToAll(this);
}

public void sendTo(EntityPlayerMP player) {
	TtM.networkChannel.sendTo(this, player);
}

public void sendToServer() {
	TtM.networkChannel.sendToServer(this);
	System.err.println("TO THE SERVER!");
}
}

Kain

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.