Skip to content

Commit

Permalink
Implement ingredient checks, replace default sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Sep 25, 2022
1 parent e399a06 commit 6e987a5
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 59 deletions.
29 changes: 27 additions & 2 deletions src/main/java/mod/acgaming/extrasounds/config/ESConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static class SoundCategories
@Config.Name("Pick/Place Sounds")
@Config.Comment({
"Categories of sounds when picking and placing items in GUIs",
"Available categories: wood, dirt, gravel, sand, grass, wool, snow, ingot, nugget, gem, dust",
"Available categories: dirt, dust, gem, grass, gravel, ingot, nugget, sand, snow, stone, wood, wool",
"Syntax: CATEGORY;REGISTRY_NAME",
"Use * for ore dictionary wildcards",
"Examples | ingot;ore:example_ore | gem;mod_id:example_item"
Expand All @@ -141,7 +141,32 @@ public static class SoundCategories
"ingot;ore:ingot*",
"nugget;ore:nugget*",
"snow;ore:snow",
"wood;ore:stickWood"
"stone;ore:stone*",
"gem;minecraft:diamond_axe",
"gem;minecraft:diamond_hoe",
"gem;minecraft:diamond_pickaxe",
"gem;minecraft:diamond_shovel",
"gem;minecraft:diamond_sword",
"ingot;minecraft:golden_axe",
"ingot;minecraft:golden_hoe",
"ingot;minecraft:golden_pickaxe",
"ingot;minecraft:golden_shovel",
"ingot;minecraft:golden_sword",
"ingot;minecraft:iron_axe",
"ingot;minecraft:iron_hoe",
"ingot;minecraft:iron_pickaxe",
"ingot;minecraft:iron_shovel",
"ingot;minecraft:iron_sword",
"stone;minecraft:stone_axe",
"stone;minecraft:stone_hoe",
"stone;minecraft:stone_pickaxe",
"stone;minecraft:stone_shovel",
"stone;minecraft:stone_sword",
"wood;minecraft:wooden_axe",
"wood;minecraft:wooden_hoe",
"wood;minecraft:wooden_pickaxe",
"wood;minecraft:wooden_shovel",
"wood;minecraft:wooden_sword"
};
}

Expand Down
48 changes: 36 additions & 12 deletions src/main/java/mod/acgaming/extrasounds/sound/ESSoundEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class ESSoundEvents
public static SoundEvent pick_place_nugget;
public static SoundEvent pick_place_sand;
public static SoundEvent pick_place_snow;
public static SoundEvent pick_place_stone;
public static SoundEvent pick_place_wood;
public static SoundEvent pick_place_wool;
public static SoundEvent place_boat;
Expand Down Expand Up @@ -102,6 +103,7 @@ public static void preInit()
pick_place_nugget = register("pick_place_nugget");
pick_place_sand = register("pick_place_sand");
pick_place_snow = register("pick_place_snow");
pick_place_stone = register("pick_place_stone");
pick_place_wood = register("pick_place_wood");
pick_place_wool = register("pick_place_wool");
place_boat = register("place_boat");
Expand Down Expand Up @@ -130,20 +132,20 @@ public static void getBackportedSounds()
backportMap.put("assets/minecraft/sounds/block/bamboo/step6.ogg", "assets/extrasounds/sounds/block/bamboo/step6.ogg");

// PLANT CROP
backportMap.put("assets/minecraft/sounds/item/plant/crop1.ogg", "assets/extrasounds/sounds/plant/crop1.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/crop2.ogg", "assets/extrasounds/sounds/plant/crop2.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/crop3.ogg", "assets/extrasounds/sounds/plant/crop3.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/crop4.ogg", "assets/extrasounds/sounds/plant/crop4.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/crop5.ogg", "assets/extrasounds/sounds/plant/crop5.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/crop6.ogg", "assets/extrasounds/sounds/plant/crop6.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/crop1.ogg", "assets/extrasounds/sounds/item/plant/crop1.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/crop2.ogg", "assets/extrasounds/sounds/item/plant/crop2.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/crop3.ogg", "assets/extrasounds/sounds/item/plant/crop3.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/crop4.ogg", "assets/extrasounds/sounds/item/plant/crop4.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/crop5.ogg", "assets/extrasounds/sounds/item/plant/crop5.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/crop6.ogg", "assets/extrasounds/sounds/item/plant/crop6.ogg");

// PLANT NETHERWART
backportMap.put("assets/minecraft/sounds/item/plant/netherwart1.ogg", "assets/extrasounds/sounds/plant/netherwart1.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/netherwart2.ogg", "assets/extrasounds/sounds/plant/netherwart2.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/netherwart3.ogg", "assets/extrasounds/sounds/plant/netherwart3.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/netherwart4.ogg", "assets/extrasounds/sounds/plant/netherwart4.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/netherwart5.ogg", "assets/extrasounds/sounds/plant/netherwart5.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/netherwart6.ogg", "assets/extrasounds/sounds/plant/netherwart6.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/netherwart1.ogg", "assets/extrasounds/sounds/item/plant/netherwart1.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/netherwart2.ogg", "assets/extrasounds/sounds/item/plant/netherwart2.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/netherwart3.ogg", "assets/extrasounds/sounds/item/plant/netherwart3.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/netherwart4.ogg", "assets/extrasounds/sounds/item/plant/netherwart4.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/netherwart5.ogg", "assets/extrasounds/sounds/item/plant/netherwart5.ogg");
backportMap.put("assets/minecraft/sounds/item/plant/netherwart6.ogg", "assets/extrasounds/sounds/item/plant/netherwart6.ogg");

// BEACON
backportMap.put("assets/minecraft/sounds/block/beacon/ambient.ogg", "assets/extrasounds/sounds/block/beacon/ambient.ogg");
Expand Down Expand Up @@ -177,6 +179,27 @@ public static void getBackportedSounds()
backportMap.put("assets/minecraft/sounds/enchant/soulspeed/soulspeed12.ogg", "assets/extrasounds/sounds/enchant/soulspeed/soulspeed12.ogg");
backportMap.put("assets/minecraft/sounds/enchant/soulspeed/soulspeed13.ogg", "assets/extrasounds/sounds/enchant/soulspeed/soulspeed13.ogg");

// METAL
backportMap.put("assets/minecraft/sounds/block/copper/step1.ogg", "assets/extrasounds/sounds/block/copper/step1.ogg");
backportMap.put("assets/minecraft/sounds/block/copper/step2.ogg", "assets/extrasounds/sounds/block/copper/step2.ogg");
backportMap.put("assets/minecraft/sounds/block/copper/step3.ogg", "assets/extrasounds/sounds/block/copper/step3.ogg");
backportMap.put("assets/minecraft/sounds/block/copper/step4.ogg", "assets/extrasounds/sounds/block/copper/step4.ogg");
backportMap.put("assets/minecraft/sounds/block/copper/step5.ogg", "assets/extrasounds/sounds/block/copper/step5.ogg");
backportMap.put("assets/minecraft/sounds/block/copper/step6.ogg", "assets/extrasounds/sounds/block/copper/step6.ogg");

// GEM
backportMap.put("assets/minecraft/sounds/block/amethyst/place1.ogg", "assets/extrasounds/sounds/block/amethyst/place1.ogg");
backportMap.put("assets/minecraft/sounds/block/amethyst/place2.ogg", "assets/extrasounds/sounds/block/amethyst/place2.ogg");
backportMap.put("assets/minecraft/sounds/block/amethyst/place3.ogg", "assets/extrasounds/sounds/block/amethyst/place3.ogg");
backportMap.put("assets/minecraft/sounds/block/amethyst/place4.ogg", "assets/extrasounds/sounds/block/amethyst/place4.ogg");

// BONEMEAL
backportMap.put("assets/minecraft/sounds/item/bonemeal/bonemeal1.ogg", "assets/extrasounds/sounds/item/bonemeal/bonemeal1.ogg");
backportMap.put("assets/minecraft/sounds/item/bonemeal/bonemeal2.ogg", "assets/extrasounds/sounds/item/bonemeal/bonemeal2.ogg");
backportMap.put("assets/minecraft/sounds/item/bonemeal/bonemeal3.ogg", "assets/extrasounds/sounds/item/bonemeal/bonemeal3.ogg");
backportMap.put("assets/minecraft/sounds/item/bonemeal/bonemeal4.ogg", "assets/extrasounds/sounds/item/bonemeal/bonemeal4.ogg");
backportMap.put("assets/minecraft/sounds/item/bonemeal/bonemeal5.ogg", "assets/extrasounds/sounds/item/bonemeal/bonemeal5.ogg");

ExtraSounds.LOGGER.info("Downloading Minecraft 1.19.2 sounds, this could take a while...");
AssetMoverAPI.fromMinecraft("1.19.2", backportMap);
ExtraSounds.LOGGER.info("Downloading finished!");
Expand Down Expand Up @@ -224,6 +247,7 @@ public static void register(RegistryEvent.Register<SoundEvent> event)
event.getRegistry().register(pick_place_nugget);
event.getRegistry().register(pick_place_sand);
event.getRegistry().register(pick_place_snow);
event.getRegistry().register(pick_place_stone);
event.getRegistry().register(pick_place_wood);
event.getRegistry().register(pick_place_wool);
event.getRegistry().register(place_boat);
Expand Down
52 changes: 38 additions & 14 deletions src/main/java/mod/acgaming/extrasounds/sound/ESSoundManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mod.acgaming.extrasounds.sound;

import java.util.Map;
import java.util.*;

import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
Expand All @@ -9,6 +9,9 @@
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.*;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
Expand Down Expand Up @@ -53,17 +56,18 @@ public static void initSoundCategoryMap()
{
soundCategoryMap.clear();

soundCategoryMap.put("wood", ESSoundEvents.pick_place_wood);
soundCategoryMap.put("dirt", ESSoundEvents.pick_place_dirt);
soundCategoryMap.put("gravel", ESSoundEvents.pick_place_gravel);
soundCategoryMap.put("sand", ESSoundEvents.pick_place_sand);
soundCategoryMap.put("dust", ESSoundEvents.pick_place_dust);
soundCategoryMap.put("gem", ESSoundEvents.pick_place_gem);
soundCategoryMap.put("grass", ESSoundEvents.pick_place_grass);
soundCategoryMap.put("wool", ESSoundEvents.pick_place_wool);
soundCategoryMap.put("snow", ESSoundEvents.pick_place_snow);
soundCategoryMap.put("gravel", ESSoundEvents.pick_place_gravel);
soundCategoryMap.put("ingot", ESSoundEvents.pick_place_ingot);
soundCategoryMap.put("nugget", ESSoundEvents.pick_place_nugget);
soundCategoryMap.put("gem", ESSoundEvents.pick_place_gem);
soundCategoryMap.put("dust", ESSoundEvents.pick_place_dust);
soundCategoryMap.put("sand", ESSoundEvents.pick_place_sand);
soundCategoryMap.put("snow", ESSoundEvents.pick_place_snow);
soundCategoryMap.put("stone", ESSoundEvents.pick_place_stone);
soundCategoryMap.put("wood", ESSoundEvents.pick_place_wood);
soundCategoryMap.put("wool", ESSoundEvents.pick_place_wool);
}

@SuppressWarnings("ConstantConditions")
Expand Down Expand Up @@ -134,13 +138,34 @@ public static void initSoundFinalMap()
if (item instanceof ItemBlock) soundEvent = ((ItemBlock) item).getBlock().getSoundType().getPlaceSound();
else if (item instanceof ItemFood) soundEvent = ESSoundEvents.pick_place_food;
else if (item instanceof ItemArmor) soundEvent = ((ItemArmor) item).getArmorMaterial().getSoundEvent();
else if (item == Items.WATER_BUCKET) soundEvent = SoundEvents.ITEM_BUCKET_FILL;
else if (item == Items.WATER_BUCKET || item == Items.MILK_BUCKET) soundEvent = SoundEvents.ITEM_BUCKET_FILL;
else if (item == Items.LAVA_BUCKET) soundEvent = SoundEvents.ITEM_BUCKET_FILL_LAVA;
else if (item instanceof UniversalBucket)
{
FluidStack fluidStack = ((UniversalBucket) item).getFluid(new ItemStack(item));
if (fluidStack != null) soundEvent = fluidStack.getFluid().getFillSound();
}
// CHECK ITEM'S RECIPE INGREDIENTS FOR KNOWN SOUND EVENTS
else if (item.getRegistryName() != null && CraftingManager.REGISTRY.containsKey(item.getRegistryName()))
{
IRecipe recipe = CraftingManager.REGISTRY.getObject(item.getRegistryName());
if (recipe != null)
{
List<Ingredient> ingredientList = new ArrayList<>(recipe.getIngredients());
List<ItemStack> ingredientStackList = new ArrayList<>();
// GET ALL INGREDIENT ITEM STACKS
for (Ingredient ingredient : ingredientList) ingredientStackList.addAll(Arrays.asList(ingredient.getMatchingStacks()));
if (ingredientStackList.size() > 0)
{
// SORT LIST BY FREQUENCY
ingredientStackList.sort(Comparator.comparing(i -> Collections.frequency(ingredientStackList, i)).reversed());
// GET MOST FREQUENT ITEM (BEST EFFORT)
Item ingredientItem = ingredientStackList.get(0).getItem();
if (soundItemMap.containsKey(ingredientItem)) soundEvent = soundCategoryMap.get(soundItemMap.get(ingredientItem));
else if (ingredientItem instanceof ItemBlock) soundEvent = ((ItemBlock) ingredientItem).getBlock().getSoundType().getPlaceSound();
}
}
}
if (soundEvent != null) soundFinalMap.put(item, soundEvent);
}
}
Expand All @@ -157,8 +182,8 @@ public static void playSoundPlayer(SoundEvent soundEvent, float pitch, float vol
{
Minecraft mc = Minecraft.getMinecraft();
EntityPlayerSP player = mc.player;
if (player != null) mc.getSoundHandler().playSound(new PositionedSoundRecord(soundEvent.getSoundName(), SoundCategory.PLAYERS, volume, pitch, false, 0, ISound.AttenuationType.NONE, (float) player.posX, (float) player.posY + 32, (float) player.posZ));
else mc.getSoundHandler().playSound(new PositionedSoundRecord(soundEvent.getSoundName(), SoundCategory.MASTER, volume, pitch, false, 0, ISound.AttenuationType.NONE, 0F, 0F, 0F));
if (player != null) mc.getSoundHandler().playSound(new PositionedSoundRecord(soundEvent.getSoundName(), SoundCategory.PLAYERS, volume, pitch - 0.1F + randomOffset(), false, 0, ISound.AttenuationType.NONE, (float) player.posX, (float) player.posY + 32, (float) player.posZ));
else mc.getSoundHandler().playSound(new PositionedSoundRecord(soundEvent.getSoundName(), SoundCategory.MASTER, volume, pitch - 0.1F + randomOffset(), false, 0, ISound.AttenuationType.NONE, 0F, 0F, 0F));
lastPlayed = now;
}
}
Expand All @@ -170,8 +195,8 @@ public static void playSoundPlayer(SoundEvent soundEvent)
{
Minecraft mc = Minecraft.getMinecraft();
EntityPlayerSP player = mc.player;
if (player != null) mc.getSoundHandler().playSound(new PositionedSoundRecord(soundEvent.getSoundName(), SoundCategory.PLAYERS, 1.0F, 1.0F, false, 0, ISound.AttenuationType.NONE, (float) player.posX, (float) player.posY + 32, (float) player.posZ));
else mc.getSoundHandler().playSound(new PositionedSoundRecord(soundEvent.getSoundName(), SoundCategory.MASTER, 1.0F, 1.0F, false, 0, ISound.AttenuationType.NONE, 0F, 0F, 0F));
if (player != null) mc.getSoundHandler().playSound(new PositionedSoundRecord(soundEvent.getSoundName(), SoundCategory.PLAYERS, 1.0F, 0.9F + randomOffset(), false, 0, ISound.AttenuationType.NONE, (float) player.posX, (float) player.posY + 32, (float) player.posZ));
else mc.getSoundHandler().playSound(new PositionedSoundRecord(soundEvent.getSoundName(), SoundCategory.MASTER, 1.0F, 0.9F + randomOffset(), false, 0, ISound.AttenuationType.NONE, 0F, 0F, 0F));
lastPlayed = now;
}
}
Expand Down Expand Up @@ -206,7 +231,6 @@ public static void playClickSound(ItemStack stackIn)
if (stackIn.isEmpty()) return;

Item item = stackIn.getItem();

if (soundItemMap.containsKey(item)) playSoundPlayer(soundCategoryMap.get(soundItemMap.get(item)));
else if (soundFinalMap.containsKey(item)) playSoundPlayer(soundFinalMap.get(item), 2.0F, 0.4F);
else playSoundPlayer(ESSoundEvents.pick_place_generic);
Expand Down
Loading

0 comments on commit 6e987a5

Please sign in to comment.