Jump to content

Recommended Posts

Posted

I finally got off my lazy butt and decided to work on my mod again, and I am currently working to fix all the "little" things first.

 

So I have an event that causes the player to take damage in the water if a value is <= 0.

 

Event:

 

  Reveal hidden contents

 

 

However this doesn't seem to do anything now, (it used to work but I remember changing the event a while back).

 

I feel like I'm either using the wrong event for this or not using the current event properly.

 

If someone could help me out with this, maybe point me in the right direction it would be much appreciated.  :)

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?

Posted

Few things:

1. Tick event have Phases - you need to define (by if statement), START or END Phase (otherwise code will be ran twice).

2. You CAN'T use KeyBindings inside this tick event - mouse and keyboard is CLIENT side. You need to send packet that you clicked and/or unclicked key.

3. 20 tick = 1sec (you have 50=1sec and 200=5sec - wtf?)

 

Edit: I also remember you and your problem - we alredy told you all this above.

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted

1. What is the difference between the START and END phase? I can't seem to find anything really explaining them.

2. I do remember the keybind problem I forgot to comment it out in the version I posted as I plan to try really hard to understand packets and how they work with the help of tutorials.

3. Those numbers are somewhat arbitrary at the moment  :-[

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?

Posted
  On 4/7/2015 at 3:31 AM, Robo51 said:

1. What is the difference between the START and END phase? I can't seem to find anything really explaining them.

 

Is kind of like the stay of a race and the end. There really isn't much difference at all. But I'm pretty sure the medals are only given our once, at the end.

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

1. It's about game loop. 1tick = 50ms, in that time everything happens, updates of world, entities, tileentities, everything. If you'd look at code that initiates all those updates you would see that Forge with phase START is called 1st, then there are entity updates - so methods like onUpdate() inside entity (I like to call it MIDDLE phase or ACTUAL tick) and then END phase. Most of the time you will want to use START.

 

2. Not really much to talk about:

http://www.minecraftforge.net/forum/index.php/topic,20135.0.html

I was learnin on this, so I'll link it:

http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2137055-1-7-x-1-8-customizing-packet-handling-with

 

3. Yeah, but important.

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted

So I decided to redo this little section of code as I always find it easiest to start over.

 

I've started with this:

 

 

  Reveal hidden contents

 

 

However the player takes no damage when in water or rain.

Am I referencing the player wrong here?

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?

Posted

@SubscribeEvent
   public void playerTickEvent(TickEvent.PlayerTickEvent event) {
      
       if(event.phase == Phase.START && !event.player.worldObj.isRemote) {
          
          if(event.player.isWet()) {
             event.player.attackEntityFrom(DamageSource.drown, 1.0F);
          }    
       }
   }

 

^ more suitable code, also - ticks events are fired by FML - you need to register them using FML, not Forge bus.

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted

Okay so I fixed up my playerTickEvent and got that all working. :)

 

And now I'm working on the next bit that handles water movement and requires a packet.

This is what I have so far:

 

Inside of the event handler:

 

  Reveal hidden contents

 

 

And this is in the NewtMessage class:

 

  Reveal hidden contents

 

 

I left the response for the packet as what came out of the tutorial for the moment so I could get the packet working first.

 

However I'm not sure what all needs to be transferred in the packet, I think I need the player?

And If I do need the player how do I properly transfer that since what I'm currently using doesn't work.

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?

Posted

This is totally wrong, do:

1. Make KeyBinding for your key. Subscribe to InputEvent.KeyInputEvent and check wether key was pressed and/or unpressed.

1.1. On key pressed: set som boolean to true and send packet FROM client TO server that key is pressed (true).

1.2. On key unpressed send another packet - false (from client To server) that will tell server that you stopped holding it.

2. Make PlayerTickEvent ONLY (and ONLY) check your boolean on server side, since server will now know that you pressed button (this true/false) you can make if on that boolean and operate on server-side.

2.1. Do your stuff.

 

Notes:

Save that boolean per-player, so inside ExtendedPlayer (IEEP class).

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted

So I've been working through the key binding and hit a small snag.

 

The key binding works fine for the client but the server doesn't like it.

I feel like this has to do with which side the key bindings need to be on, but one of the tutorials Ive been reading through mentioned it.

 

This is the KeyBindingHandler:

  Reveal hidden contents

 

 

And this is the KeyInputHandler:

  Reveal hidden contents

 

 

The server doesn't like this line in the bindinghandler:

  Reveal hidden contents

 

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?

Posted

Because you're still calling that class from common code.  Proxy that shit.

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

Yeah, key bindings are only supposed to be on the client -- this allows each player to have different key bindings if they really wanted. As explained above, use proxy to only do the key binding stuff on client side, then send packet to server to get it to respond in whatever way you want. I have a tutorial here (on the key binding part): http://jabelarminecraft.blogspot.com/p/minecraft-forge-1721710-keybinding.html

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

Posted

Okay now I'm kinda confused  :-\

 

Ive moved to the ClientProxy:

  Reveal hidden contents

 

 

And this is what in now in the KeyInputHandler:

  Reveal hidden contents

 

 

And now the client errors the moment I press any key, I feel like its going to smack me in the face when I figure it out.

But I've got no idea now.

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?

Posted

No, bad!

 

You should never directly reference your ClientProxy file.  That breaks the whole point of proxies.

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

Yeah, that's not the way to use proxies. In the approach that I use is that your main class should have methods that handle the FML "life cycle" events (what people typically call "pre-init", "init", "post-init"). Those should call the same method in the proxy instance. E.g. in my main class I'll have something like this:

 

 

  Reveal hidden contents

 

 

Then your Common Proxy should have the same methods and should do whatever is actually common, for example in my CommonProxy:

 

  Reveal hidden contents

 

 

Then in the ClientProxy which extends CommonProxy, call the super method for the common stuff then add the client-specific stuff:

 

  Reveal hidden contents

 

 

So main class handles the init life cycle event by calling the proxy, and proxy will have appropriate methods based on side.

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

Posted

Is:

  @EventHandler

    public void fmlLifeCycleEvent(FMLInitializationEvent event)

 

Similar to:

    @Mod.EventHandler

    public void init(FMLInitializationEvent event) {

 

Because this is what my main class looks like right now:

  Reveal hidden contents

 

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?

Posted

Yes, it doesn't actually matter what the name of the method is, or the name of the parameter either, rather the @EventHandler only looks at the parameter type passed. So a method that passes FMLInitializationEvent will be the same.

 

Okay, in the code you posted, you're registering the key handler in the main class. That should be in the client proxy lik,e we've been saying.

 

I personally would put all that other code into the CommonProxy and the KeyBinding stuff in the ClientProxy, although it is technically okay to have the common stuff in the main class method.

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

Posted

I feel like I'm still missing something.

 

I've moved the register KeyInputHandler into the ClientProxy:

 

 

  Reveal hidden contents

 

 

And still get the same error from the client upon test:

  Reveal hidden contents

 

 

Am I just repeating myself at this point?

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?

Posted

This is the KeyInputHandler code:

package robo51.newt.handlers;

import net.minecraft.client.settings.KeyBinding;
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 KeyInputHandler {

@SideOnly(Side.CLIENT)
@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
public void onEvent(KeyInputEvent event) {
    System.out.println("Key Input Event");
    KeyBinding[] keyBindings = ClientProxy.keyBindings; 

    if (keyBindings[0].isPressed()) { //line 19
        System.out.println("Key binding ="+keyBindings[0].getKeyDescription());
        // do stuff for this key binding here
        // remember you may need to send packet to server
    }

    if (keyBindings[1].isPressed()) {
        System.out.println("Key binding ="+keyBindings[1].getKeyDescription());
        // do stuff for this key binding here
        // remember you may need to send packet to server
    }

}



}

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?

Posted

@EventHandler
public void preLoad(FMLPreInitializationEvent event)
{
	proxy.registerPre();
}

public class CommonProxy
{
@SideOnly(Side.CLIENT)
public KeyHandler keyHandler; //will exist only on client.jar

public void registerPre() {} // Empty, you will override it on clientProxy
}

public class ClientProxy extends CommonProxy
{
@Override
public void registerPre()
{
	keyHandler = new KeyHandler(); // this is keyHandler from superclass.
	FMLCommonHandler.instance().bus().register(keyHandler); //You register it only if you are running client.jar
}
}

 

The to reference it:

public void someMethod()
{
MainMod.proxy.keyHandler
}

On dedic.jar this will crash since CommonProxy doesn't have this field, but you don't use in on server, do you?

On client.jar you will get keyHandler from ClientProxy.

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted
  On 4/8/2015 at 11:15 PM, Robo51 said:
I've moved the register KeyInputHandler into the ClientProxy:

 

   public void FMLPreInitializationEvent(FMLPreInitializationEvent event) {
      
      FMLCommonHandler.instance().bus().register(new KeyInputHandler());
      
   }

 

...No, no you did not.  You referenced your KeyInputHandler in your main mod file.

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

How would I go about properly registering the KeyInputHandler in the ClientProxy then?

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?

Posted

Thank you for that. :)

 

I started from scratch and the keybinds work great now.

 

 

I move onto the packets and I'm stuck at what I actually send in the packet.

This is the KeyHandler:

 

  Reveal hidden contents

 

 

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?

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.