If I were to provide code from a working Minecraft Forge mod for Minecraft 1.4.7…
- User
If I were to provide code from a working Minecraft Forge mod for Minecraft 1.4.7 involving altering sounds for blocks (such as by metadata), would you be able to update most or all of it to the newer sound system in Minecraft Forge for Minecraft 1.7.10? In 1.4.7, the names of the sounds were passed as Strings, but this was changed at some point between then at 1.7.10 to use Block.SoundType.
- Assistant
Yes, I can help you update the code to the new sound system in Minecraft Forge for Minecraft 1.7.10. Please share the code you have for the 1.4.7 version, and I will assist you in making the necessary changes to utilize the Block.SoundType in the updated version.
- User
- Assistant
- User
Your code has some issues... how about we go one step up and just pass the SoundSourceEvent directly to the method instead of all the seperate variables, and start over from there?
- Assistant
Apologies for the confusion. Let's start fresh and update the code to use the SoundSourceEvent instead. Here's the revised version:
- User
I'm sorry, looking closer, SoundSourceEvent is not a good choice to use, as it does not have the location information - it looks to instead be used for things like menu button presses. What would you suggest using instead, given that we're wanting to work with Block sounds? Or is there nothing good to use in this version?
- Assistant
- User
The original Block sound is obtained by the sound manager getting a public field in Block directly. How do you recommend changing the sound type by metadata like was done prior, or should all of the affected blocks in the mod be split into different blocks by sound type?
- Assistant
If you want to change the sound type based on metadata as you did previously, you can create custom block classes for each sound type variation. These custom block classes can extend the existing block classes and specify the desired sound type based on the metadata of the block.
Here's an example of how you can create custom block classes for different sound types:
public class CustomBlockHayBlock extends BlockHayBlock { public CustomBlockHayBlock() { super(); } @Override public Block.SoundType getStepSound(int metadata) { if (metadata >= 0 && metadata <= 9) return SoundType.GROUND; if (metadata >= 10 && metadata <= 12) return SoundType.SAND; if (metadata == 15) return SoundType.STONE; return SoundType.GROUND; } } public class CustomBlockTree extends BlockLog { public CustomBlockTree() { super(); } @Override public Block.SoundType getStepSound(int metadata) { if (metadata == 1 || metadata == 7 || metadata > 11) return SoundType.WOOD; return SoundType.GROUND; } } - User
Where in the vanilla code is the sound for breaking a painting located in Minecraft 1.7.10?
- Assistant
In Minecraft 1.7.10, the sound for breaking a painting is located in the
ItemPaintingclass.The relevant code can be found in the
ItemPaintingclass, which is located in thenet.minecraft.itempackage of the Minecraft source code.Here's an example of the sound being played when breaking a painting in Minecraft 1.7.10:
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { if (side == EnumFacing.DOWN && side != EnumFacing.UP && player.canPlayerEdit(pos.offset(side), side, stack)) { if (world.isAirBlock(pos.up())) { int i = EnumArt.maxArtTitle(); float f = 0.5F; float f1 = 1.0F; if (side == EnumFacing.UP && !world.isRemote && stack.stackSize == 1) { ItemFrame