TheRealMcrafter
-
Posts
137 -
Joined
-
Last visited
Posts posted by TheRealMcrafter
-
-
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;} }
-
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?
-
-
Thanks, Ill give this a try.
-
So how would I go about doing this? Extend EntityVillager, and set it so when an IExtendedEntityProperty changes to true, I activate the task?
-
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(); } } }
-
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?
-
Instead of setting isStriking to true in your GUI class (on the Client), you need to send a packet to the server, and then in your packet handler, you set isStriking to true (on the Server).
-
By the way, this is bad:
entity.motionX != 0
since motion fields are all floats, they suffer from approximation errors. See here, it is a really good article on that topic: http://www.theregister.co.uk/2006/08/12/floating_point_approximation/
So I'd suggest you check for "approximately" 0, like
entity.motionX > 0.0001 || entity.motionX < -0.0001
Yeah, I just quickly did that to show my point. I figured that out when I was testing for motionY, which is about 1.17. Thanks for reminding me though.
-
Or just use IExtendedEntityProperties. It takes care of all the loading and unloading for you.
How would I go about doing this?
-
How could I do this when I have more than one entity to track, and I dont know how many entities that are being tracked? An ArrayList?
-
Does anyone have a workaround for this? It appears coolAlias had troubles with this before, did you ever find a way to do it?
-
I'm checking on the server, and it is not just for the player, it is for any living entity. I am making a motion detector, so if any entity in the list moves, isDetected turns to true.
if (!worldObj.isRemote){ List list = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(this.xCoord - 10, this.yCoord - 10, this.zCoord - 10, this.xCoord + 10, this.yCoord + 10, this.zCoord + 10)); if (list.isEmpty()){ this.isDetecting = false; } else { for (int i = 0; i < list.size(); i ++){ EntityLivingBase entity = (EntityLivingBase) list.get(i); if (entity.motionX != 0){ this.isDetecting = true; } else { this.isDetecting = false; } } }
Right now I'm focusing only on motionX, but it doesn't work for Y and Z also. A System.out.println() always prints out 0.0
-
Hey guys, I want to check if an entity is moving from inside my Tile Entity updateEntity method. I have already checked if entity.prevPosX != entity.posX, I've tried using entity.motionX, and I've tried storing the old coordinates in a variable and checking against them. Entity.motion* only works if the player is sprinting, and all of the other methods I've tried don't work. Does anyone know how to do this?
-
Oh dear lord...
1. DO NOT use 'static' fields to store the player, extended properties, or anything else - clearly you don't know what it's for.
2. DO NOT use Minecraft.getMinecraft().thePlayer - that is CLIENT side only player.
3. You are still using a 'new ExtendedPlayer' - NEVER do that - the player already has an ExtendedPlayer instance created by Forge, which is why you use the ExtendedPlayer.get(player) method to retrieve it (which is just a wrapper for player.getExtendedProperties("YourProperties")).
I know, I know! I've just been trying everything possible to get this to work. (Even doing things I know I shouldnt) :'(
And THATS what I needed, I forgot I had that .get(player) method. Thanks for all your help!
Edit: Seriously, thank you so much coolAlias. Your tutorials and explanations are amazing and you dont get enough credit for what you do for the forge community
-TheRealMcrafter
-
Welp, that didn't seem to work either.
I'm doing this:
private final static ExtendedPlayer extendedPlayer = new ExtendedPlayer(Minecraft.getMinecraft().thePlayer); public static boolean tryToHolster(EntityPlayer player){ ItemStack stack = player.inventory.getCurrentItem(); ItemStack holsterSlot = extendedPlayer.inventory.getStackInSlot(0); System.err.println(holsterSlot); System.err.println(extendedPlayer.inventory.getStackInSlot(0)); if (stack != null){ if (stack.getItem() == CitiesMod.M1911){ if (holsterSlot != null){ System.err.println("Reached!"); } } else if (stack.getItem() == CitiesMod.Glock21){ if (holsterSlot != null){ System.err.println("Reached!"); } } } return false; }
-
I'm using it in a custom class, that is called when the server gets a packet from my key handler. I can't believe i missed a solution as simple as that, although I've been at this for a long time now so I probably cant see straight
-
The problem looks to be that you are always creating 'new' instances of your extended player and inventory, when what you really want is the one that should already exist:
ExtendedPlayer props = ExtendedPlayer.get(player); props.inventory.setStackInSlot(0, new ItemStack(Items.stick)); System.out.println("Stack in slot 0: " + props.inventory.getStackInSlot(0));
Oh! That makes sense! So where could I put that instance for the extended player then?
-
public class ExtendedPlayer implements IExtendedEntityProperties{ public final static String EXT_PROP_NAME = "ExtendedPlayer"; private final EntityPlayer player; public final InventoryCustomPlayer inventory = new InventoryCustomPlayer(); public ExtendedPlayer(EntityPlayer player){ this.player = player; } public static final void register(EntityPlayer player){ player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer(player)); } public static final ExtendedPlayer get(EntityPlayer player){ return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME); } // Save any custom data that needs saving here @Override public void saveNBTData(NBTTagCompound compound){ NBTTagCompound properties = new NBTTagCompound(); this.inventory.writeToNBT(properties); compound.setTag(EXT_PROP_NAME, properties); } @Override public void loadNBTData(NBTTagCompound compound){ NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); this.inventory.readFromNBT(properties); System.err.println("Loading Player's NBT: " + this.inventory.getStackInSlot(0) != null ? this.inventory.getStackInSlot(0) : ""); } @Override public void init(Entity entity, World world){ } }
-
I never said there was an error, it is just always null, even though I can see the item in the slot, and if I put the System.out... statement in InventoryCustomPlayer#getStackInSlot, and I open up my custom inventory GUI, it prints out the correct item.
-
Hey,
I have created a custom player inventory, with one extra slot. When I try to get the ItemStack in that slot, it always returns null, even if I do something like
setInventorySlotContents(0, new ItemStack(Blocks.dirt));
before a System.out.println(getStackInSlot(0))
I have tried the following ways of getting the itemstack:
ExtendedPlayer extendedPlayer = new ExtendedPlayer(getPlayer()); ItemStack holsterSlot = extendedPlayer.inventory.getStackInSlot(0);
InventoryCustomPlayer inventory = new InventoryCustomPlayer(); ItemStack holsterSlow = inventory.getStackInSlot(0);
but nothing seems to work, it always prints null.
I have tried checking the slot on the Client Side, and also sending a packet to the server side, and checking it there. Nothing seems to work.
Is this the correct way to get an ItemStack in a custom player inventory slot?
Thanks for your time,
-TheRealMcrafter
-
Your item receives update ticks (onUpdate), use that.
Can't, onUpdate is only called when the item is in a Players inventory.
EDIT: Figured it out, a bit "hackishly"
-
Hey everyone,
I have a custom GUI and Container (opened with an item) that I use to store one ItemStack. Is there any kind of onUpdate() method that I can use to get the ItemStack in that slot each tick, since I'm not using a TileEntity.
Thanks,
-TheRealMcrafter
-
Ah! Thats exactly what I was looking for. I actually did this before in my mod but when I changed some stuff i accidentally deleted the code for it, thanks so much!
How to update an entity's AI
in Modder Support
Posted
I know I could have just done
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.