Jump to content

Recommended Posts

Posted

1. Please don't use SideOnly.. Instead, register it on client proxy

2. You should set up your own IMessage and IMessageHandler implementations, to process the key input packet.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Now in the sendToServer(); bit what do I actually put in the parenthesis?

Is it something I choose or does it need to be something specific?

 

Seriously?  Of course it needs to be something specific.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Now in the sendToServer(); bit what do I actually put in the parenthesis?

Is it something I choose or does it need to be something specific?

 

First of all, you should learn to use your IDE (Eclipse or whatever) to help you. If you hover over the sendToServer() method it should tell you the parameter types needed, and that should give you a clue. It his case I think will tell you you need an IMessage.

 

As mentioned above, you need to implement your own IMessage and message handler implementation.

 

Now, in the message itself you actually get to choose what goes in. You create a "payload" using a ByteBuf that it is up to you what you put in and what order you put it in. But you have to make sure that the packet receiving method takes it out in same order.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Okay I have the packets working, and now I'm stuck on figuring out the key state.

 

I have the water movement working fine for climbing out but at the moment it stays that way because I haven't figured out how to properly do the unpressed part.

 

Ive tried doing this:

 

KeyHandler:

package robo51.newt.handlers;

 

import net.minecraft.client.settings.KeyBinding;

import robo51.newt.packets.NewtMessage;

import robo51.newt.packets.PacketRegistry;

import robo51.newt.proxy.ClientProxy;

import cpw.mods.fml.common.eventhandler.EventPriority;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class KeyHandler {

 

@SideOnly(Side.CLIENT)

@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)

public void onEvent(KeyInputEvent event) {

 

    // make local copy of key binding array

    KeyBinding[] keyBindings = ClientProxy.keyBindings;

   

    // check each enumerated key binding type for pressed and take appropriate action

    if (keyBindings[0].isPressed()) { //WaterRise

    PacketRegistry.network.sendToServer(new NewtMessage("UseStateChanged"));

        // DEBUG

        System.out.println("Key binding ="+keyBindings[0].getKeyDescription());

    }

 

    if (keyBindings[1].isPressed()) {

        // DEBUG

        System.out.println("Key binding ="+keyBindings[1].getKeyDescription());

        // do stuff for this key binding here

        // remember you may need to send packet to server

    }

 

}

 

}

 

 

 

And this is the message recevier:

package robo51.newt.packets;

 

import robo51.newt.handlers.WaterSealantHandler;

import io.netty.buffer.ByteBuf;

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

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 NewtMessage implements IMessage {

 

private String text;

    public static boolean workingwater = false;

 

public NewtMessage() {

 

}

 

public NewtMessage(String text) {

this.text = text;

}

 

@Override

public void fromBytes(ByteBuf buf) {

        text = ByteBufUtils.readUTF8String(buf);

}

 

@Override

public void toBytes(ByteBuf buf) {

        ByteBufUtils.writeUTF8String(buf, text);

}

 

public static class Handler implements IMessageHandler<NewtMessage, IMessage> {

 

@Override

public IMessage onMessage(NewtMessage message, MessageContext ctx) {

            System.out.println(String.format("Received %s from %s", message.text, ctx.getServerHandler().playerEntity.getDisplayName()));

           

WaterSealantHandler.waterup = workingwater;

           

            if(workingwater = false) {

            WaterSealantHandler.waterup = true;

            System.out.println("Waterup set to true");

            } else if(workingwater = true) {

            WaterSealantHandler.waterup = false;

            System.out.println("Waterup set to false");

            }

           

return null;

}

 

}

 

}

 

 

 

But it always prints out a setting to false, I'm assuming this is because I've done something weird with the logic.

 

 

Also in the keyhandler I'm using KeyInputEvent but its overwriting vanilla behavior (just the space-bar, I'm not able to jump), should I be using a different event in its place?

I'm not trying to be rude it just comes out that way sometimes.

I'm here to try and learn as much as I can, won't you join me?

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.