Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!!!

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

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

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

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

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.

  • 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 by Whompy

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.

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.