Skip to content

Commit

Permalink
fixed missing default constructor in config
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad2305m committed Dec 5, 2021
1 parent 82481ee commit a26bc10
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/sonicether/soundphysics/SoundPhysics.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.sonicether.soundphysics;

import com.sonicether.soundphysics.config.ConfigManager;
import com.sonicether.soundphysics.config.ReflectivityPair;
import com.sonicether.soundphysics.config.ReverbParams;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.Formatting;
import net.minecraft.util.Pair;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -201,7 +201,7 @@ private static float getBlockReflectivity(final BlockPos blockPos)
double reflectivity = ConfigManager.getConfig().Material_Properties.reflectivityMap.get("DEFAULT").getLeft();

String key = SoundPhysicsMod.blockSoundGroups.get(soundType).getLeft();
reflectivity = ConfigManager.getConfig().Material_Properties.reflectivityMap.getOrDefault(key, new Pair<>(reflectivity, "")).getLeft();
reflectivity = ConfigManager.getConfig().Material_Properties.reflectivityMap.getOrDefault(key, new ReflectivityPair(reflectivity, "")).getLeft();

reflectivity *= ConfigManager.getConfig().General.globalBlockReflectance;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.sonicether.soundphysics.config;

import net.minecraft.util.Pair;
import org.jetbrains.annotations.Nullable;

import java.util.Map;
Expand Down Expand Up @@ -41,7 +40,7 @@ public static void setPerformance(SoundPhysicsConfig.Performance performance, @N
}

public static void setMaterial_Properties(SoundPhysicsConfig.Material_Properties material_properties, @Nullable Map<String, Double> reflectivityMap) {
if (reflectivityMap != null) reflectivityMap.forEach((s, d) -> material_properties.reflectivityMap.compute(s, (k, v) -> (v == null) ? new Pair<>(d, "error") : new Pair<>(d, v.getRight())));
if (reflectivityMap != null) reflectivityMap.forEach((s, d) -> material_properties.reflectivityMap.compute(s, (k, v) -> (v == null) ? new ReflectivityPair(d, "error") : new ReflectivityPair(d, v.getRight())));
}

public static void setVlads_Tweaks(SoundPhysicsConfig.Vlads_Tweaks vlads_tweaks, @Nullable Double leakyBlocksOcclusionMultiplier, @Nullable Double maxDirectOcclusionFromBlocks, @Nullable Boolean _9RayDirectOcclusion, @Nullable Boolean soundDirectionEvaluation, @Nullable Double maxDirVariance, @Nullable Boolean notOccludedNoRedirect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
public class ConfigManager {
private static ConfigHolder<SoundPhysicsConfig> holder;
public static final SoundPhysicsConfig DEFAULT = new SoundPhysicsConfig(){{
Map<String, Pair<Double, String>> map =
Map<String, ReflectivityPair> map =
SoundPhysicsMod.blockSoundGroups.entrySet().stream()
.collect(Collectors.toMap((e)-> e.getValue().getLeft(), (e) -> new Pair<>(0.5, e.getValue().getRight())));
map.putIfAbsent("DEFAULT", new Pair<>(0.5, ""));
.collect(Collectors.toMap((e)-> e.getValue().getLeft(), (e) -> new ReflectivityPair(0.5, e.getValue().getRight())));
map.putIfAbsent("DEFAULT", new ReflectivityPair(0.5, ""));
Material_Properties.reflectivityMap = map;
}};

Expand All @@ -27,7 +27,7 @@ public static void registerAutoConfig() {

holder = AutoConfig.register(SoundPhysicsConfig.class, JanksonConfigSerializer::new);
holder.load();
if (!(holder.getConfig().Material_Properties.reflectivityMap == null)) {
if (holder.getConfig().Material_Properties.reflectivityMap == null) {
holder.getConfig().preset = ConfigPresets.DrRubisco_Signature;
holder.getConfig().Material_Properties.reflectivityMap = DEFAULT.Material_Properties.reflectivityMap;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sonicether.soundphysics.config;

public class ReflectivityPair {
public double reflectivity;
public String example;

public ReflectivityPair(double r, String s){
reflectivity = r; example = s;
}

public ReflectivityPair() { reflectivity = 0; example = null; }

public double getLeft() {return reflectivity;}
public String getRight() {return example;}
public void setLeft(double r) {reflectivity = r;}
public void setRight(String s) {example = s;}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.sonicether.soundphysics.config;

import com.sonicether.soundphysics.SoundPhysicsMod;
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.autoconfig.annotation.ConfigEntry;
import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Comment;
import net.minecraft.util.Pair;

import java.util.Map;
import java.util.stream.Collectors;

@Config(name = "sound_physics")
@Config.Gui.Background("minecraft:textures/block/note_block.png")
Expand Down Expand Up @@ -69,7 +66,7 @@ public static class Performance{
public static class Material_Properties {
@Comment("Sound reflectivity for blocks.\n0.0 - 1.0")
@ConfigEntry.Gui.CollapsibleObject
public Map<String, Pair<Double, String>> reflectivityMap = null;
public Map<String, ReflectivityPair> reflectivityMap = null;
}

public static class Vlads_Tweaks {
Expand Down

0 comments on commit a26bc10

Please sign in to comment.