Jump to content

[1.7.10] EntityClientPlayerMP cannot be cast to EntityPlayerMP


gline9

Recommended Posts

I have created a gui for a block I made that only needs to transfer 1 integer worth of information over to the server and client tile entities. I thought that using IMessage and IMessageHandler would be useful in syncing the two tile entities but when I send the message it calls and index of -1 and won't send...

 

Here is my code:

 

Block class:

 

package com.gavincraft.blocks;

import java.util.Random;

import com.gavincraft.main.GavinCraft;
import com.gavincraft.tileentity.TileEntityAdvancedCatapult;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class AdvancedCatapult extends BlockContainer {
private boolean activeState = false;
public AdvancedCatapult(boolean active) {
	super(Material.piston);
	this.setStepSound(soundTypePiston);
	this.activeState=active;
}
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side){
	return true;
}
public void onBlockAdded(World world, int x, int y, int z)
    {
        if (!world.isRemote)
        {
            if (this.activeState && !world.isBlockIndirectlyGettingPowered(x, y, z))
            {
                world.scheduleBlockUpdate(x, y, z, this, this.tickRate(world));
            }
            else if (!this.activeState && world.isBlockIndirectlyGettingPowered(x, y, z))
            {
                world.setBlock(x, y, z, GavinCraft.active_advanced_catapult, 1, 2);
                this.activeState = true;
            }
        }
    }
public void updateTick(World world, int x, int y, int z, Random p_149674_5_)
    {
    	if (!world.isRemote && this.activeState && !world.isBlockIndirectlyGettingPowered(x, y, z))
        {
            world.setBlock(x, y, z, GavinCraft.advanced_catapult, 0, 2);
            this.activeState = false;
            
        }
    	if(!world.isRemote && this.activeState && world.isBlockIndirectlyGettingPowered(x, y, z)){
    		world.setBlock(x, y, z, GavinCraft.active_advanced_catapult, 1, 2);
    		this.activeState = true;
    	}
    	this.setLightLevel(world.getLightBrightness(x, y+1, z));
    }
public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
    {
	if (!world.isRemote)
        {
            if (this.activeState && !world.isBlockIndirectlyGettingPowered(x, y, z))
            {
            	world.scheduleBlockUpdate(x, y, z, this, this.tickRate(world));
            }
            else if (!this.activeState && world.isBlockIndirectlyGettingPowered(x, y, z))
            {
            	world.setBlock(x, y, z, GavinCraft.active_advanced_catapult, 1, 2);
            	this.activeState = true;
            }
        }
    }
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int metadata, float what, float are, float these ){
	TileEntity tileEntity = world.getTileEntity(x, y, z);
	if (player.isSneaking()||tileEntity == null){
		return false;
	}
	player.openGui(GavinCraft.instance, 20, world, x, y, z);
	return true;
}
public int tickRate(World world)
    {
        return activeState?1:2;
    }
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
	return new TileEntityAdvancedCatapult();
}

}

 

 

TileEntity class:

 

package com.gavincraft.tileentity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

public class TileEntityAdvancedCatapult extends TileEntity {
public int strength = 0;
public void updateEntity(){
	EntityPlayer person = (EntityPlayer) this.worldObj.getClosestPlayer(this.xCoord, this.yCoord, this.zCoord, 2);
	if (person != null && ((int)(Math.abs(person.posX-(person.posX<0?1:0)))) == Math.abs(xCoord) && person.posY -1 == yCoord  && ((int)(Math.abs(person.posZ-(person.posZ<0?1:0)))) == Math.abs(zCoord)){
		if (this.worldObj.getBlock(xCoord, yCoord, zCoord).tickRate(this.worldObj)==1){
			person.velocityChanged=true;
			person.setVelocity(0, strength/10, 0);
		}
	}
}
public void readFromNBT(NBTTagCompound tag){
	super.readFromNBT(tag);
	strength = tag.getInteger("strength");
}
public void writeToNBT(NBTTagCompound tag){
	super.writeToNBT(tag);
	tag.setInteger("strength", strength);
}
}

 

 

IMessage class:

 

package com.gavincraft.packet;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import cpw.mods.fml.common.network.simpleimpl.IMessage;

public class PacketAdvancedCatapult implements IMessage {
public int strength;
public int xPos;
public int yPos;
public int zPos;
public PacketAdvancedCatapult(int var1, int x, int y, int z){
	strength = var1;
	xPos = x;
	yPos = y;
	zPos = z;
}
public PacketAdvancedCatapult(){}
@Override
public void fromBytes(ByteBuf buf) {
	strength = buf.getInt(0);
	xPos = buf.getInt(0);
	yPos = buf.getInt(0);
	zPos = buf.getInt(0);
	System.out.println("message decoded");
}

@Override
public void toBytes(ByteBuf buf) {
	buf.setInt(0, strength);
	buf.setInt(0, xPos);
	buf.setInt(0, yPos);
	buf.setInt(0, zPos);
	System.out.println("message coded");
}

}

 

 

IMessageHandler class:

 

package com.gavincraft.packet.handler;

import com.gavincraft.packet.PacketAdvancedCatapult;
import com.gavincraft.tileentity.TileEntityAdvancedCatapult;

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 PacketHandlerAdvancedCatapult implements IMessageHandler<PacketAdvancedCatapult, IMessage> {
public PacketHandlerAdvancedCatapult(){}
@Override
public IMessage onMessage(PacketAdvancedCatapult message, MessageContext ctx) {
	System.out.println("message received");
	TileEntityAdvancedCatapult entity = (TileEntityAdvancedCatapult) ctx.getServerHandler().playerEntity.worldObj.getTileEntity(message.xPos, message.yPos, message.zPos);
	System.out.println("entity set");
	entity.strength = message.strength;
	return null;
}

}
[/spoiler]

 

Gui class:

 

package com.gavincraft.gui;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

import com.gavincraft.main.GavinCraft;
import com.gavincraft.packet.PacketAdvancedCatapult;
import com.gavincraft.tileentity.TileEntityAdvancedCatapult;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiScreenDemo;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.C17PacketCustomPayload;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public class GuiAdvancedCatapult extends GuiScreen {
public static final int GUI_ID = 20;
private static final ResourceLocation resource = new ResourceLocation("textures/gui/demo_background.png");
private int strength;
private ItemStack item;
private NBTTagCompound nbt;
private EntityPlayer player;
private World worldObj;
private int xPos;
private int yPos;
private int zPos;
public GuiAdvancedCatapult(EntityPlayer entityPlayer, ItemStack itemStack, World world, int x, int y, int z){
	worldObj = world;
	xPos = x;
	yPos = y;
	zPos = z;
	item = itemStack;
	player = entityPlayer;
	if (item.hasTagCompound()){
		NBTTagCompound nbt = item.getTagCompound();
		strength = nbt.getInteger("strength");
	}else{
		nbt = new NBTTagCompound();
		strength = 0;
	}
}
public void drawScreen(int par1, int par2, float par3) {
	this.mc.renderEngine.bindTexture(new ResourceLocation("gavincraft:/textures/gui/advancedcatapultgui.png"));
	this.drawDefaultBackground();
	int k = (this.width - 248) / 2 + 10;
        int l = (this.height - 166) / 2 + 8;
        this.fontRendererObj.drawString("Advanced Catapult", k, l, 2039583);
        this.fontRendererObj.drawString(String.valueOf(this.strength), k+100, l+66, 2039583);
        super.drawScreen(par1, par2, par3);
}
public void drawDefaultBackground()
    {
        super.drawDefaultBackground();
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(resource);
        int i = (this.width - 248) / 2;
        int j = (this.height - 166) / 2;
        this.drawTexturedModalRect(i, j, 0, 0, 248, 166);
    }
public void initGui()
    {
        this.buttonList.clear();
        byte b0 = -16;
        this.buttonList.add(new GuiButton(1, this.width / 2 - 116, this.height / 2 + b0, 40, 20, "+1"));
        this.buttonList.add(new GuiButton(2, this.width / 2 - 71, this.height / 2 + b0, 40, 20, "+10"));
        this.buttonList.add(new GuiButton(3, this.width / 2 + 31, this.height / 2 + b0, 40, 20, "-10"));
        this.buttonList.add(new GuiButton(4, this.width / 2 + 76, this.height / 2 + b0, 40, 20, "-1"));
        this.buttonList.add(new GuiButton(5, this.width / 2 - 116, this.height / 2 + 62 + b0, 100, 20, "Confirm"));
    }
protected void actionPerformed(GuiButton button){
	switch (button.id){
	case 1:{
		this.strength++;
		if (this.strength>100)
			this.strength=100;
		this.updateScreen();
		break;
	}
	case 2:{
		this.strength+=10;
		if (this.strength>100)
			this.strength=100;
		this.updateScreen();
		break;
	}
	case 3:{
		this.strength-=10;
		if (this.strength<0)
			this.strength=0;
		this.updateScreen();
		break;
	}
	case 4:{
		this.strength--;
		if (this.strength<0)
			this.strength=0;
		this.updateScreen();
		break;
	}
	case 5:{
		this.mc.displayGuiScreen((GuiScreen)null);
            this.mc.setIngameFocus();
	}
	}
}
public void onGuiClosed(){
	nbt.setInteger("strength", this.strength);
	if (this.item.hasTagCompound()){
		System.out.println("has tag compound");
            NBTTagCompound nbttagcompound = this.item.getTagCompound();
            nbttagcompound.setInteger("strength", this.strength);
        }else{
            this.item.setTagInfo("strength", this.nbt);
        }
	GavinCraft.channel.sendToServer(new PacketAdvancedCatapult(strength, xPos, yPos, zPos));
    }
}

 

 

my common proxy class

 

package com.gavincraft.main;

import com.gavincraft.gui.GuiAdvancedCatapult;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;

public class CommonProxy implements IGuiHandler {

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	if (ID == GuiAdvancedCatapult.GUI_ID){
		return new GuiAdvancedCatapult(player, new ItemStack(Item.getItemFromBlock(world.getBlock(x, y, z)), 1), world, x, y, z);
	}
	return null;
}

}

 

 

finally the main class:

 

package com.gavincraft.main;

import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

import com.gavincraft.blocks.AdjustmentCore;
import com.gavincraft.blocks.AdvancedCatapult;
import com.gavincraft.blocks.BigSpring;
import com.gavincraft.blocks.CamoflageCore;
import com.gavincraft.blocks.Casing;
import com.gavincraft.blocks.Catapult;
import com.gavincraft.blocks.Coil;
import com.gavincraft.blocks.Core;
import com.gavincraft.blocks.EnderShard;
import com.gavincraft.blocks.OpenBook;
import com.gavincraft.blocks.ReinforcedCasing;
import com.gavincraft.blocks.SemiSolidFloor;
import com.gavincraft.blocks.ShockAbsorber;
import com.gavincraft.blocks.Spring;
import com.gavincraft.blocks.TeleportCore;
import com.gavincraft.creativeTabs.GavinCraftTab;
import com.gavincraft.tileentity.TileEntityOpenBook;
import com.gavincraft.tileentity.TileEntitySemiSolidFloor;

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.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
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.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;

@Mod(modid = GavinCraft.MODID, version = GavinCraft.VERSION)
public class GavinCraft
{
@Instance(GavinCraft.MODID)
    public static GavinCraft instance;
@SidedProxy(clientSide="com.gavincraft.main.ClientProxy", serverSide="com.gavincraft.main.ServerProxy")
public static ServerProxy serverProxy;
public static CreativeTabs gavinCraftTab = new GavinCraftTab(CreativeTabs.getNextID(), "Gavin Craft");
public static SimpleNetworkWrapper channel;

    public static final String MODID = "gavincraft";
    public static final String VERSION = "0.0.0";
    public static Block catapult = new Catapult(false).setCreativeTab(gavinCraftTab).setBlockName("Catapult");
    public static Block active_catapult = new Catapult(true).setBlockName("Catapult");
    public static Item spring = new Spring().setCreativeTab(gavinCraftTab).setUnlocalizedName("Spring").setTextureName("gavincraft:spring");
    public static Item coil = new Coil().setCreativeTab(gavinCraftTab).setUnlocalizedName("Coil").setTextureName("gavincraft:coil");
    public static Block casing = new Casing().setCreativeTab(gavinCraftTab).setBlockName("Casing").setBlockTextureName("gavincraft:casing");
    public static Item big_spring = new BigSpring().setUnlocalizedName("Big_Spring").setCreativeTab(gavinCraftTab).setTextureName("gavincraft:big spring");
    public static Block reinforced_casing = new ReinforcedCasing().setBlockName("Reinforced_Casing").setCreativeTab(gavinCraftTab).setBlockTextureName("gavincraft:reinforced casing");
    public static Block shock_absorber = new ShockAbsorber().setBlockName("Shock_Absorber").setCreativeTab(gavinCraftTab).setBlockTextureName("gavincraft:shockabsorber");
    public static Item teleport_core = new TeleportCore().setUnlocalizedName("Teleport_Core").setCreativeTab(gavinCraftTab).setTextureName("gavincraft:teleport core");
    public static Block open_book = new OpenBook().setBlockName("Open_Book").setCreativeTab(gavinCraftTab);
    public static Block semi_solid_floor = new SemiSolidFloor().setBlockName("Semi-Solid_Floor").setCreativeTab(gavinCraftTab).setBlockTextureName("gavincraft:semisolidfloor");
    public static Item ender_shard = new EnderShard().setUnlocalizedName("Ender_Shard").setCreativeTab(gavinCraftTab).setTextureName("gavincraft:ender shard");
    public static Item core = new Core().setUnlocalizedName("Core").setCreativeTab(gavinCraftTab).setTextureName("gavincraft:core");
    public static Item camoflage_core = new CamoflageCore().setUnlocalizedName("Camoflage_Core").setCreativeTab(gavinCraftTab).setTextureName("gavincraft:camoflage core");
    public static Block advanced_catapult = new AdvancedCatapult(false).setBlockName("Advanced_Catapult").setCreativeTab(gavinCraftTab);
    public static Block active_advanced_catapult = new AdvancedCatapult(true).setBlockName("Advanced_Catapult");
    public static Item adjustment_core = new AdjustmentCore().setUnlocalizedName("Adjustment_Core").setCreativeTab(gavinCraftTab);
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event){
    	serverProxy.registerRenderThings();
    	channel = NetworkRegistry.INSTANCE.newSimpleChannel(GavinCraft.MODID);
    	channel.registerMessage(com.gavincraft.packet.handler.PacketHandlerAdvancedCatapult.class, com.gavincraft.packet.PacketAdvancedCatapult.class, 0, Side.SERVER);
    	
    	GameRegistry.registerBlock(catapult, "catapult");
    	GameRegistry.registerItem(spring, "Spring");
    	GameRegistry.registerItem(coil, "Coil");
    	GameRegistry.registerBlock(casing, "Casing");
    	GameRegistry.registerItem(big_spring, "Big_Spring");
    	GameRegistry.registerBlock(reinforced_casing, "Reinforced_Casing");
    	GameRegistry.registerBlock(shock_absorber, "Shock_Absorber");
    	GameRegistry.registerItem(teleport_core, "Teleport_Core");
    	GameRegistry.registerBlock(open_book, "Open Book");
    	GameRegistry.registerBlock(semi_solid_floor, "Semi-Solid_Floor");
    	GameRegistry.registerTileEntity(TileEntityOpenBook.class, "Open_Book");
    	GameRegistry.registerBlock(active_catapult, "Active_Catapult");
    	GameRegistry.registerItem(ender_shard, "Ender_Shard");
    	GameRegistry.registerItem(core, "Core");
    	GameRegistry.registerItem(camoflage_core, "Camoflage_Core");
    	GameRegistry.registerBlock(advanced_catapult, "Advanced_Catapult");
    	GameRegistry.registerBlock(active_advanced_catapult, "Active_Advanced_Catapult");
    	GameRegistry.registerItem(adjustment_core, "Adjustment_Core");
    	
    	
    	GameRegistry.addRecipe(new ItemStack(Blocks.vine), new Object[]{
    		"xxx",
    		"xyx",
    		"xxx",
    		'x', Items.wheat, 'y', Blocks.dirt});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.coil, 9), new Object[]{
    		"xxx",
    		"x x",
    		"xxx",
    		'x', Items.iron_ingot});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.spring), new Object[]{
    		"xxx",
    		'x', GavinCraft.coil});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.casing, 2), new Object[]{
    		"xxx",
    		"xyx",
    		"xxx",
    		'x', Blocks.stone, 'y', Items.iron_ingot});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.catapult), new Object[]{
    		"xxx",
    		"yzy",
    		"ywy",
    		'x', Blocks.piston, 'y', GavinCraft.casing, 'z', GavinCraft.spring, 'w', Items.redstone});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.big_spring, 2), new Object[]{
    		"xxx",
    		"yyy",
    		"xxx",
    		'x', Items.gold_ingot,'y', GavinCraft.spring});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.reinforced_casing, 2), new Object[]{
    		"yxy",
    		"x x",
    		"yxy",
    		'x', GavinCraft.casing, 'y', Blocks.obsidian});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.shock_absorber), new Object[]{
    		"xxx",
    		"yyy",
    		"xxx",
    		'x', Blocks.wool, 'y', GavinCraft.spring});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.teleport_core, 1), new Object[]{
    		"xyx",
    		"yzy",
    		"xyx",
    		'x', Items.glowstone_dust, 'y', GavinCraft.casing, 'z', GavinCraft.core});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.semi_solid_floor, 1), new Object[]{
    		"xwx",
    		"zuz",
    		"xyx",
    		'x', GavinCraft.casing, 'y', GavinCraft.teleport_core, 'z', Items.iron_ingot, 'w', GavinCraft.shock_absorber, 'u', GavinCraft.camoflage_core});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.ender_shard, , new Object[]{
    		"x",
    		'x', Items.ender_pearl
    	});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.core, 1), new Object[]{
    		"xyx",
    		"yzy",
    		"xyx",
    		'x', Items.redstone, 'y', GavinCraft.ender_shard, 'z', GavinCraft.casing
    	});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.camoflage_core, 1), new Object[]{
    		" x ",
    		"yzw",
    		" u ",
    		'x',new ItemStack(Items.dye, 1, 1), 'y', new ItemStack(Items.dye, 1, 2), 'z', GavinCraft.core, 'w', new ItemStack(Items.dye, 1, 4), 'u', new ItemStack(Items.dye, 1, 0)
    	});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.adjustment_core, 1), new Object[]{
    		"xyx",
    		"yzy",
    		"xyx",
    		'x', GavinCraft.coil, 'y', GavinCraft.spring, 'z', GavinCraft.core
    	});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.advanced_catapult, 1), new Object[]{
    		" x ",
    		"yzy",
    		"ywy",
    		'x', GavinCraft.catapult, 'y', GavinCraft.reinforced_casing, 'z', GavinCraft.big_spring, 'w', GavinCraft.adjustment_core
    	});
    }
    
    @EventHandler
    public void load(FMLInitializationEvent event){
    	NetworkRegistry.INSTANCE.registerGuiHandler(instance, new CommonProxy());
    	GameRegistry.registerTileEntity(com.gavincraft.tileentity.TileEntitySemiSolidFloor.class, "Semi_Solid_Floor_Tile_Entity");
    	GameRegistry.registerTileEntity(com.gavincraft.tileentity.TileEntityCatapult.class, "Catapult_Tile_Entity");
    	GameRegistry.registerTileEntity(com.gavincraft.tileentity.TileEntityAdvancedCatapult.class, "Advanced_Catapult_Tile_Entity");
    }
    @EventHandler
    public void postinit(FMLPostInitializationEvent event){
    }
}

 

 

and here is the error log that I am getting.

 

 

 

io.netty.handler.codec.DecoderException: java.lang.NullPointerException: Undefined message for discriminator -1 in channel gavincraft

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

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

at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]

Caused by: java.lang.NullPointerException: Undefined message for discriminator -1 in channel gavincraft

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

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

... 13 more

[18:11:10] [server thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception

io.netty.handler.codec.DecoderException: java.lang.NullPointerException: Undefined message for discriminator -1 in channel gavincraft

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

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

at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]

Caused by: java.lang.NullPointerException: Undefined message for discriminator -1 in channel gavincraft

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

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

... 13 more

[18:11:10] [server thread/ERROR] [FML]: There was a critical exception handling a packet on channel gavincraft

io.netty.handler.codec.DecoderException: java.lang.NullPointerException: Undefined message for discriminator -1 in channel gavincraft

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

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

at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]

Caused by: java.lang.NullPointerException: Undefined message for discriminator -1 in channel gavincraft

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

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

... 13 more

 

 

 

If you need any additional info please let me know.

Link to comment
Share on other sites

For some reason the rest of the message didn't add

 

Gui class:

 

package com.gavincraft.gui;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

import com.gavincraft.main.GavinCraft;
import com.gavincraft.packet.PacketAdvancedCatapult;
import com.gavincraft.tileentity.TileEntityAdvancedCatapult;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiScreenDemo;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.C17PacketCustomPayload;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public class GuiAdvancedCatapult extends GuiScreen {
public static final int GUI_ID = 20;
private static final ResourceLocation resource = new ResourceLocation("textures/gui/demo_background.png");
private int strength;
private ItemStack item;
private NBTTagCompound nbt;
private EntityPlayer player;
private World worldObj;
private int xPos;
private int yPos;
private int zPos;
public GuiAdvancedCatapult(EntityPlayer entityPlayer, ItemStack itemStack, World world, int x, int y, int z){
	worldObj = world;
	xPos = x;
	yPos = y;
	zPos = z;
	item = itemStack;
	player = entityPlayer;
	if (item.hasTagCompound()){
		NBTTagCompound nbt = item.getTagCompound();
		strength = nbt.getInteger("strength");
	}else{
		nbt = new NBTTagCompound();
		strength = 0;
	}
}
public void drawScreen(int par1, int par2, float par3) {
	this.mc.renderEngine.bindTexture(new ResourceLocation("gavincraft:/textures/gui/advancedcatapultgui.png"));
	this.drawDefaultBackground();
	int k = (this.width - 248) / 2 + 10;
        int l = (this.height - 166) / 2 + 8;
        this.fontRendererObj.drawString("Advanced Catapult", k, l, 2039583);
        this.fontRendererObj.drawString(String.valueOf(this.strength), k+100, l+66, 2039583);
        super.drawScreen(par1, par2, par3);
}
public void drawDefaultBackground()
    {
        super.drawDefaultBackground();
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(resource);
        int i = (this.width - 248) / 2;
        int j = (this.height - 166) / 2;
        this.drawTexturedModalRect(i, j, 0, 0, 248, 166);
    }
public void initGui()
    {
        this.buttonList.clear();
        byte b0 = -16;
        this.buttonList.add(new GuiButton(1, this.width / 2 - 116, this.height / 2 + b0, 40, 20, "+1"));
        this.buttonList.add(new GuiButton(2, this.width / 2 - 71, this.height / 2 + b0, 40, 20, "+10"));
        this.buttonList.add(new GuiButton(3, this.width / 2 + 31, this.height / 2 + b0, 40, 20, "-10"));
        this.buttonList.add(new GuiButton(4, this.width / 2 + 76, this.height / 2 + b0, 40, 20, "-1"));
        this.buttonList.add(new GuiButton(5, this.width / 2 - 116, this.height / 2 + 62 + b0, 100, 20, "Confirm"));
    }
protected void actionPerformed(GuiButton button){
	switch (button.id){
	case 1:{
		this.strength++;
		if (this.strength>100)
			this.strength=100;
		this.updateScreen();
		break;
	}
	case 2:{
		this.strength+=10;
		if (this.strength>100)
			this.strength=100;
		this.updateScreen();
		break;
	}
	case 3:{
		this.strength-=10;
		if (this.strength<0)
			this.strength=0;
		this.updateScreen();
		break;
	}
	case 4:{
		this.strength--;
		if (this.strength<0)
			this.strength=0;
		this.updateScreen();
		break;
	}
	case 5:{
		this.mc.displayGuiScreen((GuiScreen)null);
            this.mc.setIngameFocus();
	}
	}
}
public void onGuiClosed(){
	nbt.setInteger("strength", this.strength);
	if (this.item.hasTagCompound()){
		System.out.println("has tag compound");
            NBTTagCompound nbttagcompound = this.item.getTagCompound();
            nbttagcompound.setInteger("strength", this.strength);
        }else{
            this.item.setTagInfo("strength", this.nbt);
        }
	GavinCraft.channel.sendToServer(new PacketAdvancedCatapult(strength, xPos, yPos, zPos));
    }
}

 

 

my common proxy class

 

package com.gavincraft.main;

import com.gavincraft.gui.GuiAdvancedCatapult;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;

public class CommonProxy implements IGuiHandler {

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	if (ID == GuiAdvancedCatapult.GUI_ID){
		return new GuiAdvancedCatapult(player, new ItemStack(Item.getItemFromBlock(world.getBlock(x, y, z)), 1), world, x, y, z);
	}
	return null;
}

}

 

 

finally the main class:

 

package com.gavincraft.main;

import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

import com.gavincraft.blocks.AdjustmentCore;
import com.gavincraft.blocks.AdvancedCatapult;
import com.gavincraft.blocks.BigSpring;
import com.gavincraft.blocks.CamoflageCore;
import com.gavincraft.blocks.Casing;
import com.gavincraft.blocks.Catapult;
import com.gavincraft.blocks.Coil;
import com.gavincraft.blocks.Core;
import com.gavincraft.blocks.EnderShard;
import com.gavincraft.blocks.OpenBook;
import com.gavincraft.blocks.ReinforcedCasing;
import com.gavincraft.blocks.SemiSolidFloor;
import com.gavincraft.blocks.ShockAbsorber;
import com.gavincraft.blocks.Spring;
import com.gavincraft.blocks.TeleportCore;
import com.gavincraft.creativeTabs.GavinCraftTab;
import com.gavincraft.tileentity.TileEntityOpenBook;
import com.gavincraft.tileentity.TileEntitySemiSolidFloor;

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.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
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.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;

@Mod(modid = GavinCraft.MODID, version = GavinCraft.VERSION)
public class GavinCraft
{
@Instance(GavinCraft.MODID)
    public static GavinCraft instance;
@SidedProxy(clientSide="com.gavincraft.main.ClientProxy", serverSide="com.gavincraft.main.ServerProxy")
public static ServerProxy serverProxy;
public static CreativeTabs gavinCraftTab = new GavinCraftTab(CreativeTabs.getNextID(), "Gavin Craft");
public static SimpleNetworkWrapper channel;

    public static final String MODID = "gavincraft";
    public static final String VERSION = "0.0.0";
    public static Block catapult = new Catapult(false).setCreativeTab(gavinCraftTab).setBlockName("Catapult");
    public static Block active_catapult = new Catapult(true).setBlockName("Catapult");
    public static Item spring = new Spring().setCreativeTab(gavinCraftTab).setUnlocalizedName("Spring").setTextureName("gavincraft:spring");
    public static Item coil = new Coil().setCreativeTab(gavinCraftTab).setUnlocalizedName("Coil").setTextureName("gavincraft:coil");
    public static Block casing = new Casing().setCreativeTab(gavinCraftTab).setBlockName("Casing").setBlockTextureName("gavincraft:casing");
    public static Item big_spring = new BigSpring().setUnlocalizedName("Big_Spring").setCreativeTab(gavinCraftTab).setTextureName("gavincraft:big spring");
    public static Block reinforced_casing = new ReinforcedCasing().setBlockName("Reinforced_Casing").setCreativeTab(gavinCraftTab).setBlockTextureName("gavincraft:reinforced casing");
    public static Block shock_absorber = new ShockAbsorber().setBlockName("Shock_Absorber").setCreativeTab(gavinCraftTab).setBlockTextureName("gavincraft:shockabsorber");
    public static Item teleport_core = new TeleportCore().setUnlocalizedName("Teleport_Core").setCreativeTab(gavinCraftTab).setTextureName("gavincraft:teleport core");
    public static Block open_book = new OpenBook().setBlockName("Open_Book").setCreativeTab(gavinCraftTab);
    public static Block semi_solid_floor = new SemiSolidFloor().setBlockName("Semi-Solid_Floor").setCreativeTab(gavinCraftTab).setBlockTextureName("gavincraft:semisolidfloor");
    public static Item ender_shard = new EnderShard().setUnlocalizedName("Ender_Shard").setCreativeTab(gavinCraftTab).setTextureName("gavincraft:ender shard");
    public static Item core = new Core().setUnlocalizedName("Core").setCreativeTab(gavinCraftTab).setTextureName("gavincraft:core");
    public static Item camoflage_core = new CamoflageCore().setUnlocalizedName("Camoflage_Core").setCreativeTab(gavinCraftTab).setTextureName("gavincraft:camoflage core");
    public static Block advanced_catapult = new AdvancedCatapult(false).setBlockName("Advanced_Catapult").setCreativeTab(gavinCraftTab);
    public static Block active_advanced_catapult = new AdvancedCatapult(true).setBlockName("Advanced_Catapult");
    public static Item adjustment_core = new AdjustmentCore().setUnlocalizedName("Adjustment_Core").setCreativeTab(gavinCraftTab);
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event){
    	serverProxy.registerRenderThings();
    	channel = NetworkRegistry.INSTANCE.newSimpleChannel(GavinCraft.MODID);
    	channel.registerMessage(com.gavincraft.packet.handler.PacketHandlerAdvancedCatapult.class, com.gavincraft.packet.PacketAdvancedCatapult.class, 0, Side.SERVER);
    	
    	GameRegistry.registerBlock(catapult, "catapult");
    	GameRegistry.registerItem(spring, "Spring");
    	GameRegistry.registerItem(coil, "Coil");
    	GameRegistry.registerBlock(casing, "Casing");
    	GameRegistry.registerItem(big_spring, "Big_Spring");
    	GameRegistry.registerBlock(reinforced_casing, "Reinforced_Casing");
    	GameRegistry.registerBlock(shock_absorber, "Shock_Absorber");
    	GameRegistry.registerItem(teleport_core, "Teleport_Core");
    	GameRegistry.registerBlock(open_book, "Open Book");
    	GameRegistry.registerBlock(semi_solid_floor, "Semi-Solid_Floor");
    	GameRegistry.registerTileEntity(TileEntityOpenBook.class, "Open_Book");
    	GameRegistry.registerBlock(active_catapult, "Active_Catapult");
    	GameRegistry.registerItem(ender_shard, "Ender_Shard");
    	GameRegistry.registerItem(core, "Core");
    	GameRegistry.registerItem(camoflage_core, "Camoflage_Core");
    	GameRegistry.registerBlock(advanced_catapult, "Advanced_Catapult");
    	GameRegistry.registerBlock(active_advanced_catapult, "Active_Advanced_Catapult");
    	GameRegistry.registerItem(adjustment_core, "Adjustment_Core");
    	
    	
    	GameRegistry.addRecipe(new ItemStack(Blocks.vine), new Object[]{
    		"xxx",
    		"xyx",
    		"xxx",
    		'x', Items.wheat, 'y', Blocks.dirt});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.coil, 9), new Object[]{
    		"xxx",
    		"x x",
    		"xxx",
    		'x', Items.iron_ingot});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.spring), new Object[]{
    		"xxx",
    		'x', GavinCraft.coil});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.casing, 2), new Object[]{
    		"xxx",
    		"xyx",
    		"xxx",
    		'x', Blocks.stone, 'y', Items.iron_ingot});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.catapult), new Object[]{
    		"xxx",
    		"yzy",
    		"ywy",
    		'x', Blocks.piston, 'y', GavinCraft.casing, 'z', GavinCraft.spring, 'w', Items.redstone});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.big_spring, 2), new Object[]{
    		"xxx",
    		"yyy",
    		"xxx",
    		'x', Items.gold_ingot,'y', GavinCraft.spring});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.reinforced_casing, 2), new Object[]{
    		"yxy",
    		"x x",
    		"yxy",
    		'x', GavinCraft.casing, 'y', Blocks.obsidian});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.shock_absorber), new Object[]{
    		"xxx",
    		"yyy",
    		"xxx",
    		'x', Blocks.wool, 'y', GavinCraft.spring});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.teleport_core, 1), new Object[]{
    		"xyx",
    		"yzy",
    		"xyx",
    		'x', Items.glowstone_dust, 'y', GavinCraft.casing, 'z', GavinCraft.core});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.semi_solid_floor, 1), new Object[]{
    		"xwx",
    		"zuz",
    		"xyx",
    		'x', GavinCraft.casing, 'y', GavinCraft.teleport_core, 'z', Items.iron_ingot, 'w', GavinCraft.shock_absorber, 'u', GavinCraft.camoflage_core});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.ender_shard, , new Object[]{
    		"x",
    		'x', Items.ender_pearl
    	});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.core, 1), new Object[]{
    		"xyx",
    		"yzy",
    		"xyx",
    		'x', Items.redstone, 'y', GavinCraft.ender_shard, 'z', GavinCraft.casing
    	});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.camoflage_core, 1), new Object[]{
    		" x ",
    		"yzw",
    		" u ",
    		'x',new ItemStack(Items.dye, 1, 1), 'y', new ItemStack(Items.dye, 1, 2), 'z', GavinCraft.core, 'w', new ItemStack(Items.dye, 1, 4), 'u', new ItemStack(Items.dye, 1, 0)
    	});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.adjustment_core, 1), new Object[]{
    		"xyx",
    		"yzy",
    		"xyx",
    		'x', GavinCraft.coil, 'y', GavinCraft.spring, 'z', GavinCraft.core
    	});
    	GameRegistry.addRecipe(new ItemStack(GavinCraft.advanced_catapult, 1), new Object[]{
    		" x ",
    		"yzy",
    		"ywy",
    		'x', GavinCraft.catapult, 'y', GavinCraft.reinforced_casing, 'z', GavinCraft.big_spring, 'w', GavinCraft.adjustment_core
    	});
    }
    
    @EventHandler
    public void load(FMLInitializationEvent event){
    	NetworkRegistry.INSTANCE.registerGuiHandler(instance, new CommonProxy());
    	GameRegistry.registerTileEntity(com.gavincraft.tileentity.TileEntitySemiSolidFloor.class, "Semi_Solid_Floor_Tile_Entity");
    	GameRegistry.registerTileEntity(com.gavincraft.tileentity.TileEntityCatapult.class, "Catapult_Tile_Entity");
    	GameRegistry.registerTileEntity(com.gavincraft.tileentity.TileEntityAdvancedCatapult.class, "Advanced_Catapult_Tile_Entity");
    }
    @EventHandler
    public void postinit(FMLPostInitializationEvent event){
    }
}

 

 

and here is the error log that I am getting.

 

 

 

io.netty.handler.codec.DecoderException: java.lang.NullPointerException: Undefined message for discriminator -1 in channel gavincraft

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

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

at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]

Caused by: java.lang.NullPointerException: Undefined message for discriminator -1 in channel gavincraft

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

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

... 13 more

[18:11:10] [server thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception

io.netty.handler.codec.DecoderException: java.lang.NullPointerException: Undefined message for discriminator -1 in channel gavincraft

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

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

at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]

Caused by: java.lang.NullPointerException: Undefined message for discriminator -1 in channel gavincraft

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

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

... 13 more

[18:11:10] [server thread/ERROR] [FML]: There was a critical exception handling a packet on channel gavincraft

io.netty.handler.codec.DecoderException: java.lang.NullPointerException: Undefined message for discriminator -1 in channel gavincraft

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

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

at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]

Caused by: java.lang.NullPointerException: Undefined message for discriminator -1 in channel gavincraft

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

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

... 13 more

 

 

 

If you need any additional info please let me know.

Link to comment
Share on other sites

Thank you guys so much for your help. My tileentity saves the data now to the server using a combination of the two ideas :) Unfortunately whenever I change the redstone state of the block, the tile entity data for the block disappears. I am using the same methods for using redstone as the redstone lamp uses. Does anyone know of a way of keeping the same tile entity data with that block when replacing the block? Here are the classes that I changed for anyone interested in how I solved the previous problem.

 

Tile Entity Class:

 

package com.gavincraft.tileentity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;

public class TileEntityAdvancedCatapult extends TileEntity {
public int strength = 0;
public void updateEntity(){
	EntityPlayer person = (EntityPlayer) this.worldObj.getClosestPlayer(this.xCoord, this.yCoord, this.zCoord, 2);
	if (person != null && ((int)(Math.abs(person.posX-(person.posX<0?1:0)))) == Math.abs(xCoord) && person.posY -1 == yCoord  && ((int)(Math.abs(person.posZ-(person.posZ<0?1:0)))) == Math.abs(zCoord) && this.strength!=9){
		if (this.worldObj.getBlock(xCoord, yCoord, zCoord).tickRate(this.worldObj)==1){
			person.velocityChanged=true;
			person.setVelocity(0, (double)strength/10, 0);
		}
	}
}
public void readFromNBT(NBTTagCompound tag){
	super.readFromNBT(tag);
	strength = tag.getInteger("strength");
}
public void writeToNBT(NBTTagCompound tag){
	super.writeToNBT(tag);
	tag.setInteger("strength", strength);
}
 @Override
 public Packet getDescriptionPacket(){
	 System.out.println("sending description packet");
	 System.out.println(this.strength);
	 NBTTagCompound syncData = new NBTTagCompound();
	 this.writeToNBT(syncData);
	 return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, syncData);
 }
 @Override
 public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt){
	 System.out.println("received description packet");
     readFromNBT(pkt.func_148857_g());
     System.out.println(this.strength);
 }
}

 

 

IMessage Class:

 

 

package com.gavincraft.packet;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import cpw.mods.fml.common.network.simpleimpl.IMessage;

public class PacketAdvancedCatapult implements IMessage {
public int strength;
public int xPos;
public int yPos;
public int zPos;
public PacketAdvancedCatapult(int var1, int x, int y, int z){
	strength = var1;
	xPos = x;
	yPos = y;
	zPos = z;
}
public PacketAdvancedCatapult(){}
@Override
public void fromBytes(ByteBuf buf) {
	strength = buf.readInt();
	xPos = buf.readInt();
	yPos = buf.readInt();
	zPos = buf.readInt();
	System.out.println("message decoded");
}

@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(strength);
	buf.writeInt(xPos);
	buf.writeInt(yPos);
	buf.writeInt(zPos);
	System.out.println("message coded");
}

}

 

 

Gui Class:

 

package com.gavincraft.gui;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

import com.gavincraft.main.GavinCraft;
import com.gavincraft.packet.PacketAdvancedCatapult;
import com.gavincraft.tileentity.TileEntityAdvancedCatapult;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiScreenDemo;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.C17PacketCustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public class GuiAdvancedCatapult extends GuiScreen {
public static final int GUI_ID = 20;
private static final ResourceLocation resource = new ResourceLocation("textures/gui/demo_background.png");
private int strength;
private TileEntityAdvancedCatapult tile;
public GuiAdvancedCatapult(TileEntity entity){
	tile = (TileEntityAdvancedCatapult)entity;
	strength = tile.strength;
}
public void drawScreen(int par1, int par2, float par3) {
	this.mc.renderEngine.bindTexture(new ResourceLocation("gavincraft:/textures/gui/advancedcatapultgui.png"));
	this.drawDefaultBackground();
	int k = (this.width - 248) / 2 + 10;
        int l = (this.height - 166) / 2 + 8;
        this.fontRendererObj.drawString("Advanced Catapult", k, l, 2039583);
        this.fontRendererObj.drawString(String.valueOf(this.strength), k+100, l+66, 2039583);
        super.drawScreen(par1, par2, par3);
}
public void drawDefaultBackground()
    {
        super.drawDefaultBackground();
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(resource);
        int i = (this.width - 248) / 2;
        int j = (this.height - 166) / 2;
        this.drawTexturedModalRect(i, j, 0, 0, 248, 166);
    }
public void initGui()
    {
        this.buttonList.clear();
        byte b0 = -16;
        this.buttonList.add(new GuiButton(1, this.width / 2 - 116, this.height / 2 + b0, 40, 20, "+1"));
        this.buttonList.add(new GuiButton(2, this.width / 2 - 71, this.height / 2 + b0, 40, 20, "+10"));
        this.buttonList.add(new GuiButton(3, this.width / 2 + 31, this.height / 2 + b0, 40, 20, "-10"));
        this.buttonList.add(new GuiButton(4, this.width / 2 + 76, this.height / 2 + b0, 40, 20, "-1"));
        this.buttonList.add(new GuiButton(5, this.width / 2 - 116, this.height / 2 + 62 + b0, 100, 20, "Confirm"));
    }
protected void actionPerformed(GuiButton button){
	switch (button.id){
	case 1:{
		this.strength++;
		if (this.strength>100)
			this.strength=100;
		this.updateScreen();
		break;
	}
	case 2:{
		this.strength+=10;
		if (this.strength>100)
			this.strength=100;
		this.updateScreen();
		break;
	}
	case 3:{
		this.strength-=10;
		if (this.strength<0)
			this.strength=0;
		this.updateScreen();
		break;
	}
	case 4:{
		this.strength--;
		if (this.strength<0)
			this.strength=0;
		this.updateScreen();
		break;
	}
	case 5:{
		this.mc.displayGuiScreen((GuiScreen)null);
            this.mc.setIngameFocus();
	}
	}
}
public void onGuiClosed(){
	tile.strength = this.strength;
	GavinCraft.channel.sendToServer(new PacketAdvancedCatapult(strength, tile.xCoord, tile.yCoord, tile.zCoord));
	System.out.println(tile.getWorldObj().isRemote);
    }
}

 

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

    • where opportunities abound and promises of financial prosperity beckon from every corner of the internet, the line between opportunity and deception becomes increasingly blurred. As a 38-year-old single mom, I embarked on a journey into the world of cryptocurrency investing, hoping to secure a brighter future for myself and my family. Little did I know, this journey would lead me down a treacherous path fraught with deception and heartbreak. My foray into cryptocurrency investing began with the promise of lucrative returns from a platform claiming to operate within Europe and South Asia. Blinded by optimism and the allure of financial gain, I entrusted my hard-earned savings to this fraudulent company, believing wholeheartedly in its legitimacy. However, my hopes were dashed when I began encountering difficulties with withdrawals and found myself entangled in a web of exorbitant fees and dubious practices. In a desperate bid to salvage what remained of my investment, I turned to a recovery company recommended to me by the very platform that had deceived me. Yet, even in my darkest hour, the deceit persisted, as I soon discovered that the company tasked with recovering my funds was complicit in the deception. Faced with the crushing realization that I had been betrayed once again, I felt a sense of hopelessness engulf me. It was in this moment of despair that I stumbled upon Lee Ultimate Hacker – a shining beacon of hope amidst the darkness of deception. Through a stroke of luck, I came across a blog post singing the praises of this remarkable team, and I knew I had found my savior. With nothing left to lose and everything to gain, I reached out to them, hoping against hope for a chance at redemption. From the outset, Lee Ultimate Hacker proved to be a guiding light in my journey toward financial recovery. Their professionalism, expertise, and unwavering commitment to client satisfaction set them apart from the myriad of recovery services in the digital sphere. With empathy and understanding, they listened to my story and embarked on a mission to reclaim what was rightfully mine. Through their diligent efforts and meticulous attention to detail, Lee Ultimate Hacker succeeded where others had failed, restoring a sense of hope and security in the wake of betrayal. Their dedication to justice and unwavering determination to deliver results ensured that I emerged from the ordeal stronger and more resilient than ever before. Throughout the recovery process, their team remained accessible, transparent, and supportive, offering guidance and reassurance every step of the way. To anyone grappling with devastating financial fraud, I offer a lifeline of hope – trust in Lee Ultimate Hacker to guide you through the storm with expertise and compassion. In a world rife with deception and uncertainty, they stand as a beacon of reliability and trustworthiness, ready to lead you toward financial restitution and a brighter future. If you find yourself in a similar predicament, do not hesitate to reach out to Lee Ultimate Hacker.AT LEEULTIMATEHACKER@ AOL. COM   Support @ leeultimatehacker . com.  telegram:LEEULTIMATE   wh@tsapp +1  (715) 314  -  9248  https://leeultimatehacker.com
    • Sorry, this is the report https://paste.ee/p/OeDj1
    • Please share a link to your crash report on https://paste.ee, as explained in the FAQ
    • This is the crash report [User dumped their crash report directly in their thread, triggering the anti-spam]  
    • Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
  • Topics

×
×
  • Create New...

Important Information

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