Jump to content

Get server Side EntityPlayer in client TickHandler


Bedrock_Miner

Recommended Posts

My crafting table won't work (Click here!) so I started working at another part of My Mod.

But now, I got another Problem:

 

I want to give the Player some options to select with the Keys 1..9.

If the player presses one, he'll get some potion effects, but the Items in the Inventory are damaged..

I used a client tick handler to control the Keys (look in the source).

But from a client Tick Handler I have no access to the server Inventory. What should I do?

 

Source:

ClientTickHandler:

package magicum.minecraft.tick;

import java.util.EnumSet;

import magicum.Main;
import net.minecraft.client.Minecraft;

import org.lwjgl.input.Keyboard;

import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class ClientTickHandler implements ITickHandler {

private Minecraft mc;

public ClientTickHandler(Minecraft mc) {
	super();
	this.mc = mc;
}

@Override
    public void tickStart(EnumSet<TickType> type, Object... tickData) 
    {
    	if (type.equals(EnumSet.of(TickType.CLIENT)))
        {
                this.onStartTickInGame();
        }
    }

    @Override
    public void tickEnd(EnumSet<TickType> type, Object... tickData)
    {
        if (type.equals(EnumSet.of(TickType.CLIENT)))
        {
                this.onEndTickInGame();
        }
    }

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

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

//---------------------------------------------------------------------------------------------

public void onStartTickInGame()
{
}


public void onEndTickInGame()
    {
    	//...call on NumKeyPressed(Num Key number) if the player pressed one.
        //...(don't want to show this code; but it works.)
    }
    
    private void onNumKeyPress(int Num) {
       for (int i = 0; i < this.mc.thePlayer.inventory.getSizeInventory(); i++)
	{
		this.mc.thePlayer.inventory.getStackInSlot(i).damageItem(10, this.mc.thePlayer);
	} //How can I do THIS without this.mc.thePlayer ?
        //(...)
}
}

 

Link to comment
Share on other sites

"Get server side entity from the client side" -> You can't.

 

You need to use packets to communicate from the client ("This event has occurred") and interpret it on the server ("Event A has occurred?  Ok, I'll do X")

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

What a pity.. I thought, that there is another way..

But Thanks!

 

Dude, the client and server can be running on different machines.  The client CANNOT get a memory address for the server object.

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

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.