Jump to content

Trying to access player information using a Custom Block


Recommended Posts

I am trying to make a mod that has a block that affects the movement of a player when they are within a radius of the block. I have found some methods in the forge api, but I can't seem to get anything to work.


My code accesses the net.minecraft.world.World methods as well as the net.minecraft.entity.player.EntityPlayer package to access nearby players.


My code doesn't do anything, my guess is it just grabs null references for the player/world. I also think the block might not be affecting the player because the code might only run through one time when it is first instantiated into the world.


Any thoughts would be helpful, here is the code.


protected CustomBlock(Material p_i45394_1_) {
	this.setBlockTextureName(StringLibrary.MODID + ":dense_block");
	this.setPlayerMovement(1.0D,1.0D,1.0D, 5.0D);

private void setPlayerMovement(double moveX, double moveY, double moveZ, double distance) {
	World world = Minecraft.getMinecraft().theWorld;
	TileEntityCamp camp = new TileEntityCamp();
	if(world != null){
		EntityPlayer player = world.getClosestPlayer(camp.xCoord,camp.yCoord,camp.zCoord,distance);
		if(player != null)
			player.isDead = true;

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.

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.