Jump to content

[Solved] Custom BlockFenceGate won't make open/close sounds


ozBillo

Recommended Posts

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);
			}

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

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