Jump to content

Recommended Posts

Posted

Hey all,

 

I am trying to make a vilager panic when they hear my siren sound. I have it setup to add EntityAIPanic to the tasks list when to the villager, but they dont move until I hit them. How can I push the AI update to them?

Posted

Tried a few things:

 

if (this.isPlaying){
       List l = this.worldObj.getEntitiesWithinAABB(EntityVillager.class, AxisAlignedBB.getBoundingBox(this.xCoord - 20, this.yCoord - 20, this.zCoord - 20, this.xCoord + 20, this.yCoord + 20, this.zCoord + 20));

       if (!l.isEmpty()){
	for (int i = 0; i < l.size(); i++){
		EntityVillager villager = (EntityVillager) l.get(i);
		((EntityVillager) villager).tasks.addTask(0, new EntityAIPanic(villager, 0.9D));

                        //((EntityVillager) villager).targetTasks.addTask(0, new EntityAIPanic(villager, 0.9D));
		//((EntityVillager) villager).tasks.onUpdateTasks();
		//((EntityVillager) villager).targetTasks.onUpdateTasks();
	}
}
}

Posted

Okay, I got it to work how I want it. But now, my sirens only play for like a half a second and then they stop. If I remove this code from my tile entity, the sounds play all the way through and continue looping.

 


if (this.isPlaying){
List l = this.worldObj.getEntitiesWithinAABB(EntityVillager.class, AxisAlignedBB.getBoundingBox(this.xCoord - 20, this.yCoord - 20, this.zCoord - 20, this.xCoord + 20, this.yCoord + 20, this.zCoord + 20));

if (!l.isEmpty()){
	for (int i = 0; i < l.size(); i++){
		EntityVillager villager = (EntityVillager) l.get(i);
		ExtendedVillager props = ExtendedVillager.get(villager);
		props.isScared = true;
	}
}
}

 

Anyone have an idea what I'm doing wrong?

Posted

I play the sound by sending a packet with the sound name from the tile entity to all nearby players in the same world, and then passing the sound name to my Looping Audio Handler, and then passing that to my Siren Looper class.

 

Tile Entity:

if (!isPlaying && shouldStart){
			shouldStart = false; 
			shouldStop = false; 
			isPlaying = true; 
			this.updateClientRender();
			SirenModPacketDispatcher.sendToAllAround(new SirenModPlayLoopedSoundMessage(xCoord, yCoord, zCoord, "sirenT121"), this.worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50000000);
		}

 

Play Sound Message:

public IMessage handleClientMessage(EntityPlayer player, SirenModPlayLoopedSoundMessage message, MessageContext ctx) {
    		new LoopingAudioHandler(player.worldObj, message.x, message.y, message.z, message.soundName);

 

Looping Audio Handler:

public LoopingAudioHandler(World world, int x, int y, int z, String soundName){
	SirenLooper looper = new SirenLooper(world.getTileEntity(x, y, z), soundName);
	Minecraft.getMinecraft().getSoundHandler().playSound(looper);
}

 

Siren Looper:

public SirenLooper(TileEntity tile, String soundName){ 
        super(new ResourceLocation("SirenMod:" + soundName));  
        this.tile = tile;
        this.repeat = true; 
        if (tile instanceof NuclearSirenTileEntity){
            volume = 5.0F;
    	} else if (tile instanceof GeneralSirenTileEntity){
            volume = 10.0F;
    	} else if (tile instanceof BurglarSirenTileEntity){
            volume = 5.0F;
    	} else if (tile instanceof FireAlarmTileEntity){
            volume = 5.0F;
    	} else if (tile instanceof AmericanSignalT121TileEntity){
            volume = 20.0F;

    	} else {
            volume = 5.0F;
    	}
        this.xPosF = tile.xCoord;
        this.yPosF = tile.yCoord;
        this.zPosF = tile.zCoord;
    }


    public void update(){ 
    	if (tile instanceof GeneralSirenTileEntity){
    		if (((GeneralSirenTileEntity) tile).isShouldStop() || ((GeneralSirenTileEntity) tile).isInvalid()){  
                this.donePlaying = true;}
    	} else if (tile instanceof NuclearSirenTileEntity){
    		if (((NuclearSirenTileEntity) tile).isShouldStop() || ((NuclearSirenTileEntity) tile).isInvalid()){    
                this.donePlaying = true;}
    	} else if (tile instanceof BurglarSirenTileEntity){
    		if (((BurglarSirenTileEntity) tile).isShouldStop() || ((BurglarSirenTileEntity) tile).isInvalid()){    
                this.donePlaying = true;}
    	} else if (tile instanceof FireAlarmTileEntity){
    		if (((FireAlarmTileEntity) tile).isShouldStop() || ((FireAlarmTileEntity) tile).isInvalid()){    
                this.donePlaying = true;}
    	} else if (tile instanceof AmericanSignalT121TileEntity){
    		if (((AmericanSignalT121TileEntity) tile).isShouldStop() || ((AmericanSignalT121TileEntity) tile).isInvalid()){    
                this.donePlaying = true;}
    	} else {
    		throw new ClassCastException();
    	}   
    }

@Override
    public boolean isDonePlaying(){
        return this.donePlaying;} 
}

Posted

public void setShouldStop(boolean shouldStop){
    	if (shouldStop){
    		if (isPlaying){
    			isPlaying = false; 
    			this.shouldStop = true;
    		}
    	} else {
    		this.shouldStop = shouldStop;
    	}
    }

 

 

I know I could have just done

 

public void setShouldStop(boolean shouldStop){
    this.shouldStop = shouldStop;
}

 

but in order for my sirens to work properly, I have to do the above. Everything worked fine until I implemented the AI changes above, then they play for a few seconds and stop.

Posted

So I can just mark the block for update?

 

EDIT: I put a System.out.println(); in the shouldStop method. It isn't called, but the sound still stops. The siren doesnt stop until

 

props.isScared = true;

 

is called.

Posted

Well I figured it out. It only happens when I have around 20 villagers near the siren. I think the sound of the villagers running is stopping my sound. Any way to fix this? It doesnt happen when theres only a few villagers.

Posted

Do I actually need packets, or can I just mark the block for update?

 

Edit: Marking the block for update seems to work fine, it pushes the correct shouldStop value to the client, and then the client retrieves that and uses it.

Posted

Neither do I. You know the sound that plays when you spawn a ton of mobs in a limited space? It sounds sorta like footsteps running. If i have a few villagers, and I activate the sound and they panic, the siren keeps playing. If there are closer to 20 or so villagers, and I activate the siren and they panic, as soon as that strange footstep sound starts playing, the siren cuts out. Its like Minecraft is stopping my sound based on priority or something like that. Can you think of a workaround for this?

Posted

If you go into an MC world and spawn about 15 - 20 mobs in an enclosed space, they start to spam that weird footstep sound. And that makes sense now, because killing off one villager will allow the sound to play a bit longer than before.

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.