Jump to content

Recommended Posts

Posted

Hello,

I'm trying to port my mod CraftingManager to 1.7.2, i read this tutorial for packets: http://www.minecraftforge.net/wiki/Tutorials/Packet_Handling

 

i did it almost the same way here are my classes

CraftingPacket

 

 

package com.creativemd.craftingmanager.common;

 

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map.Entry;

import java.util.Set;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.entity.player.EntityPlayer;

import io.netty.buffer.ByteBuf;

 

public abstract interface CraftingPacket {

 

    public abstract void readBytes(ByteBuf bytes);

    public abstract void writeBytes(ByteBuf bytes);

    public abstract void executeClient(EntityPlayer player);

    public abstract void executeServer(EntityPlayer player);

}

 

 

 

PacketDisabled

 

 

package com.creativemd.craftingmanager.common.packets;

 

import java.util.ArrayList;

import java.util.List;

 

import io.netty.buffer.ByteBuf;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.util.ChatComponentTranslation;

 

import com.creativemd.craftingmanager.common.CraftingPacket;

import com.creativemd.craftingmanager.core.CraftingManagerMod;

import com.creativemd.craftingmanager.core.RecipeHelper;

 

import cpw.mods.fml.common.network.ByteBufUtils;

import cpw.mods.fml.common.network.FMLOutboundHandler;

import cpw.mods.fml.relauncher.Side;

 

public class PacketDisabled implements CraftingPacket{

 

public String[] recipes;

 

public PacketDisabled(String[] recipes) {

this.recipes = recipes;

}

 

@Override

public void readBytes(ByteBuf bytes) {

int count = bytes.readInt();

recipes = new String[count];

for(int zahl = 0; zahl < recipes.length; zahl++)

recipes[zahl] = ByteBufUtils.readUTF8String(bytes);

 

//Save information

List disabled = new ArrayList();

for(int zahl = 0; zahl < recipes.length; zahl++)

disabled.add(recipes[zahl]);

CraftingManagerMod.disabledRecipes.clear();

for(int zahl = 0; zahl < CraftingManagerMod.allrecipes.size(); zahl++)

if(disabled.contains(RecipeHelper.RecipeToStringDisabled(CraftingManagerMod.allrecipes.get(zahl))))

CraftingManagerMod.disabledRecipes.add(CraftingManagerMod.allrecipes.get(zahl));

CraftingManagerMod.updateRecipes();

}

 

@Override

public void writeBytes(ByteBuf bytes) {

bytes.writeInt(recipes.length);

for(int zahl = 0; zahl < recipes.length; zahl++)

ByteBufUtils.writeUTF8String(bytes, recipes[zahl]);

}

 

@Override

public void executeClient(EntityPlayer player) {

player.addChatComponentMessage(new ChatComponentTranslation("Disabled " + recipes.length + " Recipes"));

}

 

@Override

public void executeServer(EntityPlayer player) {

PacketHandler.sendToAllPlayers(PacketHandler.getDisabledPacket());

}

 

}

 

 

 

Channel Register

 

 

channels = NetworkRegistry.INSTANCE.newChannel("CMPacket", new ChannelHandler());

 

 

 

Sending Packet

 

 

@SubscribeEvent

public void onPlayerLogin(PlayerLoggedInEvent event) {

if(event.player instanceof EntityPlayerMP)

{

if(((EntityPlayerMP) event.player).mcServer.isSinglePlayer())

CraftingManagerMod.instance.load(new FMLPostInitializationEvent(null, null));

PacketHandler.sendToPlayer(PacketHandler.getDisabledPacket(), event.player);

PacketHandler.sendToPlayer(PacketHandler.getAddedPacket(), event.player);

}

}

 

 

 

sendToPlayer & getDisabledPacket

 

 

public static PacketDisabled getDisabledPacket()

{

String[] recipes = new String[CraftingManagerMod.disabledRecipes.size()];

for(int zahl = 0; zahl < recipes.length; zahl++)

recipes[zahl] = RecipeHelper.RecipeToStringDisabled(CraftingManagerMod.disabledRecipes.get(zahl));

return new PacketDisabled(recipes);

}

public static void sendToPlayer(CraftingPacket packet, EntityPlayer player)

{

CraftingManagerMod.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);

CraftingManagerMod.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);

CraftingManagerMod.channels.get(Side.SERVER).writeOutbound(packet);

}

 

 

 

but something goes wrong :(, i have no idea why this error comes up:

 

 

[Client thread/ERROR] [FML]: There was a critical exception handling a packet on channel CMPacket

io.netty.handler.codec.DecoderException: java.lang.InstantiationException: com.creativemd.craftingmanager.common.packets.PacketDisabled

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:80) [FMLProxyPacket.class:?]

at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:232) [NetworkManager.class:?]

at net.minecraft.client.Minecraft.runTick(Minecraft.java:2118) [Minecraft.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:995) [Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:910) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:112) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?]

Caused by: java.lang.InstantiationException: com.creativemd.craftingmanager.common.packets.PacketDisabled

at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_25]

at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:73) ~[FMLIndexedMessageToMessageCodec.class:?]

at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:16) ~[FMLIndexedMessageToMessageCodec.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:?]

... 17 more

 

 

 

Can anyone help me? I tried everything, but this error comes up everytime :(

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



×
×
  • Create New...

Important Information

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