Posted September 11, 201213 yr i have the following problem: public static boolean setBlock(EntityPlayer player, int x, int y, int z, int id, int meta) { boolean rv = false; if(player.worldObj.isAirBlock(x, y, z) && player.canPlayerEdit(x, y, z)) { player.worldObj.setBlockAndMetadataWithNotify(x,y,z,id,meta); return true; } return rv; } it checks if the block is air but i cant check if an entity stands on the block. how can i check this?
September 11, 201213 yr well you can get close to it by checking if the distance to block is less or equal to one. public boolean collectItem(EntityItem targetItem) { if(targetItem == null) { targetItem = findClosestItem(this.posX, this.posY, this.posZ,30); } else { if(!targetItem.isEntityAlive()) { targetItem = null; } } if(targetItem != null) { PathEntity PathToItem = this.worldObj.getPathEntityToEntity(this, targetItem, 30, true, false, false, true); if(hasPath()){ this.setPathToEntity(PathToItem); this.moveSpeed = 1.0F; [b]if(targetItem.getDistanceSq(this.posX,this.posY,this.posZ) < 2)[/b] { targetItem.setDead(); //TODO add item to inventory targetItem = null; } } else { this.moveSpeed = 0.23F; } } return false; } this is the code i use for collecting items. It has cod for checking distance to target. http://i577.photobucket.com/albums/ss215/bobstrong/ModBannerMed.png[/img]
September 11, 201213 yr Author i dont have any entity... i have only X, Y & Z Coordinates and i whant to find out if there is a entity in this "block"
September 12, 201213 yr i dont have any entity... i have only X, Y & Z Coordinates and i whant to find out if there is a entity in this "block" oh so you want to find if its just above the block. //your'll have to fiddle with the bound box size to find only items above AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(x,y+1,z, x+1,y+2,z+1); //change EntityItem too the entity you want to find List<EntityItem> items = par1World.getEntitiesWithinAABB(EntityItem.class, bounds); if(items.size > 0) { //there is something above block } there is more likely an easier bit of code that just checks of the spot you want to place is clear, or else placing normal block would cause issues. Check line 3461 in World.class and the ItemBlock.class http://i577.photobucket.com/albums/ss215/bobstrong/ModBannerMed.png[/img]
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.