Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Player rotation pitch and yaw


Asweez
 Share

Recommended Posts

Ok so I know how to get the player's pitch and yaw, but the world can't be remote (!world.isRemote). However, I want to use the players rotation to add velocity, but the player.addVelocity method won't work when the world isn't remote. How would I do this?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Link to comment
Share on other sites

If you absolutely positively can't do it on the server, then you need packets.  Game set match.

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.

Link to comment
Share on other sites

Ok so I have my packets set up but where would I put the player.addVelocity? Would it be in the handler? And where would the player's rotation amounts be inserted? Would they be a parameter for the packet or calculated during message handling?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Link to comment
Share on other sites

You can also change the player's motionX/Y/Z fields directly on the server, but it is usually better to handle player motion on the client.

 

Correction:

You want to do it on both.

 

If you do it client-side-only then the server will go "hey buddy, you're over here" and rubber band you back.

If you do it server-side-only the client will lag-behind and you'll rubber band the other way.

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.

Link to comment
Share on other sites

You can also change the player's motionX/Y/Z fields directly on the server, but it is usually better to handle player motion on the client.

 

Correction:

You want to do it on both.

 

If you do it client-side-only then the server will go "hey buddy, you're over here" and rubber band you back.

If you do it server-side-only the client will lag-behind and you'll rubber band the other way.

The rubber-band effect typically happens if you use setPosition type methods on the client, but changing motion actually works just fine. You can still get an 'illegal stance' warning if player's total motion is too high, though, whether or not you set it on the server, the client, or both.

 

Generally it is better to do things on both sides if possible, but in this case I don't think it really matters that much since the client is sending motion updates to the server anyway (see EntityClientPlayerMP#sendMotionUpdates).

Link to comment
Share on other sites

Ya:

 

PacketHandler

 

package 
;

import com.apmods.accupack.AccuPack;

import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;

public class AccuNetwork {
public static SimpleNetworkWrapper network ;
public static void init(){
	network = NetworkRegistry.INSTANCE.newSimpleChannel(AccuPack.MODID);
	registerPackets();
}
public static void registerPackets(){
	network.registerMessage(JetpackFlyPacket.class, JetpackFlyPacket.JetpackFlyMessage.class, 0, Side.SERVER);
	network.registerMessage(JetpackFlyPacket.class, JetpackFlyPacket.JetpackFlyMessage.class, 0, Side.CLIENT);
}
}

 

 

JetpackFlyPacket:

 

 

package com.apmods.accupack.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;

import com.apmods.accupack.network.JetpackFlyPacket.JetpackFlyMessage;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;

public class JetpackFlyPacket implements IMessageHandler<JetpackFlyMessage, IMessage>{

@Override
public IMessage onMessage(JetpackFlyMessage message, MessageContext ctx) {

	return null;
}
public class JetpackFlyMessage implements IMessage{

	public JetpackFlyMessage(){

	}
	@Override
	public void fromBytes(ByteBuf buf) {


	}

	@Override
	public void toBytes(ByteBuf buf) {


	}

}

}

(empty as of now)

 

KeyHandler:

 

 

package com.apmods.accupack;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;

import com.apmods.accupack.network.AccuNetwork;
import com.apmods.accupack.network.JetpackFlyPacket;

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

public class KeyHandler {
@SubscribeEvent
public void keyInput(KeyInputEvent event){
	Minecraft mc = Minecraft.getMinecraft();
	if(KeyBindings.jetpackFly.isPressed()){
		if(mc.inGameHasFocus){
			AccuNetwork.network.sendToServer(new JetpackFlyPacket.JetpackFlyMessage());
			//Error above "No enclosing instance of type JetpackFlyPacket is accessible. 
			// Cont. Must qualify the allocation with an enclosing instance of type JetpackFlyPacket 
			// Cont. (e.g. x.new A() where x is an instance of JetpackFlyPacket)."
		}
	}
}
}

 

 

KeyBindings:

 

package com.apmods.accupack;

import org.lwjgl.input.Keyboard;

import net.minecraft.client.settings.KeyBinding;

public class KeyBindings {
public static final KeyBinding jetpackFly = new KeyBinding("AccuPack Fly Key", Keyboard.KEY_SPACE, "key.categories.accupack");
}

 

 

Init method:

 

@EventHandler
    public void preInit(FMLPreInitializationEvent event){
    	proxy.preInit();
    	AccuNetwork.init();
    }
    @EventHandler
    public void init(FMLInitializationEvent event)
    {
    	proxy.init();
    	
    }

(edited for the important parts)

 

Tell me if you need anything else

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Link to comment
Share on other sites

So what exactly is it you are wanting to do, fly? KeyInputEvent fires once when a key is pressed and once when it is released, but not at all in between, so you'll need to set some variable somewhere like 'isBoosting' then add player.motionY += 0.15D or whatever each tick if it's true. You could of course just check if the key is still pressed using the keybinding instance, but that is client side only.

Link to comment
Share on other sites

  • 3 years later...
On 31. 12. 2014 at 7:07 PM, Asweez said:

Why do they change the names?

Most likely to make development more user friendly. I believe the original names func_xxx are a result of decompilation, and the new names are user friendly aliases for them. 

Edited by DeadPix
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.