Jump to content

Recommended Posts

Posted

Hey guys,

 

I managed to find chest nearby a custom entity that i had made but the problem is that sometimes it work, and sometimes it doesn't. I've been figuring out what is causing the problem but have no solution to it.

Here is the code:

public boolean findChest()
    {
    	Vec3 vec = new Vec3(this.posX, this.posY, this.posZ);

	xPos = vec.xCoord;
	yPos = vec.yCoord;
	zPos = vec.zCoord;

	for (double x = xPos-10; x < xPos+10; x++) 
	{	
		for (double z = zPos-10; z < zPos+10; z++) 
		{
			pos = new BlockPos(x, yPos, z);

			if (this.worldObj.getBlockState(pos) == Blocks.chest.getDefaultState())
			{
				PathEntity path = this.getNavigator().getPathToXYZ(x, yPos, z);
				this.getNavigator().setPath(path, 0.;

				return true;
			}
		}
	}
    	
    	return false;
    }
    
    public void onUpdate()
    {
    	super.onUpdate();
    	
    	if(findChest())
    	{
    		System.out.println("Success!!");
    	}
    }

 

It doesnt seem to go into this statement sometimes for some reason " if (this.worldObj.getBlockState(pos) == Blocks.chest.getDefaultState()) "

 

Any kind soul that can help?

Posted

I don't think you should be comparing states, especially the default state because I think if the chest is rotated it probably isn't in the default state.

 

Why don't you just compare the actual block instead? With something like

if (this.worldObj.getBlockState(pos).getBlock() == Blocks.chest)

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Thanks! Its working now.

 

Was wondering, is there a way my custom entity can interact with the chest and store its items inside? Hopper can be used but is there a way to let the entity interact with the chest?

Posted

After you get the TE for the chest and cast it to TileEntityChest, you can use the functions getStackInSlot and setInventorySlotContents to peek and poke into the chest.

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.