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

Code Health Work #490

Merged
merged 14 commits into from
Sep 22, 2023
14 changes: 14 additions & 0 deletions .github/workflows/checkstyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Code Style Scan
on: [pull_request]
jobs:
checkstyle:
name: runner / checkstyle
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dbelyaev/action-checkstyle@v0.9.5
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
level: warning
checkstyle_config: config/checkstyle/checkstyle.xml
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ plugins {
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
id "me.hypherionmc.modutils.modpublisher" version "1.+"
id 'checkstyle'
}

apply plugin: 'org.spongepowered.mixin'
Expand Down
33 changes: 33 additions & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="JavadocPackage"/>
<module name="TreeWalker">
<module name="AvoidStarImport"/>
<module name="ConstantName"/>

<!-- Modifier Checks -->
<!-- See https://checkstyle.org/checks/modifier/index.html -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>

<!-- Checks for blocks. You know, those {}'s -->
<!-- See https://checkstyle.org/checks/blocks/index.html -->
<module name="AvoidNestedBlocks"/>
<module name="EmptyBlock"/>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>

<!-- Checks for common coding problems -->
<!-- See https://checkstyle.org/checks/coding/index.html -->
<module name="EmptyStatement"/>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MissingSwitchDefault"/>
<module name="MultipleVariableDeclarations"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
</module>
</module>
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.enderio.api.capability;

import org.jetbrains.annotations.Nullable;

import java.util.function.Consumer;

public interface ICoordinateSelectionHolder {

@Nullable
CoordinateSelection getSelection();

void setSelection(CoordinateSelection selection);
Expand All @@ -13,7 +16,8 @@ default boolean hasSelection() {
}

default void ifSelectionPresent(Consumer<CoordinateSelection> cons) {
if (hasSelection())
if (hasSelection()) {
cons.accept(getSelection());
}
}
}
4 changes: 3 additions & 1 deletion src/api/java/com/enderio/api/conduit/ConduitItemFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public static void setFactory(BiFunction<Supplier<? extends IConduitType<?>>, It
* @return
*/
public static Item build(Supplier<? extends IConduitType<?>> type, Item.Properties properties) {
if (factory != null)
if (factory != null) {
return factory.apply(type, properties);
}

return new Item(properties);
}
}
7 changes: 5 additions & 2 deletions src/api/java/com/enderio/api/conduit/TieredConduit.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public ResourceLocation getItemTexture() {

@Override
public boolean canBeReplacedBy(IConduitType<?> other) {
if (!(other instanceof TieredConduit<?> tieredOther))
if (!(other instanceof TieredConduit<?> tieredOther)) {
return false;
}

if (type.equals(tieredOther.getType())) {
return tier < tieredOther.getTier();
Expand All @@ -49,8 +50,10 @@ public boolean canBeReplacedBy(IConduitType<?> other) {

@Override
public boolean canBeInSameBlock(IConduitType<?> other) {
if (!(other instanceof TieredConduit<?> tieredOther))
if (!(other instanceof TieredConduit<?> tieredOther)) {
return true;
}

// if they have the same type they can't be in the same block, their tier doesn't matter as canBeReplacedBy is checked first
return !type.equals(tieredOther.getType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,36 @@ default void tickGraph(IConduitType<?> type, List<NodeIdentifier<?>> loadedNodes
for (ColorControl color: ColorControl.values()) {
List<Connection> extractList = extracts.get(color);
List<Connection> insertList = inserts.get(color);
if (extractList.isEmpty() || insertList.isEmpty())
if (extractList.isEmpty() || insertList.isEmpty()) {
continue;
}

tickColoredGraph(type, insertList, extractList, color, level, graph, isRedstoneActive);
}
}

void tickColoredGraph(IConduitType<?> type, List<Connection> inserts, List<Connection> extracts, ColorControl color, ServerLevel level, Graph<Mergeable.Dummy> graph, TriFunction<ServerLevel, BlockPos, ColorControl, Boolean> isRedstoneActive);
default boolean isRedstoneMode(IConduitType<?> type, ServerLevel level, BlockPos pos, NodeIdentifier.IOState state, TriFunction<ServerLevel, BlockPos, ColorControl, Boolean> isRedstoneActive) {
if (!type.getMenuData().showRedstoneExtract())
if (!type.getMenuData().showRedstoneExtract()) {
return true;
if (state.control() == RedstoneControl.ALWAYS_ACTIVE)
}

if (state.control() == RedstoneControl.ALWAYS_ACTIVE) {
return true;
if (state.control() == RedstoneControl.NEVER_ACTIVE)
}

if (state.control() == RedstoneControl.NEVER_ACTIVE) {
return false;
}

boolean hasRedstone = false;
for (Direction direction: Direction.values()) {
if (level.getSignal(pos.relative(direction), direction) > 0) {
hasRedstone = true;
break;
}
}

return state.control().isActive(hasRedstone || isRedstoneActive.apply(level, pos, state.redstoneChannel()));
}
record Connection(BlockPos pos, Direction dir, IExtendedConduitData<?> data) {
Expand Down
5 changes: 5 additions & 0 deletions src/api/java/com/enderio/api/conduit/ticker/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@javax.annotation.ParametersAreNonnullByDefault
@net.minecraft.MethodsReturnNonnullByDefault
@com.tterrag.registrate.util.nullness.FieldsAreNonnullByDefault

package com.enderio.api.conduit.ticker;
12 changes: 9 additions & 3 deletions src/api/java/com/enderio/api/integration/IntegrationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

public class IntegrationManager {

Expand Down Expand Up @@ -43,16 +47,18 @@ public static <T> Optional<T> getFirst(Function<Integration, Optional<T>> mapper

public static void executeIf(Predicate<Integration> condition, Consumer<Integration> consumer) {
for (Integration integration : ALL_INTEGRATIONS) {
if (condition.test(integration))
if (condition.test(integration)) {
consumer.accept(integration);
}
}
}

public static <T> List<T> getIf(Predicate<Integration> condition, Function<Integration, T> mapper) {
List<T> list = new ArrayList<>();
for (Integration integration : ALL_INTEGRATIONS) {
if (condition.test(integration))
if (condition.test(integration)) {
list.add(mapper.apply(integration));
}
}
return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public boolean isEmpty() {
* @throws NullPointerException if {@code consumer} is null and this {@link LazyOptional} is non-empty
*/
public void ifPresent(Consumer<? super T> consumer) {
if (isPresent())
if (isPresent()) {
consumer.accept(value);
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/api/java/com/enderio/api/io/IOMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public enum IOMode {
*/
DISABLED(false, false, false, false);

private final boolean input, output, force, canConnect;
private final boolean input;
private final boolean output;
private final boolean force;
private final boolean canConnect;

IOMode(boolean input, boolean output, boolean force, boolean canConnect) {
this.input = input;
Expand Down
4 changes: 3 additions & 1 deletion src/api/java/com/enderio/api/io/energy/EnergyIOMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public enum EnergyIOMode {
*/
Both(true, true, true);

private final boolean input, output, respectIOConfig;
private final boolean input;
private final boolean output;
private final boolean respectIOConfig;

EnergyIOMode(boolean input, boolean output, boolean respectIOConfig) {
this.input = input;
Expand Down
9 changes: 7 additions & 2 deletions src/api/java/com/enderio/api/misc/Vector2i.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ public String toString() {

@Override
public boolean equals(Object o) {
if (this == o)
if (this == o) {
return true;
if (o == null)
}

if (o == null) {
return false;
}

if (o instanceof Vector2i other) {
return x == other.x && y == other.y;
}

return false;
}

Expand Down
5 changes: 5 additions & 0 deletions src/api/java/com/enderio/api/misc/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@javax.annotation.ParametersAreNonnullByDefault
@net.minecraft.MethodsReturnNonnullByDefault
@com.tterrag.registrate.util.nullness.FieldsAreNonnullByDefault

package com.enderio.api.misc;
5 changes: 5 additions & 0 deletions src/api/java/com/enderio/api/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@javax.annotation.ParametersAreNonnullByDefault
@net.minecraft.MethodsReturnNonnullByDefault
@com.tterrag.registrate.util.nullness.FieldsAreNonnullByDefault

package com.enderio.api;
13 changes: 7 additions & 6 deletions src/api/java/com/enderio/api/travel/TravelRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,31 @@
import java.util.function.Function;
import java.util.function.Supplier;

// TODO: Maybe this should be a forge registry?
@ApiStatus.Internal
public class TravelRegistry {

private static final Map<ResourceLocation, TravelEntry<?>> registry = new HashMap<>();
private static final Map<ResourceLocation, TravelEntry<?>> REGISTRY = new HashMap<>();

public static <T extends ITravelTarget> void addTravelEntry(ResourceLocation serializationName, Function<CompoundTag, T> constructor,
Supplier<Lazy<TravelRenderer<T>>> renderer) {
registry.put(serializationName, new TravelEntry<>(serializationName, constructor, renderer));
REGISTRY.put(serializationName, new TravelEntry<>(serializationName, constructor, renderer));
}

public static <T extends ITravelTarget> void addTravelEntry(TravelEntry<?> travelEntry) {
registry.put(travelEntry.serializationName(), travelEntry);
REGISTRY.put(travelEntry.serializationName(), travelEntry);
}

public static <T extends ITravelTarget> TravelRenderer<T> getRenderer(T entry) {
return (TravelRenderer<T>) registry.get(entry.getSerializationName()).renderer().get().get();
return (TravelRenderer<T>) REGISTRY.get(entry.getSerializationName()).renderer().get().get();
}

public static Optional<ITravelTarget> deserialize(CompoundTag nbt) {
return Optional.ofNullable(registry.get(new ResourceLocation(nbt.getString("name")))).map(entry -> entry.constructor().apply(nbt.getCompound("data")));
return Optional.ofNullable(REGISTRY.get(new ResourceLocation(nbt.getString("name")))).map(entry -> entry.constructor().apply(nbt.getCompound("data")));
}

public static boolean isRegistered(ITravelTarget target) {
return registry.containsKey(target.getSerializationName());
return REGISTRY.containsKey(target.getSerializationName());
}

public static CompoundTag serialize(ITravelTarget travelData) {
Expand Down
5 changes: 5 additions & 0 deletions src/armory/java/com/enderio/armory/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@javax.annotation.ParametersAreNonnullByDefault
@net.minecraft.MethodsReturnNonnullByDefault
@com.tterrag.registrate.util.nullness.FieldsAreNonnullByDefault

package com.enderio.armory;
7 changes: 6 additions & 1 deletion src/conduits/java/com/enderio/conduits/EIOConduits.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
import com.enderio.api.conduit.ConduitItemFactory;
import com.enderio.api.conduit.ConduitTypes;
import com.enderio.base.data.EIODataProvider;
import com.enderio.conduits.common.init.*;
import com.enderio.conduits.common.init.ConduitBlockEntities;
import com.enderio.conduits.common.init.ConduitBlocks;
import com.enderio.conduits.common.init.ConduitItems;
import com.enderio.conduits.common.init.ConduitLang;
import com.enderio.conduits.common.init.ConduitMenus;
import com.enderio.conduits.common.init.EnderConduitTypes;
import com.enderio.conduits.common.integrations.Integrations;
import com.enderio.conduits.common.items.ConduitBlockItem;
import com.enderio.conduits.common.network.ConduitNetwork;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
@Mod.EventBusSubscriber(value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ConduitClientSetup {

private static final List<ResourceLocation> modelLocations = new ArrayList<>();
private static final Map<ResourceLocation, BakedModel> models = new HashMap<>();
private static final List<ResourceLocation> MODEL_LOCATIONS = new ArrayList<>();
private static final Map<ResourceLocation, BakedModel> MODELS = new HashMap<>();

public static final ResourceLocation CONDUIT_CONNECTOR = loc("block/conduit_connector");
public static final ResourceLocation CONDUIT_FACADE = loc("block/conduit_facade");
Expand All @@ -51,16 +51,16 @@ public static void modelLoader(ModelEvent.RegisterGeometryLoaders event) {

@SubscribeEvent
public static void registerModels(ModelEvent.RegisterAdditional event) {
for (ResourceLocation model : modelLocations) {
for (ResourceLocation model : MODEL_LOCATIONS) {
event.register(model);
}
ConduitTypes.getRegistry().getValues().stream().flatMap(type -> type.getClientData().modelsToLoad().stream()).forEach(event::register);
}

@SubscribeEvent
public static void bakingModelsFinished(ModelEvent.BakingCompleted event) {
for (ResourceLocation modelLocation : modelLocations) {
models.put(modelLocation, event.getModels().get(modelLocation));
for (ResourceLocation modelLocation : MODEL_LOCATIONS) {
MODELS.put(modelLocation, event.getModels().get(modelLocation));
}
}

Expand All @@ -79,12 +79,12 @@ public int getColor(BlockState state, @Nullable BlockAndTintGetter level, @Nulla

private static ResourceLocation loc(String modelName) {
ResourceLocation loc = EnderIO.loc(modelName);
modelLocations.add(loc);
MODEL_LOCATIONS.add(loc);
return loc;
}

public static BakedModel modelOf(ResourceLocation location) {
return models.get(location);
return MODELS.get(location);
}

public static Level getClientLevel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ private void updateConnectionWidgets(boolean forceUpdate) {
typeSelectionButtons.clear();
for (int i = 0; i < validConnections.size(); i++) {
IConduitType<?> connection = validConnections.get(i);
ConduitSelectionButton button = new ConduitSelectionButton(getGuiLeft() + 206, getGuiTop() + 4 + 24*i, connection, menu::getConduitType, type -> {menu.setConduitType(type); recalculateTypedButtons = true;});
ConduitSelectionButton button = new ConduitSelectionButton(getGuiLeft() + 206, getGuiTop() + 4 + 24*i, connection, menu::getConduitType, type -> {
menu.setConduitType(type);
recalculateTypedButtons = true;
});

typeSelectionButtons.add(button);
addRenderableWidget(button);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@javax.annotation.ParametersAreNonnullByDefault
@net.minecraft.MethodsReturnNonnullByDefault
@com.tterrag.registrate.util.nullness.FieldsAreNonnullByDefault

package com.enderio.conduits.client.gui;