Jump to content

Recommended Posts

Posted (edited)

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 by Whompy
SOLVED!!!
Posted (edited)
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 by SerpentDagger
  • Like 1
  • Thanks 1

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Posted
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 ?

Posted
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.

Posted (edited)
            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 by Whompy
Posted
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.

Posted (edited)

--ignore this--

Edited 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.

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.