Skip to content

Commit

Permalink
Made sound profiles optional
Browse files Browse the repository at this point in the history
  • Loading branch information
50ap5ud5 committed Aug 18, 2024
1 parent 4035590 commit 0bed68e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void playDoorCloseSound(boolean closeDoor) {
ShellPattern pattern = this.pattern();
if (pattern != null){
Level currentLevel = this.getLevel();
ConfiguredSound configuredSound = pattern.soundProfile().getDoorClose();
ConfiguredSound configuredSound = pattern.soundProfile().get().getDoorClose();
if (configuredSound != null){
currentLevel.playSound(null, this.getBlockPos(), configuredSound.getSoundEvent(), SoundSource.BLOCKS, configuredSound.getPitch(), configuredSound.getVolume());
}
Expand All @@ -189,10 +189,12 @@ public void playDoorLockedSound(boolean lockDoor) {
ShellPattern pattern = this.pattern();
if (pattern != null){
Level currentLevel = this.getLevel();
ConfiguredSound configuredSound = pattern.soundProfile().getDoorLocked();
ConfiguredSound configuredSound = pattern.soundProfile().get().getDoorLocked();
if (configuredSound != null){
currentLevel.playSound(null, this.getBlockPos(), configuredSound.getSoundEvent(), SoundSource.BLOCKS, configuredSound.getPitch(), configuredSound.getVolume());
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ConfiguredSound getSuccessSound(TardisLevelOperator operator, ConsoleThem
pattern = consoleBlockEntity.pattern();
}

var pitchedSound = (leftClick) ? pattern.soundProfile().getGeneric().leftClick(): pattern.soundProfile().getGeneric().rightClick();
var pitchedSound = (leftClick) ? pattern.soundProfile().get().getGeneric().leftClick(): pattern.soundProfile().get().getGeneric().rightClick();
if (pitchedSound != null){
this.successSound = pitchedSound;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ConfiguredSound getSuccessSound(TardisLevelOperator operator, ConsoleThem
if (blockEntity != null){
if (blockEntity instanceof GlobalDoorBlockEntity internalDoor){
var isDoorOpen = internalDoor.isOpen();
var pitchedSound = (isDoorOpen) ? internalDoor.pattern().soundProfile().getDoorClose() : internalDoor.pattern().soundProfile().getDoorOpen();
var pitchedSound = (isDoorOpen) ? internalDoor.pattern().soundProfile().get().getDoorClose() : internalDoor.pattern().soundProfile().get().getDoorOpen();
if (pitchedSound != null) {
return pitchedSound;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import net.minecraft.resources.ResourceLocation;
import whocraft.tardis_refined.TardisRefined;
import whocraft.tardis_refined.patterns.sound.ConsoleSoundProfile;
import whocraft.tardis_refined.patterns.sound.TRConsoleSoundProfiles;

import java.util.Optional;

public class ConsolePattern extends BasePattern {

Expand All @@ -13,24 +16,24 @@ public class ConsolePattern extends BasePattern {
ResourceLocation.CODEC.fieldOf("id").forGetter(ConsolePattern::id),
Codec.STRING.orElse("Placeholder").fieldOf("name_component").forGetter(BasePattern::name),
PatternTexture.getCodec().fieldOf("texture_definition").forGetter(ConsolePattern::patternTexture),
ConsoleSoundProfile.CODEC.fieldOf("sound_profile").forGetter(ConsolePattern::soundProfile)
ConsoleSoundProfile.CODEC.optionalFieldOf("sound_profile").orElse(Optional.of(TRConsoleSoundProfiles.DEFAULT_SOUND_PROFILE)).forGetter(ConsolePattern::soundProfile)
).apply(instance, ConsolePattern::new);
});

private final PatternTexture patternTexture;
private final ConsoleSoundProfile consoleSoundProfile;
private final Optional<ConsoleSoundProfile> consoleSoundProfile;

public ConsolePattern(String identifier, PatternTexture textureDefinition, ConsoleSoundProfile consoleSoundProfile) {
public ConsolePattern(String identifier, PatternTexture textureDefinition, Optional<ConsoleSoundProfile> consoleSoundProfile) {
this(new ResourceLocation(TardisRefined.MODID, identifier), textureDefinition, consoleSoundProfile);
}

public ConsolePattern(ResourceLocation identifier, PatternTexture textureDefinition, ConsoleSoundProfile consoleSoundProfile) {
public ConsolePattern(ResourceLocation identifier, PatternTexture textureDefinition, Optional<ConsoleSoundProfile> consoleSoundProfile) {
super(identifier);
this.patternTexture = textureDefinition;
this.consoleSoundProfile = consoleSoundProfile;
}

public ConsolePattern(ResourceLocation identifier, String name, PatternTexture textureDefinition, ConsoleSoundProfile consoleSoundProfile) {
public ConsolePattern(ResourceLocation identifier, String name, PatternTexture textureDefinition, Optional<ConsoleSoundProfile> consoleSoundProfile) {
super(identifier, name);
this.patternTexture = textureDefinition;
this.consoleSoundProfile = consoleSoundProfile;
Expand All @@ -48,7 +51,7 @@ public ResourceLocation emissiveTexture(){
return this.patternTexture.emissiveTexture();
}

public ConsoleSoundProfile soundProfile() {
public Optional<ConsoleSoundProfile> soundProfile() {
return this.consoleSoundProfile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ConsolePatterns{

private static Map<ResourceLocation, List<ConsolePattern>> DEFAULT_PATTERNS = new HashMap();

public static final ConsolePattern DEFAULT = (ConsolePattern) new ConsolePattern(ResourceConstants.DEFAULT_PATTERN_ID, new PatternTexture(createConsolePatternTextureLocation(ConsoleTheme.FACTORY.getId(), ConsoleTheme.FACTORY.getId().getPath() + "_console"), true), TRConsoleSoundProfiles.DEFAULT_SOUND_PROFILE).setThemeId(ConsoleTheme.FACTORY.getId());
public static final ConsolePattern DEFAULT = (ConsolePattern) new ConsolePattern(ResourceConstants.DEFAULT_PATTERN_ID, new PatternTexture(createConsolePatternTextureLocation(ConsoleTheme.FACTORY.getId(), ConsoleTheme.FACTORY.getId().getPath() + "_console"), true), Optional.of(TRConsoleSoundProfiles.DEFAULT_SOUND_PROFILE)).setThemeId(ConsoleTheme.FACTORY.getId());

public static PatternReloadListener<ConsolePatternCollection, ConsolePattern> getReloadListener(){
return PATTERNS;
Expand Down Expand Up @@ -101,7 +101,7 @@ public static ConsolePattern next(List<ConsolePattern> patterns, ConsolePattern
}

private static ConsolePattern addDefaultPattern(ResourceLocation themeId, String patternId, String textureName, boolean hasEmissiveTexture) {
return addDefaultPattern(themeId, patternId, textureName, hasEmissiveTexture, TRConsoleSoundProfiles.DEFAULT_SOUND_PROFILE);
return addDefaultPattern(themeId, patternId, textureName, hasEmissiveTexture, Optional.of(TRConsoleSoundProfiles.DEFAULT_SOUND_PROFILE));
}


Expand All @@ -110,7 +110,7 @@ private static ConsolePattern addDefaultPattern(ResourceLocation themeId, String
* <br> Also assigns the {@link ConsolePattern} its parent {@link ConsoleTheme}'s ID
* @implSpec INTERNAL USE ONLY
* */
private static ConsolePattern addDefaultPattern(ResourceLocation themeId, String patternId, String textureName, boolean hasEmissiveTexture, ConsoleSoundProfile soundProfile) {
private static ConsolePattern addDefaultPattern(ResourceLocation themeId, String patternId, String textureName, boolean hasEmissiveTexture, Optional<ConsoleSoundProfile> soundProfile) {
List<ConsolePattern> consolePatternList;
ConsolePattern pattern = (ConsolePattern) new ConsolePattern(patternId, new PatternTexture(createConsolePatternTextureLocation(themeId,textureName), hasEmissiveTexture), soundProfile).setThemeId(themeId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import net.minecraft.resources.ResourceLocation;
import whocraft.tardis_refined.common.util.RegistryHelper;
import whocraft.tardis_refined.patterns.sound.ShellSoundProfile;
import whocraft.tardis_refined.patterns.sound.TRShellSoundProfiles;

import java.util.Optional;

public class ShellPattern extends BasePattern {

Expand All @@ -14,27 +17,27 @@ public class ShellPattern extends BasePattern {
Codec.STRING.orElse("Placeholder").fieldOf("name_component").forGetter(ShellPattern::name),
PatternTexture.getCodec().fieldOf("exterior").forGetter(ShellPattern::exteriorDoorTexture),
PatternTexture.getCodec().fieldOf("interior").forGetter(ShellPattern::interiorDoorTexture),
ShellSoundProfile.CODEC.fieldOf("sound_profile").forGetter(ShellPattern::soundProfile)
ShellSoundProfile.CODEC.optionalFieldOf("sound_profile").orElse(Optional.of(TRShellSoundProfiles.DEFAULT_SOUND_PROFILE)).forGetter(ShellPattern::soundProfile)
).apply(instance, ShellPattern::new);
});

private final PatternTexture interiorDoorTexture;
private final PatternTexture exteriorDoorTexture;

private final ShellSoundProfile shellSoundProfile;
private final Optional<ShellSoundProfile> shellSoundProfile;

public ShellPattern(String identifier, PatternTexture exteriorDoorTexture, PatternTexture interiorDoorTexture, ShellSoundProfile shellSoundProfile) {
public ShellPattern(String identifier, PatternTexture exteriorDoorTexture, PatternTexture interiorDoorTexture, Optional<ShellSoundProfile> shellSoundProfile) {
this(RegistryHelper.makeKey(identifier), exteriorDoorTexture, interiorDoorTexture, shellSoundProfile);
}

public ShellPattern(ResourceLocation identifier, PatternTexture exteriorDoorTexture, PatternTexture interiorDoorTexture, ShellSoundProfile shellSoundProfile) {
public ShellPattern(ResourceLocation identifier, PatternTexture exteriorDoorTexture, PatternTexture interiorDoorTexture, Optional<ShellSoundProfile> shellSoundProfile) {
super(identifier);
this.exteriorDoorTexture = exteriorDoorTexture;
this.interiorDoorTexture = interiorDoorTexture;
this.shellSoundProfile = shellSoundProfile;
}

public ShellPattern(ResourceLocation identifier, String name, PatternTexture exteriorDoorTexture, PatternTexture interiorDoorTexture, ShellSoundProfile shellSoundProfile) {
public ShellPattern(ResourceLocation identifier, String name, PatternTexture exteriorDoorTexture, PatternTexture interiorDoorTexture, Optional<ShellSoundProfile> shellSoundProfile) {
super(identifier, name);
this.exteriorDoorTexture = exteriorDoorTexture;
this.interiorDoorTexture = interiorDoorTexture;
Expand All @@ -50,7 +53,7 @@ public Codec<ShellPattern> getCodec() {
return CODEC;
}

public ShellSoundProfile soundProfile(){
public Optional<ShellSoundProfile> soundProfile(){
return this.shellSoundProfile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ShellPatterns {
private static Map<ResourceLocation, List<ShellPattern>> DEFAULT_PATTERNS = new HashMap();

public static final ShellPattern DEFAULT = (ShellPattern) new ShellPattern(ResourceConstants.DEFAULT_PATTERN_ID, new PatternTexture(exteriorTextureLocation(ShellTheme.FACTORY.getId(), ShellTheme.FACTORY.getId().getPath()), false)
, new PatternTexture(interiorTextureLocation(ShellTheme.FACTORY.getId(), ShellTheme.FACTORY.getId().getPath()), false), TRShellSoundProfiles.DEFAULT_SOUND_PROFILE).setThemeId(ConsoleTheme.FACTORY.getId());
, new PatternTexture(interiorTextureLocation(ShellTheme.FACTORY.getId(), ShellTheme.FACTORY.getId().getPath()), false), Optional.of(TRShellSoundProfiles.DEFAULT_SOUND_PROFILE)).setThemeId(ConsoleTheme.FACTORY.getId());

public static PatternReloadListener<ShellPatternCollection, ShellPattern> getReloadListener(){
return PATTERNS;
Expand Down Expand Up @@ -124,10 +124,10 @@ public static ShellPattern addDefaultPattern(ResourceLocation themeId, ShellPatt
}

public static ShellPattern addDefaultPattern(ResourceLocation themeId, String patternName, boolean hasEmissiveTexture) {
return addDefaultPattern(themeId, patternName, hasEmissiveTexture, TRShellSoundProfiles.DEFAULT_SOUND_PROFILE);
return addDefaultPattern(themeId, patternName, hasEmissiveTexture, Optional.of(TRShellSoundProfiles.DEFAULT_SOUND_PROFILE));
}

public static ShellPattern addDefaultPattern(ResourceLocation themeId, String patternName, boolean hasEmissiveTexture, ShellSoundProfile soundProfile) {
public static ShellPattern addDefaultPattern(ResourceLocation themeId, String patternName, boolean hasEmissiveTexture, Optional<ShellSoundProfile> soundProfile) {
ShellPattern pattern = (ShellPattern) new ShellPattern(patternName, new PatternTexture(exteriorTextureLocation(themeId, patternName), hasEmissiveTexture)
, new PatternTexture(interiorTextureLocation(themeId, patternName), hasEmissiveTexture), soundProfile).setThemeId(themeId);
return addDefaultPattern(themeId, pattern);
Expand Down Expand Up @@ -175,7 +175,7 @@ public static Map<ResourceLocation, List<ShellPattern>> registerDefaultPatterns(

//Use an overload version of the method for default shells because the texture files were named based on shell theme name
ShellPattern pattern = new ShellPattern(ResourceConstants.DEFAULT_PATTERN_ID, new PatternTexture(exteriorTextureLocation(shellTheme, textureName), hasDefaultEmission)
, new PatternTexture(interiorTextureLocation(shellTheme, textureName), hasDefaultEmission), soundProfile);
, new PatternTexture(interiorTextureLocation(shellTheme, textureName), hasDefaultEmission), Optional.of(soundProfile));
addDefaultPattern(shellTheme, pattern);
}

Expand Down

0 comments on commit 0bed68e

Please sign in to comment.