SeKtOR Posted February 12, 2013 Posted February 12, 2013 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... Quote
SeKtOR Posted February 12, 2013 Author Posted February 12, 2013 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; Quote
SeKtOR Posted February 12, 2013 Author Posted February 12, 2013 I want make something like "Hugh Jump Boots". After some studying i can really understand java code and want code Quote
SeKtOR Posted February 12, 2013 Author Posted February 12, 2013 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); Quote
Yagoki Posted February 12, 2013 Posted February 12, 2013 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 Quote github
SeKtOR Posted February 12, 2013 Author Posted February 12, 2013 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); } Quote
Yagoki Posted February 12, 2013 Posted February 12, 2013 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 Quote github
Yagoki Posted February 12, 2013 Posted February 12, 2013 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 Quote github
SeKtOR Posted February 13, 2013 Author Posted February 13, 2013 I find something strange: if enable fall damage and get it "motionY" will triggered and player make high jump... Quote
Yagoki Posted February 13, 2013 Posted February 13, 2013 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 Quote github
Yagoki Posted February 14, 2013 Posted February 14, 2013 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 Quote github
Recommended Posts
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.