Posted May 24, 201510 yr 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?
May 24, 201510 yr Author 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(); } } }
May 24, 201510 yr Author So how would I go about doing this? Extend EntityVillager, and set it so when an IExtendedEntityProperty changes to true, I activate the task?
May 25, 201510 yr Author 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?
May 26, 201510 yr Author 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;} }
May 26, 201510 yr Author 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.
May 27, 201510 yr Author It seems to work fine, even on a dedicated server. Any idea why my sirens stop when I implement that AI?
May 28, 201510 yr Author 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.
May 28, 201510 yr Author 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.
May 29, 201510 yr Author Do I have to put my sound on a separate thread? I think I saw something like this before.
May 29, 201510 yr Author Nothing has changed, except for me updating the shouldStop field to the client. It only stops when you can start to hear the villagers footsteps running, at about 20 or so villagers spawned.
May 30, 201510 yr Author 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.
May 30, 201510 yr Author 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?
May 30, 201510 yr Author So can I put my sound on a separate thread? Or is that just not possible. I thought I saw something about this before.
May 30, 201510 yr Author 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.