Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minimal Checkstyle configuration #704

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id 'maven-publish'
id 'com.modrinth.minotaur' version '2.+'
id 'com.github.breadmoirai.github-release' version '2.4.1'
id 'checkstyle'
}

base {
Expand Down Expand Up @@ -81,6 +82,12 @@ dependencies {
testImplementation "com.code-intelligence:jazzer-junit:${project.jazzer_junit_version}"
}

checkstyle {
toolVersion = project.checkstyle_version
configFile = rootProject.file("checkstyle.xml")
ignoreFailures = false
}

test {
useJUnitPlatform()
systemProperty('clientcommands.regressionTestDir', file('regressionTests').absolutePath)
Expand Down
28 changes: 28 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
<property name="fileExtensions" value="java"/>
<module name="NewlineAtEndOfFile"/>

<module name="TreeWalker">
<module name="SuppressionCommentFilter"/>

<module name="AvoidStarImport">
<property name="allowStaticMemberImports" value="true"/>
</module>

<module name="NeedBraces">
<property name="tokens" value="LITERAL_DO, LITERAL_ELSE, LITERAL_FOR, LITERAL_IF, LITERAL_WHILE"/>
<property name="allowEmptyLoopBody" value="true"/>
</module>
<module name="WhitespaceAfter">
<property name="tokens" value="COMMA, SEMI, TYPECAST, LITERAL_IF, LITERAL_ELSE, LITERAL_RETURN, LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, LITERAL_FINALLY, DO_WHILE, ELLIPSIS, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_CATCH, LAMBDA, LITERAL_YIELD, LITERAL_CASE, LITERAL_WHEN"/>
</module>

<module name="MatchXpath">
<property name="query" value="//STATIC_IMPORT[./LITERAL_STATIC and not(.//STAR)]"/>
<message key="matchxpath.match" value="Static imports should always use wildcard imports"/>
</module>
</module>
</module>
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ org.gradle.jvmargs=-Xmx2G
seedfinding_feature_version=1.171.9
seedfinding_seed_version=1.171.2
latticg_version=1.07
checkstyle_version=10.21.1

jazzer_junit_version=0.22.1
junit_version=5.11.3
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// CHECKSTYLE:OFF: AvoidStarImport allow commands to be wildcard imported
package net.earthcomputer.clientcommands;

import com.mojang.brigadier.CommandDispatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private static int listAliases(FabricClientCommandSource source) {
} else {
source.sendFeedback(Component.translatable("commands.calias.listAliases.success", aliasMap.size()));
for (String key : aliasMap.keySet()) {
source.sendFeedback(Component.literal(ChatFormatting.BOLD + key + ChatFormatting.RESET + ": " + aliasMap.get(key).replace("%","%%")));
source.sendFeedback(Component.literal(ChatFormatting.BOLD + key + ChatFormatting.RESET + ": " + aliasMap.get(key).replace("%", "%%")));
}
}
return Command.SINGLE_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static int cenchant(FabricClientCommandSource source, ItemAndEnchantment
if (result.itemThrows() < 0) {
source.sendFeedback(Component.translatable("enchCrack.insn.itemThrows.noDummy"));
} else {
source.sendFeedback(Component.translatable("enchCrack.insn.itemThrows", result.itemThrows(), (float)result.itemThrows() / (Configs.itemThrowsPerTick * 20)));
source.sendFeedback(Component.translatable("enchCrack.insn.itemThrows", result.itemThrows(), (float) result.itemThrows() / (Configs.itemThrowsPerTick * 20)));
}
source.sendFeedback(Component.translatable("enchCrack.insn.bookshelves", result.bookshelves()));
source.sendFeedback(Component.translatable("enchCrack.insn.slot", result.slot() + 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ private static int executeTimes(FabricClientCommandSource source, int fadeIn, in
sendFeedback(Component.translatable("commands.ctitle.times"));
return Command.SINGLE_SUCCESS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
.then(literal("west")
.executes(ctx -> lookCardinal(ctx.getSource(), 90, 0)))
.then(literal("east")
.executes(ctx -> lookCardinal(ctx.getSource(),-90, 0)))
.executes(ctx -> lookCardinal(ctx.getSource(), -90, 0)))
.then(literal("north")
.executes(ctx -> lookCardinal(ctx.getSource(), -180, 0)))
.then(literal("south")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ private Expression parseConstantOrFunction() throws CommandSyntaxException {

reader.setCursor(cursor);

if (reader.canRead() && reader.peek() == '(')
if (reader.canRead() && reader.peek() == '(') {
suggestor = null;
}

Expression ret = parseParenthesized();
suggestor = null;
Expand Down Expand Up @@ -437,10 +438,10 @@ public boolean isAcceptableInputCount(int count) {
}
})
.put("acoth", (UnaryFunction) n -> 0.5 * Math.log((n + 1) / (n - 1)))
.put("and", (TwoOrMoreFunction) vals -> (double)Arrays.stream(vals).mapToInt(val -> (int) val).reduce(~0, (a, b) -> a & b))
.put("or", (TwoOrMoreFunction) vals -> (double)Arrays.stream(vals).mapToInt(val -> (int) val).reduce(0, (a, b) -> a | b))
.put("xor", (TwoOrMoreFunction) vals -> (double)Arrays.stream(vals).mapToInt(val -> (int) val).reduce(0, (a, b) -> a ^ b))
.put("not", (UnaryFunction) val -> (double)(~((int)val)))
.put("and", (TwoOrMoreFunction) vals -> (double) Arrays.stream(vals).mapToInt(val -> (int) val).reduce(~0, (a, b) -> a & b))
.put("or", (TwoOrMoreFunction) vals -> (double) Arrays.stream(vals).mapToInt(val -> (int) val).reduce(0, (a, b) -> a | b))
.put("xor", (TwoOrMoreFunction) vals -> (double) Arrays.stream(vals).mapToInt(val -> (int) val).reduce(0, (a, b) -> a ^ b))
.put("not", (UnaryFunction) val -> (double) (~((int) val)))
.build();

private final String type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private static OptionalLong getSeed(UUID uuid) {
long b = (-4824621L * upperBits + 7847617L * lowerBits + 7847617L) >> 32;
long seed = 7847617L * a - 18218081L * b;

if ((seed >>> 16 << 32) + (int)(((seed * 0x5deece66dL + 0xbL) & ((1L << 48) - 1)) >>> 16) == nextLongOutput) {
if ((seed >>> 16 << 32) + (int) (((seed * 0x5deece66dL + 0xbL) & ((1L << 48) - 1)) >>> 16) == nextLongOutput) {
// advance by -3
seed = (seed * 0x13A1F16F099DL + 0x95756C5D2097L) & ((1L << 48) - 1);
RandomSource rand = RandomSource.create(seed ^ 0x5deece66dL);
Expand Down Expand Up @@ -985,12 +985,12 @@ public void tick() {
} else {
if (this.state == State.BOBBING) {
Vec3 vec3 = this.velocity;
double d = this.pos.y + vec3.y - (double)blockPos.getY() - (double)f;
double d = this.pos.y + vec3.y - (double) blockPos.getY() - (double) f;
if (Math.abs(d) < 0.01D) {
d += Math.signum(d) * 0.1D;
}

this.velocity = new Vec3(vec3.x * 0.9D, vec3.y - d * (double)this.random.nextFloat() * 0.2D, vec3.z * 0.9D);
this.velocity = new Vec3(vec3.x * 0.9D, vec3.y - d * (double) this.random.nextFloat() * 0.2D, vec3.z * 0.9D);
if (this.hookCountdown <= 0 && this.fishTravelCountdown <= 0) {
this.inOpenWater = true;
} else {
Expand Down Expand Up @@ -1059,7 +1059,7 @@ private void onSwimmingStart() {
g = 1.0F;
}

if ((double)g < 0.25D) {
if ((double) g < 0.25D) {
random.nextFloat();
random.nextFloat();
//this.playSound(this.getSplashSound(), g, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
Expand All @@ -1069,21 +1069,21 @@ private void onSwimmingStart() {
//this.playSound(this.getHighSpeedSplashSound(), g, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
}

float h = (float)Mth.floor(this.pos.y);
float h = (float) Mth.floor(this.pos.y);

int j;
double k;
double l;
for(j = 0; (float)j < 1.0F + FISHING_BOBBER_DIMENSIONS.width() * 20.0F; ++j) {
k = (this.random.nextDouble() * 2.0D - 1.0D) * (double)FISHING_BOBBER_DIMENSIONS.width();
l = (this.random.nextDouble() * 2.0D - 1.0D) * (double)FISHING_BOBBER_DIMENSIONS.width();
for (j = 0; (float) j < 1.0F + FISHING_BOBBER_DIMENSIONS.width() * 20.0F; ++j) {
k = (this.random.nextDouble() * 2.0D - 1.0D) * (double) FISHING_BOBBER_DIMENSIONS.width();
l = (this.random.nextDouble() * 2.0D - 1.0D) * (double) FISHING_BOBBER_DIMENSIONS.width();
random.nextDouble();
//this.world.addParticle(ParticleTypes.BUBBLE, this.pos.x + k, (double)(h + 1.0F), this.pos.z + l, vec3d.x, vec3d.y - this.random.nextDouble() * 0.20000000298023224D, vec3d.z);
}

for(j = 0; (float)j < 1.0F + FISHING_BOBBER_DIMENSIONS.width() * 20.0F; ++j) {
k = (this.random.nextDouble() * 2.0D - 1.0D) * (double)FISHING_BOBBER_DIMENSIONS.width();
l = (this.random.nextDouble() * 2.0D - 1.0D) * (double)FISHING_BOBBER_DIMENSIONS.width();
for (j = 0; (float) j < 1.0F + FISHING_BOBBER_DIMENSIONS.width() * 20.0F; ++j) {
k = (this.random.nextDouble() * 2.0D - 1.0D) * (double) FISHING_BOBBER_DIMENSIONS.width();
l = (this.random.nextDouble() * 2.0D - 1.0D) * (double) FISHING_BOBBER_DIMENSIONS.width();
//this.world.addParticle(ParticleTypes.SPLASH, this.getX() + k, (double)(h + 1.0F), this.getZ() + l, vec3d.x, vec3d.y, vec3d.z);
}
}
Expand Down Expand Up @@ -1111,7 +1111,7 @@ private boolean updateMovementInFluid(TagKey<Fluid> tag, double d) {
mutable.set(p, q, r);
FluidState fluidState = this.level.getFluidState(mutable);
if (fluidState.is(tag)) {
double f = (float)q + fluidState.getHeight(this.level, mutable);
double f = (float) q + fluidState.getHeight(this.level, mutable);
if (f >= aabb.minY) {
bl2 = true;
e = Math.max(f - aabb.minY, e);
Expand All @@ -1123,7 +1123,7 @@ private boolean updateMovementInFluid(TagKey<Fluid> tag, double d) {

if (vec3.length() > 0.0D) {
if (o > 0) {
vec3 = vec3.scale(1.0D / (double)o);
vec3 = vec3.scale(1.0D / (double) o);
}

vec3 = vec3.normalize();
Expand Down Expand Up @@ -1185,7 +1185,7 @@ private void move(Vec3 movement) {
//this.checkBlockCollision(); // no interesting blocks

float i = this.getVelocityMultiplier();
this.velocity = this.velocity.multiply((double)i, 1.0D, (double)i);
this.velocity = this.velocity.multiply(i, 1.0D, i);
if (this.level.getBlockStatesIfLoaded(this.boundingBox.deflate(0.001D)).anyMatch((blockStatex) -> blockStatex.is(BlockTags.FIRE) || blockStatex.is(Blocks.LAVA))) {
failedReason = "fire";
}
Expand All @@ -1212,7 +1212,7 @@ private float getVelocityMultiplier() {
Block block = this.level.getBlockState(BlockPos.containing(pos)).getBlock();
float f = block.getSpeedFactor();
if (block != Blocks.WATER && block != Blocks.BUBBLE_COLUMN) {
return (double)f == 1.0D ? this.level
return (double) f == 1.0D ? this.level
.getBlockState(BlockPos.containing(this.pos.x, this.boundingBox.minY - 0.5000001D, this.pos.z)).getBlock().getSpeedFactor() : f;
} else {
return f;
Expand Down Expand Up @@ -1318,9 +1318,9 @@ private void tickFishingLogic(BlockPos pos) {
n = this.fishAngle * 0.017453292F;
o = Mth.sin(n);
p = Mth.cos(n);
q = this.pos.x + (double)(o * (float)this.fishTravelCountdown * 0.1F);
r = (double)((float)Mth.floor(this.pos.y) + 1.0F);
s = this.pos.z + (double)(p * (float)this.fishTravelCountdown * 0.1F);
q = this.pos.x + (double) (o * (float) this.fishTravelCountdown * 0.1F);
r = (float) Mth.floor(this.pos.y) + 1.0F;
s = this.pos.z + (double) (p * (float) this.fishTravelCountdown * 0.1F);
blockState2 = level.getBlockState(BlockPos.containing(q, r - 1.0D, s));
if (blockState2.is(Blocks.WATER)) {
if (this.random.nextFloat() < 0.15F) {
Expand All @@ -1347,19 +1347,19 @@ private void tickFishingLogic(BlockPos pos) {
this.waitCountdown -= i;
n = 0.15F;
if (this.waitCountdown < 20) {
n = (float)((double)n + (double)(20 - this.waitCountdown) * 0.05D);
n = (float) ((double) n + (double) (20 - this.waitCountdown) * 0.05D);
} else if (this.waitCountdown < 40) {
n = (float)((double)n + (double)(40 - this.waitCountdown) * 0.02D);
n = (float) ((double) n + (double) (40 - this.waitCountdown) * 0.02D);
} else if (this.waitCountdown < 60) {
n = (float)((double)n + (double)(60 - this.waitCountdown) * 0.01D);
n = (float) ((double) n + (double) (60 - this.waitCountdown) * 0.01D);
}

if (this.random.nextFloat() < n) {
o = Mth.nextFloat(this.random, 0.0F, 360.0F) * 0.017453292F;
p = Mth.nextFloat(this.random, 25.0F, 60.0F);
q = this.pos.x + (double)(Mth.sin(o) * p * 0.1F);
r = (float)Mth.floor(this.pos.y) + 1.0F;
s = this.pos.z + (double)(Mth.cos(o) * p * 0.1F);
q = this.pos.x + (double) (Mth.sin(o) * p * 0.1F);
r = (float) Mth.floor(this.pos.y) + 1.0F;
s = this.pos.z + (double) (Mth.cos(o) * p * 0.1F);
blockState2 = level.getBlockState(BlockPos.containing(q, r - 1.0D, s));
if (blockState2.is(Blocks.WATER)) {
random.nextInt(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public void writeFixedBitSet(BitSet bitSet, int size) {

@Override
public @NotNull PacketDumpByteBuf writeChar(int value) {
return dumpSimple("char", Character.toString((char)value), JsonWriter::value);
return dumpSimple("char", Character.toString((char) value), JsonWriter::value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static int nextInt() {

public static int nextInt(int bound) {
if ((bound & -bound) == bound) {
return (int) ((bound * (long)next(31)) >> 31);
return (int) ((bound * (long) next(31)) >> 31);
}

int bits, val;
Expand Down Expand Up @@ -311,8 +311,8 @@ public static void onItemDamage(int amount, LivingEntity holder, ItemStack stack

if (Configs.toolBreakWarning && stack.getDamageValue() + amount >= stack.getMaxDamage() - 30) {

if(stack.getDamageValue() + amount >= stack.getMaxDamage() - 15) {
Minecraft.getInstance().player.playSound(SoundEvents.EXPERIENCE_ORB_PICKUP, 10,0.1f);
if (stack.getDamageValue() + amount >= stack.getMaxDamage() - 15) {
Minecraft.getInstance().player.playSound(SoundEvents.EXPERIENCE_ORB_PICKUP, 10, 0.1f);
}

MutableComponent durability = Component.literal(String.valueOf(stack.getMaxDamage() - stack.getDamageValue() - 1)).withStyle(ChatFormatting.RED);
Expand All @@ -326,10 +326,12 @@ public static void onItemDamage(int amount, LivingEntity holder, ItemStack stack
int unbreakingLevel_f = unbreakingLevel;
Runnable action = () -> throwItemsUntil(rand -> {
for (int i = 0; i < amount; i++) {
if (stack.getItem() instanceof ArmorItem && rand.nextFloat() < 0.6)
if (stack.getItem() instanceof ArmorItem && rand.nextFloat() < 0.6) {
return false;
if (rand.nextInt(unbreakingLevel_f + 1) == 0)
}
if (rand.nextInt(unbreakingLevel_f + 1) == 0) {
return false;
}
}
return true;
}, 64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,13 @@ public static String getWikiSummary(String pageName) {
return null;
}

if (result.query.pages.isEmpty())
if (result.query.pages.isEmpty()) {
return null;
}
var page = result.query.pages.values().iterator().next();
if (page.missing != null || page.extract == null)
if (page.missing != null || page.extract == null) {
return null;
}
String html = page.extract;
return decode(html);
}
Expand Down
Loading
Loading