Jump to content

Recommended Posts

Posted

Hi guys, I'm new to the group. It's really great to see one single location for modders to exchange information between one another. I look forward to being a part of the forge community for a long time!

 

My question is about being able to play the creeper primed sound at a player location. I've created a simple command class that runs fine, but It doesn't seem to want to play the sound when I get in-game. Mind helping a newbie out? I noticed there are several versions of the playSound() method and I've tried them all to no avail. There must be something simple that I'm missing. Here's the execute method in question that won't play the sound.

 

I was also wondering if using thread.sleep() is considered alright to insert a delay. I'd love to have a short delay between the sound playing and the rest of my code.

 

 @Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException{
    	if (args.length <= 0)
        {
            throw new WrongUsageException("Must give player name.", new Object[0]);
        }
    	if (sender instanceof EntityPlayer){
    		EntityPlayer entityplayer = args.length >= 1 ? getPlayer(server, sender, args[0]) : getCommandSenderAsPlayer(sender);
    		server.getEntityWorld().playSound(entityplayer.getPosition().getX(), entityplayer.getPosition().getY(), entityplayer.getPosition().getZ(), SoundEvents.ENTITY_CREEPER_PRIMED, SoundCategory.HOSTILE, 1.0F, 0.5F, false); //one of many i've tried.
    	}
    }

 

Thanks for any help!

Posted

Hi guys, I'm new to the group. It's really great to see one single location for modders to exchange information between one another. I look forward to being a part of the forge community for a long time!

 

My question is about being able to play the creeper primed sound at a player location. I've created a simple command class that runs fine, but It doesn't seem to want to play the sound when I get in-game. Mind helping a newbie out? I noticed there are several versions of the playSound() method and I've tried them all to no avail. There must be something simple that I'm missing. Here's the execute method in question that won't play the sound.

 

I was also wondering if using thread.sleep() is considered alright to insert a delay. I'd love to have a short delay between the sound playing and the rest of my code.

 

 @Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException{
    	if (args.length <= 0)
        {
            throw new WrongUsageException("Must give player name.", new Object[0]);
        }
    	if (sender instanceof EntityPlayer){
    		EntityPlayer entityplayer = args.length >= 1 ? getPlayer(server, sender, args[0]) : getCommandSenderAsPlayer(sender);
    		server.getEntityWorld().playSound(entityplayer.getPosition().getX(), entityplayer.getPosition().getY(), entityplayer.getPosition().getZ(), SoundEvents.ENTITY_CREEPER_PRIMED, SoundCategory.HOSTILE, 1.0F, 0.5F, false); //one of many i've tried.
    	}
    }

 

Thanks for any help!

First off no Thread.sleep() is not a valid way of doing that. It puts the whole thread asleep. IE no game play the entire thing pauses. And I wonder why that method does nothing....oh wait

From the World class.

    public void playSound(double x, double y, double z, SoundEvent soundIn, SoundCategory category, float volume, float pitch, boolean distanceDelay)
    {
    }

 

Edit: Off topic, but something I found very funny that can be done.

   

PositionedSoundRecord sound = new PositionedSoundRecord(SoundEvents.ENTITY_CREEPER_PRIMED, SoundCategory.HOSTILE, 1, 1, new BlockPos(0, 0, 0));
    @Override
    @SideOnly(Side.CLIENT)
    public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
	if (!Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(sound)) {
		sound = new PositionedSoundRecord(SoundEvents.ENTITY_CREEPER_PRIMED, SoundCategory.HOSTILE, 1, 1, playerIn.getPosition());
		Minecraft.getMinecraft().getSoundHandler().playSound(sound);
	}
    }

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

If it's a delay you want, thread.sleep() definitely won't work as intended, as the post above says. The proper method would depend on what's playing the sounds; if it's an item, consider saving and adding to the countdown in its NBT data; if it's a tile entity, just create an integer in the tile entity's class and add to it in update(); if it's the player itself (or another entity), you might want to look into capabilities.

Posted

The documentation on sounds has a very useful list and explanation of the various methods to play sounds.

 

Thank you everyone for your help!

 

diesieben07, that link was really helpful. Turns out all I needed to do was null the EntityPlayer argument and use a different version of the World's playSound method.

 

Here's the code if anyone falls into a similar issue!

 

entityplayer.worldObj.playSound(null, entityplayer.getPosition().getX(), entityplayer.getPosition().getY(), entityplayer.getPosition().getZ(), SoundEvents.ENTITY_CREEPER_PRIMED, SoundCategory.HOSTILE, 1.0F, 0.5F);

 

 

Posted
I've created a simple command class...

 

Doesn't vanilla MC already have a command to play a sound at a player?

 

From another forum:

If you type 
    /playsound (sound) (Player) [x] [y] [z] [volume] [pitch/speed] [minimumvolume]
then the game will play the sound you entered

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

I've created a simple command class...

 

Doesn't vanilla MC already have a command to play a sound at a player?

 

From another forum:

If you type 
    /playsound (sound) (Player) [x] [y] [z] [volume] [pitch/speed] [minimumvolume]
then the game will play the sound you entered

 

Oh! Good to know :)

 

but sadly I still cant find a way to play the sound, wait 1 second, and then perform the rest of my code.

Posted

as mentioned above it could be a TE or a Capability for the player. Once the sounds plays, it enables a state to be set that says "perform my logic after x amount of ticks" which MC 20 ticks is about 1 sec RL time. If you want delays you will have to setup your own counter system. As mentioned before Thread.Sleep() is a no no.

Posted

as mentioned above it could be a TE or a Capability for the player. Once the sounds plays, it enables a state to be set that says "perform my logic after x amount of ticks" which MC 20 ticks is about 1 sec RL time. If you want delays you will have to setup your own counter system. As mentioned before Thread.Sleep() is a no no.

 

Thanks hugo. Ya, I checked up on Capabilities, something that I've never worked with before. My sound is playing through the World object, so I guess I'd have to change it back to an EntityPlayer in order to work on Capabilities from there.

 

So is the logic behind this something like: I create a capability interface and storage, register it, attach it to the EntityPlayer, and lastly make a handler for the capability to fire whenever my command is initiated? I hope I have this right....

Posted

Create a Capability, CapabilityData, and a CapbilityProvider. You then attach it to players or all entities if you wish. You can make an additional handler, but if you store the needed information in the capability you can simply access it wherever you need be. Say like in an update event

 

event.getEntity().getCapability(YourCapabilityHere,null).aFieldOrMethodInsideYourCapability;

 

Feel free to dig around my code which is in my sig to get an idea of how I've implemented capabilities. Most packages are named to contain things that make sense. So comms would be all my packets and proxies.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • logs too big for one pastebin https://pastebin.com/ZjUGHu3u  https://pastebin.com/RqCUZf3X  https://pastebin.com/6ZPS99nD
    • You probably used jd-gui to open it, didn't you? Nothing wrong with that, I also made that mistake, except that Notch was a smart guy and he obfuscated the code. That's why you only see files called "a", "b", "c" and then a file that combines them all. As I said, use RetroMCP to deobfuscate the code so that you will 100% understand it and be able to navigate it.
    • Decompiling minecraft indev, infdev, alpha, beta or whichever legacy version is really easy. I'm not a plug, I just also got interested in modding legacy versions (Infdev to be specific). Use https://github.com/MCPHackers/RetroMCP-Java Once you install their client and the Zulu Architecture that they say they recommend (or use your own Java). I encountered some problems, so I run it with: "java -jar RetroMCP-Java-CLI.jar". You should run it in a seperate folder (not in downloads), otherwise the files and folders will go all over the place. How to use RetroMCP: Type setup (every time you want change version), copy-paste the version number from their list (they support indev), write "decompile" and done! The code will now be deobfuscated and filenames will be normal, instead of "a", "b" and "c"! Hope I helped you, but I don't expect you to reply, as this discussion is 9 years old! What a piece of history!  
    • I know that this may be a basic question, but I am very new to modding. I am trying to have it so that I can create modified Vanilla loot tables that use a custom enchantment as a condition (i.e. enchantment present = item). However, I am having trouble trying to implement this; the LootItemRandomChanceWithEnchantedBonusCondition constructor needs a Holder<Enchantment> and I am unable to use the getOrThrow() method on the custom enchantment declared in my mod's enchantments class. Here is what I have so far in the GLM:   protected void start(HolderLookup.Provider registries) { HolderLookup.RegistryLookup<Enchantment> registrylookup = registries.lookupOrThrow(Registries.ENCHANTMENT); LootItemRandomChanceWithEnchantedBonusCondition lootItemRandomChanceWithEnchantedBonusCondition = new LootItemRandomChanceWithEnchantedBonusCondition(0.0f, LevelBasedValue.perLevel(0.07f), registrylookup.getOrThrow(*enchantment here*)); this.add("nebu_from_deepslate", new AddItemModifier(new LootItemCondition[]{ LootItemBlockStatePropertyCondition.hasBlockStateProperties(Blocks.DEEPSLATE).build(), LootItemRandomChanceCondition.randomChance(0.25f).build(), lootItemRandomChanceWithEnchantedBonusCondition }, OrichalcumItems.NEBU.get())); }   Inserting Enchantments.[vanilla enchantment here] actually works but trying to declare an enchantment from my custom enchantments class as [mod enchantment class].[custom enchantment] does not work even though they are both a ResourceKey and are registered in Registries.ENCHANTMENT. Basically, how would I go about making it so that a custom enchantment declared as a ResourceKey<Enchantment> of value ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath([modid], [name])), declared in a seperate enchantments class, can be used in the LootItemRandomChanceWithEnchantedBonusCondition constructor as a Holder? I can't use getOrThrow() because there is no level or block entity/entity in the start() method and it is running as datagen. It's driving me nuts.
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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