Jump to content

Player Flight in Multiplayer.


Noah_Beech

Recommended Posts

Hello, recently I came across a bug where if a player is using my flight item with 2 or more players on a lan/mltiplayer server, it won't work. Here is the code.

 


package rareores.Common;

import java.util.EnumSet;

import mod_Rareores.Events;
import mod_Rareores.mod_rareores;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeInstance;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class PlayerTickHandler implements ITickHandler {




int count = 0;
int delay = 0;
float landMovementFactor = 0.0F;
boolean check1 = true;
boolean check2= true;


private void onPlayerTick(EntityPlayer player) {

	final AttributeModifier speed1 = new AttributeModifier(player.getPersistentID(), "Emblem Speed Boost", 0.25D, 1);
	final AttributeModifier speed2 = new AttributeModifier(player.getPersistentID(), "Freedom Speed Boost", 0.5D, 1);




	if(player.inventory.hasItem(mod_rareores.ItemEmblemFlight.itemID) && player.capabilities.isCreativeMode == false && this.count < 100 && this.delay == 0)
	{

	    player.capabilities.allowFlying = true;
	    if(player.capabilities.isFlying){
		this.count++;
		Events.Fly = true;
	    }
	    if(this.count > 0 && !player.capabilities.isFlying){
	    	count = 100;
	    
	    }

	}
	else
	{   


		this.count = 0;
		this.delay++;
		if (this.delay >= 60)
		{
			Events.Fly = false;
		}
		if (this.delay >= 1200)
		{
			this.delay = 0;
		}
		if(!player.capabilities.isCreativeMode){
		player.capabilities.allowFlying = false;
		player.capabilities.isFlying = false;
		}

	}

 

I have it registers on the client and the server in both client and commonproxy classes. Not sure why I can't get it to work.

This is the creator of the Rareores mod! Be sure to check it out at

Link to comment
Share on other sites

thats because you have only 1 "count" for every player  theres 1 PlayerTickHandler overall, not per player. so basicly every player is using the same "count" value

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Sorry to bug ya again but could you just go a little more in depth to how Im exactly going to use this hashmap? I know a little bit about it but I'm not sure exactly how a hashmap would be the solution. I could see grabing an insance of the player for one part but how would I get that player to have their own :count" variables?

 

This is the creator of the Rareores mod! Be sure to check it out at

Link to comment
Share on other sites

you're lucky i write code for you, i dont do it often

 

public class PlayerTickHandler implements ITickHandler {

        HashMap<String, Integer> countMap = new HashMap<String, Integer>();
        HashMap<String, Integer> delayMap = new HashMap<String, Integer>();



int count = 0;
int delay = 0;
float landMovementFactor = 0.0F;
boolean check1 = true;
boolean check2= true;


private void onPlayerTick(EntityPlayer player) {

                if(countMap.get(player.username) == null){
                    countMap.put(player.username, 0);
                }

                if(delayMap.get(player.username) == null){
                    delayMap.put(player.username, 0);
                }
                count = countMap.get(player.username);
                delay = delayMap.get(player.username);

	final AttributeModifier speed1 = new AttributeModifier(player.getPersistentID(), "Emblem Speed Boost", 0.25D, 1);
	final AttributeModifier speed2 = new AttributeModifier(player.getPersistentID(), "Freedom Speed Boost", 0.5D, 1);




	if(player.inventory.hasItem(mod_rareores.ItemEmblemFlight.itemID) && player.capabilities.isCreativeMode == false && this.count < 100 && this.delay == 0)
	{

	    player.capabilities.allowFlying = true;
	    if(player.capabilities.isFlying){
		this.count++;
		Events.Fly = true;
	    }
	    if(this.count > 0 && !player.capabilities.isFlying){
	    	count = 100;
	    
	    }

	}
	else
	{   


		this.count = 0;
		this.delay++;
		if (this.delay >= 60)
		{
			Events.Fly = false;
		}
		if (this.delay >= 1200)
		{
			this.delay = 0;
		}
		if(!player.capabilities.isCreativeMode){
		player.capabilities.allowFlying = false;
		player.capabilities.isFlying = false;
		}

	}

                countMap.put(player.username, count);
                delayMap.put(player.username, delay);

 

couple of things, this is only an example it was NOT compiled and so maybe it does not work (i wrote thsi completelly in forge)

2, its missing at least 1 bracket at the botom, i didnt not add it because in your original post there was also missing one and i dont know if you have more method bellow

3 google how to use hashmaps if it doesnt work, itll tell how what they are used for.

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

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.



×
×
  • Create New...

Important Information

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