Jump to content

Player motionY?


SeKtOR

Recommended Posts

I solved my issue with "CommonTickHandler" big thanks to guy, who help me... Current issue with thePlayer.motionY(it's not working or i do something wrong)

My code

//thePlayer - instance of EntityPlayerMP
thePlayer.capabilities.allowFlying = true;
thePlayer.motionY *= 3.0; // Only for test
thePlayer.capabilities.isFlying = true;
thePlayer.fallDistance = 0;  

Player motionY doent's changed, but fallDistance work...

P.S. Sorry for bad english...

Link to comment
Share on other sites

I tried "System.out.println(thePlayer.motionY)" it's print "-0.078.....". Also if i run across world nothing changed motionY ignored...

P.S. Changed motionY *= 3.0 to motionY += 3.0. Nothing changed...

Current code:

        thePlayer.capabilities.allowFlying = true;
thePlayer.capabilities.isFlying = true;
thePlayer.motionY += 3.0; // Only for test
thePlayer.fallDistance = 0;  

Link to comment
Share on other sites

TickHandler(server)

package (mod package);

import java.util.EnumSet;
import java.util.ArrayList;
import java.util.Iterator;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.network.packet.Packet3Chat; // Will removed
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.server.FMLServerHandler;
import (mod package).*;

public class TickHandler implements ITickHandler 
{		
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) 
{
if(type.equals(EnumSet.of(TickType.PLAYER)))
{
ArrayList players = (ArrayList) MinecraftServer.getServer().getConfigurationManager().playerEntityList; // Wlll replace with FMLServerHandler
Iterator parray = players.iterator();
// Players armor check!
while(parray.hasNext()) {
    EntityPlayerMP thePlayer = (EntityPlayerMP) parray.next();	
ItemStack helmet = thePlayer.inventory.armorItemInSlot(3);
ItemStack body = thePlayer.inventory.armorItemInSlot(2);
ItemStack legs = thePlayer.inventory.armorItemInSlot(1);
ItemStack boots = thePlayer.inventory.armorItemInSlot(0);
if(helmet != null) {
// do something...
}

if(body != null) {
// do something...
}

if(legs != null) {
// do something...
}

if(boots != null) {
if(boots.itemID == (main mod class).bootsPremium.shiftedIndex) {
System.out.println("Player has boots");
    thePlayer.capabilities.allowFlying = true;
thePlayer.capabilities.isFlying = true;
thePlayer.motionY = 10.0; // Only for test
thePlayer.fallDistance = 0;  
//System.out.println(thePlayer.motionY);
}
}

}
}
// End Players armor check!
}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) 
{

}

@Override
public EnumSet<TickType> ticks() 
{
	return EnumSet.of(TickType.PLAYER);
}

@Override
public String getLabel() 
{
	return null;
}

}

Also in main mod class

TickRegistry.registerTickHandler(new TickHandler(), Side.SERVER);

Link to comment
Share on other sites

I'm guessing this is in a tick handler, i'm having the same problem, it will update the velocity if the player takes damage it seems, so it could be that the velocity isn't updated through this method without something else happening to the player. Not sure how to do this

 

 

Here is the tick handler as i have it (i'm guessing his is similar)

 

import java.util.EnumSet;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class ServerTickHandler implements ITickHandler
{

public static EntityPlayer thePlayer;

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) 
{
	if (type.equals(EnumSet.of(TickType.PLAYER)))
	{
		onPlayerTick((EntityPlayer)tickData[0]);
	}
}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{

}

@Override
public EnumSet<TickType> ticks()
{
	return EnumSet.of(TickType.PLAYER, TickType.CLIENT);
}

@Override
public String getLabel()
{
	return "My Tick";
}

private void onPlayerTick(EntityPlayer player) 
{
	player.motionY = 1;
}
}

 

 

[edit]

whoops looks like he updated the thread whilst i was typing this

Link to comment
Share on other sites

I'm guessing this is in a tick handler, i'm having the same problem, it will update the velocity if the player takes damage it seems, so it could be that the velocity isn't updated through this method without something else happening to the player. Not sure how to do this

 

 

Here is the tick handler as i have it (i'm guessing his is similar)

 

import java.util.EnumSet;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class ServerTickHandler implements ITickHandler
{

public static EntityPlayer thePlayer;

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) 
{
	if (type.equals(EnumSet.of(TickType.PLAYER)))
	{
		onPlayerTick((EntityPlayer)tickData[0]);
	}
}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{

}

@Override
public EnumSet<TickType> ticks()
{
	return EnumSet.of(TickType.PLAYER, TickType.CLIENT);
}

@Override
public String getLabel()
{
	return "My Tick";
}

private void onPlayerTick(EntityPlayer player) 
{
	player.motionY = 1;
}
}

 

 

[edit]

whoops looks like he updated the thread whilst i was typing this

I think this ticker dont work on server side because:

 @Override
public EnumSet<TickType> ticks()
{
  return EnumSet.of(TickType.PLAYER, TickType.CLIENT);
}

Link to comment
Share on other sites

i've tried with both, it seems to work the same both way, it's just i didn't bother changing it before posting as i was changing it to see whether it was the tick type that was the problem

[edit]

i just realised what you meant, yeah that's probably true, not got a way to try it though

Link to comment
Share on other sites

just found something else that's odd.

I told it to print the motionY before and after setting it to 1. oddly the speed it was saying before was not equal to 0 whilst standing still, instead it was a bit lower than what i was setting it to. (told it to set it to 1, and it said the initial velocity was 0.907....    told it to set it to 2 and it said it started at 1.8.....) this is odd and may shine some light on our problem.

 

[EDIT]

after my player.motionY=2, it seems that it is normally at -0.0784000015258789 whilst stationary. guess this is gravity or something

Link to comment
Share on other sites

Just had the brilliant idea of scrolling through github to see if there were any open source mods which had done this.

Looking in the source for MachineMuse modular power suits (Epic mod, try it out) In the tick data they only specified TickType.PLAYER. not player and server. not tried it yet, and it may be a while before i can, but give this a go and see what you can do (tell me what you manage so i know if it works when i get round to doing this)

 

I'll post a link to the source so you can look yourself and see what you think

https://github.com/MachineMuse/MachineMusePowersuits/blob/master/src/minecraft/net/machinemuse/powersuits/tick/PlayerTickHandler.java

Link to comment
Share on other sites

I GOT IT WORKING!!!!!!!!!!

just had to register it in the client proxy aswell :)

 

the code is now just the same (player.motionY += number in tick handler) with it regesterd as

TickRegistry.registerTickHandler(new TickHandler(), Side.SERVER);

in common proxy and

TickRegistry.registerTickHandler(new AAPlayerTickHandler(), Side.CLIENT);

in the client proxy :)

YAY IT WORKS

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



×
×
  • Create New...

Important Information

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