Jump to content

Recommended Posts

Posted

Good evening everybody,

 

I send the packet to the server but nothing changes.

 

Key event

 

 

	Item[] items = new Item[]{RedTools.redSword, RedTools.redSwordCharged, RedTools.redPickaxe, RedTools.redPickaxeCharged, RedTools.redAxe, RedTools.redAxeCharged};
	RedstoneTools.packetLine.registerPacket(PacketSwitch.class);

	if(invert.isPressed()){
		InventoryPlayer inventory = Minecraft.getMinecraft().thePlayer.inventory;
		for(int i = 0; i < items.length && inventory.getCurrentItem() != null; i += 2){
			if(inventory.getCurrentItem().getUnlocalizedName().equals(new ItemStack(items[i]).getUnlocalizedName())){
				RedstoneTools.packetLine.sendToServer(new PacketSwitch());
			}
			else if(inventory.getCurrentItem().getUnlocalizedName().equals(new ItemStack(items[i + 1]).getUnlocalizedName())){
				RedstoneTools.packetLine.sendToServer(new PacketSwitch());
			}
		}
	}

 

 

 

Packet

 

 

import at.minecraft.korti.invertredstonetools.tools.RedTools;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;

public class PacketSwitch extends AbstractPacket{

@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	// TODO Auto-generated method stub

}

@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	// TODO Auto-generated method stub

}

@Override
public void handleClientSide(EntityPlayer player) {
	// TODO Auto-generated method stub

}

@Override
public void handleServerSide(EntityPlayer player) {
	Item[] items = new Item[]{RedTools.redSword, RedTools.redSwordCharged, RedTools.redPickaxe, RedTools.redPickaxeCharged, RedTools.redAxe, RedTools.redAxeCharged};

	InventoryPlayer inventory = player.inventory;

	for(int i = 0; i < items.length && inventory.getCurrentItem() != null; i += 2){
		if(inventory.getCurrentItem().getUnlocalizedName().equals(new ItemStack(items[i]).getUnlocalizedName())){
			inventory.setInventorySlotContents(inventory.currentItem, new ItemStack(items[i + 1], 1, inventory.getCurrentItem().getItemDamage()));
		}
		else if(inventory.getCurrentItem().getUnlocalizedName().equals(new ItemStack(items[i + 1]).getUnlocalizedName())){
			inventory.setInventorySlotContents(inventory.currentItem, new ItemStack(items[i], 1, inventory.getCurrentItem().getItemDamage()));
		}
	}

}

}

 

 

 

A good new week everybody.

Posted

So I changed it, but nothing changes.

 

Packet

 

 

public class PacketSwitch extends AbstractPacket{

ItemStack itemStack;

public PacketSwitch(ItemStack itemStack){
	this.itemStack = itemStack;
}

@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	ByteBufUtils.writeItemStack(buffer, itemStack);
}

@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	itemStack = ByteBufUtils.readItemStack(buffer);
}

@Override
public void handleClientSide(EntityPlayer player) {

	itemStack.setItemDamage(player.inventory.getCurrentItem().getItemDamage());

	player.inventory.setInventorySlotContents(player.inventory.currentItem, itemStack);

}

@Override
public void handleServerSide(EntityPlayer player) {

	itemStack.setItemDamage(player.inventory.getCurrentItem().getItemDamage());

	player.inventory.setInventorySlotContents(player.inventory.currentItem, itemStack);

}

}

[spoiler

Posted

Only the construtor work.

 

 

 

public class PacketSwitch extends AbstractPacket{

ItemStack itemStack;

public PacketSwitch(ItemStack itemStack){
	this.itemStack = itemStack;
	System.out.println(RedModInfo.ModName + ": new Packet");
}

@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	ByteBufUtils.writeItemStack(buffer, itemStack);
	System.out.println(RedModInfo.ModName + ": Packet was encoded");
}

@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	itemStack = ByteBufUtils.readItemStack(buffer);
	System.out.println(RedModInfo.ModName + ": Packet was decoded");
}

@Override
public void handleClientSide(EntityPlayer player) {

}

@Override
public void handleServerSide(EntityPlayer player) {

	itemStack.setItemDamage(player.inventory.getCurrentItem().getItemDamage());

	player.inventory.setInventorySlotContents(player.inventory.currentItem, itemStack);

	System.out.println(RedModInfo.ModName + ": Item was switched");
}

}

 

 

Posted

Did you register your packet in the PacketPipeline class? If you don't register your packets, it can't process them.

 

I do it in tandem with the initialization process:

public void initialise() {
this.channels = NetworkRegistry.INSTANCE.newChannel(ModInfo.CHANNEL, this);
registerPackets();
}

public void registerPackets() {
registerPacket(SomePacket.class);
registerPacket(SomeOtherPacket.class);
}

Also don't forget to call postInitialise() during post initialization.

 

@Chibill - I have never had any problems with my packets getting sent in the normal client mode, nor in the regular Minecraft launcher; you must be doing something incorrectly.

Posted

So now crash it when i press my key.

 

[17:02:47] [server thread/INFO]: Starting integrated minecraft server version 1.7.2
[17:02:47] [server thread/INFO]: Generating keypair
[17:02:47] [server thread/INFO]: Injecting new block and item data into this server instance
[17:02:47] [server thread/INFO]: Loading dimension 0 (test) (net.minecraft.server.integrated.IntegratedServer@4e284a28)
[17:02:47] [server thread/INFO]: Loading dimension 1 (test) (net.minecraft.server.integrated.IntegratedServer@4e284a28)
[17:02:47] [server thread/INFO]: Loading dimension -1 (test) (net.minecraft.server.integrated.IntegratedServer@4e284a28)
[17:02:47] [server thread/INFO]: Preparing start region for level 0
POKEE false
[17:02:48] [Netty Client IO #0/INFO]: Server protocol version 1
[17:02:48] [Netty IO #1/INFO]: Client protocol version 1
[17:02:48] [Netty IO #1/INFO]: Client attempting to join with 4 mods : [email protected],[email protected],[email protected],invertredstonetools@Alpha 0.1.1
[17:02:48] [Netty IO #1/INFO]: Attempting connection with missing mods [] at CLIENT
[17:02:48] [Netty Client IO #0/INFO]: Attempting connection with missing mods [] at SERVER
[17:02:48] [server thread/INFO]: [server thread] Server side modded connection established
[17:02:48] [server thread/INFO]: Player882[local:E:b64eea86] logged in with entity id 117 at (-441.29226556369974, 4.0, -908.4239892768311)
[17:02:48] [Client thread/INFO]: [Client thread] Client side modded connection established
[17:02:48] [server thread/INFO]: Player882 joined the game
Invert Redstone Tools: new Packet
[17:03:05] [server thread/ERROR]: There was a critical exception handling a packet on channel invertredstonetools
io.netty.handler.codec.DecoderException: java.lang.InstantiationException: at.minecraft.korti.invertredstonetools.utils.network.PacketSwitch
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:?]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?]
at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:74) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:211) [NetworkManager.class:?]
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:173) [NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:681) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:569) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:114) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:454) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:706) [MinecraftServer$2.class:?]
Caused by: java.lang.InstantiationException: at.minecraft.korti.invertredstonetools.utils.network.PacketSwitch
at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_51]
at at.minecraft.korti.invertredstonetools.utils.network.PacketPipeline.decode(PacketPipeline.java:89) ~[PacketPipeline.class:?]
at at.minecraft.korti.invertredstonetools.utils.network.PacketPipeline.decode(PacketPipeline.java:1) ~[PacketPipeline.class:?]
at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?]
... 13 more
[17:03:05] [server thread/INFO]: Player882 lost connection: TextComponent{text='A fatal error has occured, this connection is terminated', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null}}
[17:03:05] [server thread/INFO]: Player882 left the game
[17:03:05] [server thread/INFO]: Stopping singleplayer server as player logged out
[17:03:05] [server thread/INFO]: Stopping server
[17:03:05] [server thread/INFO]: Saving players
[17:03:05] [server thread/INFO]: Saving worlds
[17:03:05] [server thread/INFO]: Saving chunks for level 'test'/Overworld
[17:03:05] [server thread/INFO]: Saving chunks for level 'test'/Nether
[17:03:05] [server thread/INFO]: Saving chunks for level 'test'/The End
[17:03:05] [server thread/INFO]: Unloading dimension 0
[17:03:05] [server thread/INFO]: Unloading dimension -1
[17:03:05] [server thread/INFO]: Unloading dimension 1

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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