Skip to content

Commit

Permalink
Minor code cleanup, added final in places where it can be. Indentat…
Browse files Browse the repository at this point in the history
…ion fixes.
  • Loading branch information
alcatrazEscapee committed May 26, 2020
1 parent c3c36d2 commit 0416e49
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public static void resetVeinStates()
public static void register(CommandDispatcher<CommandSource> dispatcher)
{
dispatcher.register(
Commands.literal("clearworld").requires(source -> source.hasPermissionLevel(2))
.then(Commands.argument("radius", IntegerArgumentType.integer(1, 250))
.executes(cmd -> clearWorld(cmd.getSource(), IntegerArgumentType.getInteger(cmd, "radius")))));
Commands.literal("clearworld").requires(source -> source.hasPermissionLevel(2))
.then(Commands.argument("radius", IntegerArgumentType.integer(1, 250))
.executes(cmd -> clearWorld(cmd.getSource(), IntegerArgumentType.getInteger(cmd, "radius")))));
}

private static int clearWorld(CommandSource source, int radius)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.SuggestionProvider;

import static com.alcatrazescapee.oreveins.OreVeins.MOD_ID;

Expand All @@ -36,32 +35,33 @@ public final class FindVeinsCommand
{
private static final String TP_MESSAGE = "{\"text\":\"" + TextFormatting.BLUE + "[Click to Teleport]" + TextFormatting.RESET + "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/tp %d %d %d\"}}";

public static final SuggestionProvider<CommandSource> VEIN_TYPE_SUGGESTIONS = (context, builder) -> ISuggestionProvider.suggestIterable(VeinManager.INSTANCE.getKeys(), builder);

public static void register(CommandDispatcher<CommandSource> dispatcher)
{
dispatcher.register(
Commands.literal("findveins").requires(source -> source.hasPermissionLevel(2))
.then(Commands.argument("type", new VeinTypeArgument())
.suggests((context, builder) -> ISuggestionProvider.suggestIterable(VeinManager.INSTANCE.getKeys(), builder))
.then(Commands.argument("radius", IntegerArgumentType.integer(0, 250))
.executes(cmd -> findVeins(cmd.getSource(), VeinTypeArgument.getVein(cmd, "type"), IntegerArgumentType.getInteger(cmd, "radius")))
)));
Commands.literal("findveins").requires(source -> source.hasPermissionLevel(2))
.then(Commands.argument("type", new VeinTypeArgument())
.suggests((context, builder) -> ISuggestionProvider.suggestIterable(VeinManager.INSTANCE.getKeys(), builder))
.then(Commands.argument("radius", IntegerArgumentType.integer(0, 250))
.executes(cmd -> findVeins(cmd.getSource(), VeinTypeArgument.getVein(cmd, "type"), IntegerArgumentType.getInteger(cmd, "radius")))
)
)
);
}

private static int findVeins(CommandSource source, ResourceLocation veinName, int radius) throws CommandSyntaxException
{
final BlockPos pos = new BlockPos(source.getPos());
final int chunkX = pos.getX() >> 4, chunkZ = pos.getZ() >> 4;
final List<Vein<?>> veins = VeinsFeature.getNearbyVeins(chunkX, chunkZ, source.getWorld().getSeed(), radius);
final VeinType type = VeinManager.INSTANCE.getVein(veinName);
final VeinType<?> type = VeinManager.INSTANCE.getVein(veinName);
if (type == null)
{
source.sendErrorMessage(new TranslationTextComponent(MOD_ID + ".command.unknown_vein", veinName.toString()));
}

// Search for veins matching type
veins.removeIf(x -> x.getType() != type);
//noinspection EqualsBetweenInconvertibleTypes
veins.removeIf(x -> !x.getType().equals(type));
source.sendFeedback(new TranslationTextComponent(MOD_ID + ".command.veins_found"), true);
for (Vein<?> vein : veins)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public final class VeinInfoCommand
public static void register(CommandDispatcher<CommandSource> dispatcher)
{
dispatcher.register(
Commands.literal("veininfo").requires(source -> source.hasPermissionLevel(2))
.then(Commands.argument("type", new VeinTypeArgument())
.executes(cmd -> veinInfo(cmd.getSource(), VeinTypeArgument.getVein(cmd, "type")))
));
Commands.literal("veininfo").requires(source -> source.hasPermissionLevel(2))
.then(Commands.argument("type", new VeinTypeArgument())
.executes(cmd -> veinInfo(cmd.getSource(), VeinTypeArgument.getVein(cmd, "type")))
));
}

private static int veinInfo(CommandSource source, ResourceLocation veinName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static <E> IWeightedList<E> singleton(E element)
{
return new IWeightedList<E>()
{
private Collection<E> elementSet = Collections.singleton(element);
private final Collection<E> elementSet = Collections.singleton(element);

@Override
public void add(double weight, E element) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

public class WeightedList<E> implements IWeightedList<E>
{
private final NavigableMap<Double, E> map;
private double totalWeight;
private NavigableMap<Double, E> map;

public WeightedList()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
@ParametersAreNonnullByDefault
public class TouchingRule implements IRule
{
private Predicate<BlockState> blockMatcher;
private int minMatches, maxMatches;
private final Predicate<BlockState> blockMatcher;
private final int minMatches;
private final int maxMatches;

private TouchingRule(Predicate<BlockState> blockMatcher, int minMatches, int maxMatches)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public float getChanceToGenerate(VeinCluster vein, BlockPos pos)
final double dz = Math.pow(c.pos.getZ() - pos.getZ(), 2);

final float radius = (float) ((dx + dz) / (horizontalSize * horizontalSize * vein.getSize() * c.size) +
dy / (verticalSize * verticalSize * vein.getSize() * c.size));
dy / (verticalSize * verticalSize * vein.getSize() * c.size));

if (shortestRadius == -1 || radius < shortestRadius) shortestRadius = radius;
}
Expand Down Expand Up @@ -77,9 +77,9 @@ private VeinCluster(ClusterVeinType type, BlockPos pos, Random rand)
for (int i = 1; i < clusters; i++)
{
final BlockPos clusterPos = pos.add(
type.horizontalSize * (0.3f - 0.6f * rand.nextFloat()),
type.verticalSize * (0.3f - 0.6f * rand.nextFloat()),
type.horizontalSize * (0.3f - 0.6f * rand.nextFloat())
type.horizontalSize * (0.3f - 0.6f * rand.nextFloat()),
type.verticalSize * (0.3f - 0.6f * rand.nextFloat()),
type.horizontalSize * (0.3f - 0.6f * rand.nextFloat())
);
spawnPoints[i] = new Cluster(clusterPos, 0.2f + 0.5f * rand.nextFloat());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public VeinCurve createVein(int chunkX, int chunkZ, Random rand)
static class VeinCurve extends Vein<CurveVeinType>
{
private final Random rand;
private final List<CurveSegment> segmentList;
private boolean isInitialized = false;
private List<CurveSegment> segmentList;

VeinCurve(CurveVeinType type, BlockPos pos, Random random)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public float getChanceToGenerate(Vein<?> vein, BlockPos pos)
final double dz = Math.pow(vein.getPos().getZ() - pos.getZ(), 2);

final float radius = (float) ((dx + dz) / (horizontalSize * horizontalSize * vein.getSize()) +
dy / (verticalSize * verticalSize * vein.getSize()));
dy / (verticalSize * verticalSize * vein.getSize()));
return 0.005f * density * (1.0f - radius);
}
}

0 comments on commit 0416e49

Please sign in to comment.