Posted December 27, 20195 yr So I put some code together to check if a glass block entityItem is on top of my block. It doesn't quite work what am I doing wrong? ItemStack glass = new ItemStack(Blocks.GLASS); @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if(!playerIn.isSneaking()) { if(worldIn.getBlockState(pos.down(1)) == ModBlocks.MAGIC_BLOCK.getDefaultState()) { List<EntityItem> entities = worldIn.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(0D, 0, 0D, 1D, 1D, 1D)); for (EntityItem entity : entities) { if(entity.getItem() == glass) { EntityItem item = new EntityItem(worldIn, pos.getX()+0.5F, pos.getY(), pos.getZ()+0.5F, glass); item.setNoPickupDelay(); entity.setFire(90000); worldIn.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_FIREWORK_LAUNCH, entity.getSoundCategory(), 0.8F, 0.8F + entity.world.rand.nextFloat() * 0.4F); } } }else { } } return enableStats; } } Edited December 29, 20195 yr by Whompy SOLVED!!!
December 27, 20195 yr 43 minutes ago, Whompy said: new AxisAlignedBB(0D, 0, 0D, 1D, 1D, 1D) You're currently checking for entities at (0, 0, 0). You need to offset the box's position by the position of the block being clicked. As a side note, you should also never mix tabs and spaces for your indentation. Choose one and treat the other like plague. Edited December 27, 20195 yr by SerpentDagger Fancy 3D Graphing Calculator mod, with many different coordinate systems. Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.
December 27, 20195 yr Author 2 minutes ago, SerpentDagger said: You're currently checking for entities at (0, 0, 0). You need to offset the box's position by the position of the block being clicked. do you mean the coordinates 0,0,0 ?
December 27, 20195 yr 1 minute ago, Whompy said: do you mean the coordinates 0,0,0 ? Yes. The box you create exists as the coordinates with which you create it. Since you're currently setting it up to range from (0, 0, 0) to (1, 1, 1), you need to offset it by the position of your block, or create it with coordinates derived from the position of the block in the first place. Fancy 3D Graphing Calculator mod, with many different coordinate systems. Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.
December 27, 20195 yr Author List<EntityItem> entities = worldIn.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), pos.getX(),pos.getY() + 1D, pos.getZ())); I gave this a shot, however it didn't quite work. I assume the issue is with the letter D I put after the number 1. Am I right? Edited December 27, 20195 yr by Whompy
December 27, 20195 yr 8 minutes ago, Whompy said: pos.getX(), pos.getY(), pos.getZ(), pos.getX(),pos.getY() + 1D, pos.getZ() This is checking from (x, y, z) to (x, y + 1, z), which is a box of width 0, depth 0, and height 1. It seems unlikely that an item would fit within that one. Beyond that... 1 hour ago, Whompy said: if(entity.getItem() == glass) This will never be true. The ItemStack stored in this EntityItem will never == that new ItemStack() you created above. You need to compare the two by their ItemStack#getItem() methods. Fancy 3D Graphing Calculator mod, with many different coordinate systems. Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.
December 28, 20195 yr --ignore this-- Edited December 28, 20195 yr by Draco18s 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.
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.