Posted June 24, 201510 yr 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?
June 24, 201510 yr 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/
June 24, 201510 yr Author 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?
June 24, 201510 yr 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.