Jump to content

[1.7.2][SOLVED]Send Packet to Server


korti11

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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");
}

}

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://youtube.com/shorts/gqLTSMymgUg?si=5QOeSvA4TTs-bL46
    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. 📈 Skills: RPG-style skill system that enhances your gaming experience! 🎮 Leaderboards: Compete and shine! Top players are rewarded weekly! 🏆 Random Teleporter: Travel instantly across different worlds with a click! 🌐 Custom World Generation: Beautifully generated world. 🌍 Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. 🏰 Kits: Unlock ranks and gain access to various kits. 🛠️ Fishing Tournament: Compete in a friendly fishing tournament! 🎣 Chat Games: Enjoy games right within the chat! 🎲 Minions: Get some help from your loyal minions. 👥 Piñata Party: Enjoy a festive party with Piñatas! 🎉 Quests: Over 1000 quests that you can complete! 📜 Bounty Hunter: Set a bounty on a player's head. 💰 Tags: Displayed on nametags, in the tab list, and in chat. 🏷️ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! 🟢 Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. 🔲✨[ Player Warp: Set your own warp points for other players to teleport to. 🌟 Display Shop: Create your own shop and sell to other players! 🛒 Item Skins: Customize your items with unique skins. 🎨 Pets: Your cute loyal companion to follow you wherever you go! 🐾 Cosmetics: Enhance the look of your character with beautiful cosmetics! 💄 XP-Bottle: Store your exp safely in a bottle for later use! 🍶 Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! 📦 Glowing: Stand out from other players with a colorful glow! ✨ Player Particles: Over 100 unique particle effects to show off. 🎇 Portable Inventories: Over virtual inventories with ease. 🧳 And a lot more! Become part of our growing community today! Discord: https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working   I am not familiar with Linux - check for similar/related issues  
    • Create a new instance and start with Embeddium/Oculus and Valkyrien Skies Try different builds of Embeddium/Valkyrien Skies until you find a working combination - then add the rest of your mods one by one or in groups
  • Topics

×
×
  • Create New...

Important Information

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