Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
OreCruncher committed Dec 23, 2018
1 parent 602d27c commit d10f692
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import org.orecruncher.lib.chunk.IBlockAccessEx;
import org.orecruncher.lib.random.XorShiftRandom;

import com.google.common.base.MoreObjects;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.audio.ISound.AttenuationType;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -88,7 +90,7 @@ protected SoundEffect(final ResourceLocation resource, final SoundCategory categ
this.conditions = StringUtils.EMPTY;
this.weight = 10;
this.type = SoundType.SPOT;
this.category = category == null ? SoundCategory.BLOCKS : category;
this.category = MoreObjects.firstNonNull(category, SoundCategory.BLOCKS);
this.variable = variable;
this.repeatDelayRandom = 0;
this.repeatDelay = repeatDelay;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static void clientDisconnect(@Nonnull final ServerDisconnectionFromClient
final NetworkDispatcher dispatcher = NetworkDispatcher.get(event.getManager());
if (dispatcher != null) {
try {
final EntityPlayerMP p = (EntityPlayerMP) player.get(dispatcher);
final EntityPlayerMP p = player.get(dispatcher);
blockList.remove(p.getPersistentID());
} catch (@Nonnull final Throwable t) {
t.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.orecruncher.dsurround.registry.config.ModConfiguration;
import org.orecruncher.lib.MCHelper;

import com.google.common.base.MoreObjects;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -170,19 +171,6 @@ protected void complete() {
ModBase.log().info("[%s] %d primitives by sound generated", getName(), this.primitives);
}

@Nullable
public IAcoustic[] getPrimitive(@Nonnull final String primitive) {
IAcoustic[] result = this.compiled.get(primitive);
if (result == null) {
final IAcoustic a = generateAcoustic(primitive);
if (a != null) {
this.compiled.put(primitive, result = new IAcoustic[] { a });
this.primitives++;
}
}
return result;
}

/**
* Used to determine what acoustics to play based on the block's sound
* attributes. It's a fallback method in case there isn't a configuration
Expand Down Expand Up @@ -233,7 +221,20 @@ public IAcoustic[] resolvePrimitive(@Nonnull final IBlockState state) {
if (acoustics == null && StringUtils.isNotEmpty(soundName))
acoustics = getPrimitive(soundName);

return acoustics != null ? acoustics : EMPTY;
return MoreObjects.firstNonNull(acoustics, EMPTY);
}

@Nullable
private IAcoustic[] getPrimitive(@Nonnull final String primitive) {
IAcoustic[] result = this.compiled.get(primitive);
if (result == null) {
final IAcoustic a = generateAcoustic(primitive);
if (a != null) {
this.compiled.put(primitive, result = new IAcoustic[] { a });
this.primitives++;
}
}
return result;
}

@Nullable
Expand All @@ -245,7 +246,7 @@ private IAcoustic[] resolveByMaterial(@Nonnull final IBlockState state) {
return result == EMPTY ? null : result;
}

public void addAcoustic(@Nonnull final IAcoustic acoustic) {
private void addAcoustic(@Nonnull final IAcoustic acoustic) {
this.acoustics.put(acoustic.getName(), acoustic);
}

Expand All @@ -254,18 +255,6 @@ public IAcoustic getAcoustic(@Nonnull final String name) {
return this.acoustics.get(name);
}

@Nonnull
public IAcoustic[] compileAcoustics(@Nonnull final SoundEvent evt) {
IAcoustic[] result = this.compiled.get(evt.getSoundName().toString());
if (result == null) {
final IAcoustic a = generateAcoustic(evt);
this.compiled.put(a.getName(), result = new IAcoustic[] { a });
} else {
this.hits++;
}
return result;
}

@Nonnull
public IAcoustic[] compileAcoustics(@Nonnull final String acousticName) {
IAcoustic[] result = this.compiled.get(acousticName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ public void reload() {
complete();
}

protected void register(@Nonnull final Biome biome) {
private void register(@Nonnull final Biome biome) {
final BiomeHandler handler = new BiomeHandler(biome);
final BiomeInfo info = new BiomeInfo(handler);
BiomeUtil.setBiomeData(biome, info);
}

protected void register(@Nonnull final IBiome biome) {
private void register(@Nonnull final IBiome biome) {
if (biome.isFake()) {
final FakeBiome fb = (FakeBiome) biome;
final BiomeInfo info = new BiomeInfo(fb);
Expand All @@ -187,7 +187,7 @@ protected void register(@Nonnull final IBiome biome) {
}

@Nullable
protected BiomeInfo resolve(@Nonnull final IBiome biome) {
private BiomeInfo resolve(@Nonnull final IBiome biome) {
if (biome.isFake()) {
final FakeBiome fb = (FakeBiome) biome;
return (BiomeInfo) fb.getBiomeData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private Stream<IBlockState> getBlockStates() {
}

@Nonnull
protected BlockStateData get(@Nonnull final IBlockState state) {
private BlockStateData get(@Nonnull final IBlockState state) {
BlockStateData profile = BlockStateUtil.getStateData(state);
if (profile == null) {
if (this.registry == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import org.orecruncher.dsurround.registry.config.SoundMetadataConfig;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;

import net.minecraft.util.SoundCategory;
Expand All @@ -40,10 +41,9 @@ public class SoundMetadata {
protected final SoundCategory category;
protected final List<String> credits;

public SoundMetadata(@Nonnull final SoundMetadataConfig cfg) {
protected SoundMetadata(@Nonnull final SoundMetadataConfig cfg) {
this.title = cfg.title;
final SoundCategory cat = translate(cfg.category);
this.category = cat != null ? cat : SoundCategory.NEUTRAL;
this.category = MoreObjects.firstNonNull(translate(cfg.category), SoundCategory.NEUTRAL);
this.credits = ImmutableList.copyOf(cfg.credits);
}

Expand Down

0 comments on commit d10f692

Please sign in to comment.