Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

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

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

Featured Replies

Posted

I have a custom item that gets summoned into the world as an EntityItem with a bunch of lightning when a key is pressed. That works, but when the item is spawned I can't pick it up. Here is my summoning code:

EntityItem item = new EntityItem(player.worldObj, player.posX, player.posY - 1, player.posZ - 4, new ItemStack(Lumina.lumicon));
            
player.worldObj.spawnEntityInWorld(item);

 

Why is this happening?

I dunno. What should I be summoning it on? I didn't specify in my code.

Now that I think of it, I think it's on client side, I'm using a key binding to spawn it and if I'm correct key bindings are on client side.

I have no experience with packets. :) How do I do that?

Ok, and how would I use that to fix the ghost item?

your problem right now is that u are spawning the item on the client side. which is wrong because it needs to be on the server side. so if the key is pressed send a packet to the server which tells him to spawn an item at a desired location (you should transmit the location via the packet..)

This example is not thread safe and might kill a server. Just so you know.

Both that code and this thread are for 1.7.10, in which the network was still on the main thread.

 

@TheRealMcrafter - if you're going to verbatim copy / paste code from a tutorial (you didn't even remove my comments!), it's considerate of you to write a note in the code saying where you got it from, i.e. giving credit where credit is due.

your problem right now is that u are spawning the item on the client side. which is wrong because it needs to be on the server side. so if the key is pressed send a packet to the server which tells him to spawn an item at a desired location (you should transmit the location via the packet..)

 

That might be why the explosion didn't work either. I had lightning strikes then an explosion then the item spawned. That's how I coded it. The explosion worked, but when I jumped in to collect the item, my player started shaking like it does when the block looks like it's not there but it actually was. So the same thing with server and client side goes for explosions, right?

 

I'm away from my code right now, I'll try to figure out packets in the morning.

This example is not thread safe and might kill a server. Just so you know.

Both that code and this thread are for 1.7.10, in which the network was still on the main thread.

 

@TheRealMcrafter - if you're going to verbatim copy / paste code from a tutorial (you didn't even remove my comments!), it's considerate of you to write a note in the code saying where you got it from, i.e. giving credit where credit is due.

 

Oh dammit you are right, Im sorry

Ok, I've been messing with packets and I got this when I clicked the key:

width=800 height=5309WC6x7X.png?1 [/img]

I also got a crash log:

 

 

io.netty.handler.codec.DecoderException: java.lang.InstantiationException: awesomespider.lumina.Packets.LumiconSpawnPacket
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.InstantiationException: awesomespider.lumina.Packets.LumiconSpawnPacket
at java.lang.Class.newInstance0(Class.java:357) ~[?:1.7.0_07]
at java.lang.Class.newInstance(Class.java:325) ~[?:1.7.0_07]
at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:75) ~[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
[09:40:56] [server thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception
io.netty.handler.codec.DecoderException: java.lang.InstantiationException: awesomespider.lumina.Packets.LumiconSpawnPacket
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.InstantiationException: awesomespider.lumina.Packets.LumiconSpawnPacket
at java.lang.Class.newInstance0(Class.java:357) ~[?:1.7.0_07]
at java.lang.Class.newInstance(Class.java:325) ~[?:1.7.0_07]
at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:75) ~[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
[09:40:56] [server thread/ERROR] [FML]: There was a critical exception handling a packet on channel Lumina|Channel
io.netty.handler.codec.DecoderException: java.lang.InstantiationException: awesomespider.lumina.Packets.LumiconSpawnPacket
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.InstantiationException: awesomespider.lumina.Packets.LumiconSpawnPacket
at java.lang.Class.newInstance0(Class.java:357) ~[?:1.7.0_07]
at java.lang.Class.newInstance(Class.java:325) ~[?:1.7.0_07]
at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:75) ~[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

 

 

 

Here is my code:

 

 

Main class:

public static SimpleNetworkWrapper network;

@EventHandler
    public void preinit(FMLPreInitializationEvent event) {
network = NetworkRegistry.INSTANCE.newSimpleChannel("Lumina|Channel");
}

@EventHandler
    public void init(FMLInitializationEvent event) {
network.registerMessage(LumiconSpawnPacket.Handler.class, LumiconSpawnPacket.class, 0, Side.SERVER);
}

 

The packet class:

 

public class LumiconSpawnPacket implements IMessage {
    double posX;
    double posY;
    double posZ;

    public LumiconSpawnPacket(double posX, double posY, double posZ){
        this.posX = posX;
        this.posY = posY;
        this.posZ = posZ;
    }

    @Override
    public void fromBytes(ByteBuf buf) {
        this.posX = buf.readDouble();
        this.posY = buf.readDouble();
        this.posZ = buf.readDouble();
    }

    @Override
    public void toBytes(ByteBuf buf) {
        buf.writeDouble(posX);
        buf.writeDouble(posY);
        buf.writeDouble(posZ);
    }

    public static class Handler implements IMessageHandler<LumiconSpawnPacket, IMessage> {
        @Override
        public IMessage onMessage(LumiconSpawnPacket message, MessageContext ctx) {
            EntityPlayer player = ctx.getServerHandler().playerEntity;
            Lumina.log.info(Lumina.LOGPREFIX + " LuminaSpawnPacket recieved, player " + player + " has attempted to summon a lumicon. Spawning...");
            try {
                PlayerUtil.startPlayer(player);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    }
}

 

My input handler:

public class InputHandler {
    @SubscribeEvent
    public void onKeyInput(InputEvent.KeyInputEvent event) {
        if(KeyBindings.start.isPressed()){
            EntityPlayer player = Minecraft.getMinecraft().thePlayer;

            Lumina.network.sendToServer(new LumiconSpawnPacket(player.posX, player.posY, player.posZ));
        }
    }
}

 

PlayerUtil:

public static void startPlayer(EntityPlayer player) throws IOException {
        if (!isPlayerAlreadyStarted(player)){
            playersStartedList.add(player.getUniqueID());

            savePlayersStarted();

            playPlayerStartAnimation(player);
        }
    }

    public static boolean isPlayerAlreadyStarted(EntityPlayer player){
        return playersStartedList.contains(player.getUniqueID());
    }

    public static void playPlayerStartAnimation(EntityPlayer player) {
        //TODO Work on the animation of the player starting the journey
        player.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + "The air hums with energy."));

        player.playSound("portal.travel", 10, 0);

        player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX + 4, player.posY - 1, player.posZ));
        player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX, player.posY - 1, player.posZ + 4));
        player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX - 4, player.posY - 1, player.posZ));
        player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX, player.posY - 1, player.posZ - 4));

        //Taken from GuiIngame debug screen code (thanks to Ernio for helping me)
        int i4 = MathHelper.floor_double((double) (player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
        String direction = Direction.directions[i4];

        ForgeDirection lookDirection = ForgeDirection.valueOf(direction);

        if (lookDirection == ForgeDirection.NORTH) {
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX, player.posY - 1, player.posZ - 4));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX, player.posY - 1, player.posZ - 4));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX, player.posY - 1, player.posZ - 4));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX, player.posY - 1, player.posZ - 4));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX, player.posY - 1, player.posZ - 4));

            EntityItem item = new EntityItem(player.worldObj, player.posX, player.posY - 1, player.posZ - 4, new ItemStack(Lumina.lumicon));
            player.worldObj.spawnEntityInWorld(item);
        } else if (lookDirection == ForgeDirection.EAST) {
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX + 4, player.posY - 1, player.posZ));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX + 4, player.posY - 1, player.posZ));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX + 4, player.posY - 1, player.posZ));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX + 4, player.posY - 1, player.posZ));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX + 4, player.posY - 1, player.posZ));

            EntityItem item = new EntityItem(player.worldObj, player.posX + 4, player.posY - 1, player.posZ, new ItemStack(Lumina.lumicon));
            player.worldObj.spawnEntityInWorld(item);
        } else if (lookDirection == ForgeDirection.SOUTH) {
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX, player.posY - 1, player.posZ + 4));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX, player.posY - 1, player.posZ + 4));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX, player.posY - 1, player.posZ + 4));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX, player.posY - 1, player.posZ + 4));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX, player.posY - 1, player.posZ + 4));

            EntityItem item = new EntityItem(player.worldObj, player.posX, player.posY - 1, player.posZ + 4, new ItemStack(Lumina.lumicon));
            player.worldObj.spawnEntityInWorld(item);
        } else if (lookDirection == ForgeDirection.WEST) {
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX - 4, player.posY - 1, player.posZ));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX - 4, player.posY - 1, player.posZ));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX - 4, player.posY - 1, player.posZ));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX - 4, player.posY - 1, player.posZ));
            player.worldObj.addWeatherEffect(new EntityLightningBolt(player.worldObj, player.posX - 4, player.posY - 1, player.posZ));

            EntityItem item = new EntityItem(player.worldObj, player.posX - 4, player.posY - 1, player.posZ, new ItemStack(Lumina.lumicon));
            player.worldObj.spawnEntityInWorld(item);
        }
    }

 

 

 

If you need more code just ask. :)

 

Looking at the crash log it's a DecoderException, I have no idea what that means.

Thanks, it works now, but the lightning I'm summoning (for effect) is burning the item >:(, but I suppose that's my problem.

-snip-

@TheRealMcrafter - if you're going to verbatim copy / paste code from a tutorial (you didn't even remove my comments!), it's considerate of you to write a note in the code saying where you got it from, i.e. giving credit where credit is due.

 

Woops, my bad. Your tutorials are the best, credit given ;)

Join the conversation

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

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

Important Information

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

Configure browser push notifications

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