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

If the gate is closed and the player is holding a valid key, the gate opens.

If the gate is open and the player is not holding a valid key, the gate closes.

 

I use the playAuxSFXAtEntity method to play the appropriate sound on gate open and close.

But, I'm not getting any sound from the gate.

Other gates sound okay.

 

Here is the relevant code. Have I missed something?

 

public class MyGate extends BlockFenceGate {
...
@Override
public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) {
	if(!par1World.isRemote) {
		if (par5Entity instanceof EntityLivingBase) {
        	EntityLivingBase entityLiving = (EntityLivingBase) par5Entity;
        	if (entityLiving instanceof EntityPlayer) {
        		EntityPlayer entityPlayer = (EntityPlayer) entityLiving;        		
...
        		int i1 = par1World.getBlockMetadata(par2, par3, par4);
        		boolean MyGateOpen = isFenceGateOpen(i1);
        		
			if (!MyGateOpen && holdingValidKey) {
				MyGateOpen = true;
				par1World.setBlockMetadataWithNotify(par2, par3, par4, i1 | 4, 2); // open the gate
				par1World.playAuxSFXAtEntity(entityPlayer, 1003, par2, par3, par4, 0);
			} 
			else if (MyGateOpen && !holdingValidKey) {
				MyGateOpen = false;
				par1World.setBlockMetadataWithNotify(par2, par3, par4, i1 & -5, 2); // close the gate
				par1World.playAuxSFXAtEntity(entityPlayer, 1003, par2, par3, par4, 0);
			}

Try with (EntityPlayer)null instead of the entity instance. It seems the given entity don't receive the packet.

  • Author
  On 8/12/2013 at 3:46 PM, GotoLink said:

Try with (EntityPlayer)null instead of the entity instance. It seems the given entity don't receive the packet.

 

That did the trick! Thank you, GotoLink.

Guest
This topic is now closed to further replies.

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.