From 62f7efc4e9c79bd8f19e58285a4069c1511ebed9 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 27 May 2024 19:08:19 +0300 Subject: [PATCH] add spotless formatting to 1.20.1 (#1334) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add spotless to 1.20.1 * clean up the GH actions * run spotless 🥰 * remove some unused classes * add spotless check action * reviews --- .editorconfig | 5 -- .github/actions/build_setup/action.yml | 2 +- .github/workflows/auto-build.yml | 11 ++-- .github/workflows/auto-publish.yml | 10 ++- .github/workflows/build-on-push.yml | 4 +- .github/workflows/format-java.yml | 29 +++++++++ gradle/scripts/spotless.gradle | 8 +-- gradle/wrapper/gradle-wrapper.properties | 1 - .../advancement/IAdvancementCriterion.java | 12 ---- .../api/advancement/IAdvancementManager.java | 6 -- .../api/advancement/IAdvancementTrigger.java | 9 --- .../material/properties/HazardProperty.java | 62 ++++++++++--------- .../gtceu/common/item/armor/HazmatSuit.java | 10 ++- .../material/UnknownCompositionMaterials.java | 3 +- 14 files changed, 93 insertions(+), 79 deletions(-) delete mode 100644 .editorconfig create mode 100644 .github/workflows/format-java.yml delete mode 100644 src/main/java/com/gregtechceu/gtceu/api/advancement/IAdvancementCriterion.java delete mode 100644 src/main/java/com/gregtechceu/gtceu/api/advancement/IAdvancementManager.java delete mode 100644 src/main/java/com/gregtechceu/gtceu/api/advancement/IAdvancementTrigger.java diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 6a01661edb..0000000000 --- a/.editorconfig +++ /dev/null @@ -1,5 +0,0 @@ -root = true - -[*.java] -indent_style = space -indent_size = 4 diff --git a/.github/actions/build_setup/action.yml b/.github/actions/build_setup/action.yml index 528db11767..5084a82967 100644 --- a/.github/actions/build_setup/action.yml +++ b/.github/actions/build_setup/action.yml @@ -5,7 +5,7 @@ inputs: update-cache: description: If cache should be updated required: false - default: false + default: true runs: using: 'composite' diff --git a/.github/workflows/auto-build.yml b/.github/workflows/auto-build.yml index dc9b8af32f..a63e5f533d 100644 --- a/.github/workflows/auto-build.yml +++ b/.github/workflows/auto-build.yml @@ -22,14 +22,15 @@ jobs: uses: ./.github/actions/build_setup - name: Build - run: ./gradlew build + uses: gradle/gradle-build-action@v2 + with: + arguments: build - name: Get Version id: var run: | MESSAGE=$(ls build/libs/* | grep sources.jar -v | grep slim.jar -v | awk -F 'gtceu-|.jar' '{print $2}') echo "version=$MESSAGE" >> $GITHUB_OUTPUT - echo "version: $MESSAGE" - name: Release id: release @@ -43,6 +44,6 @@ jobs: - name: Print Output run: | - echo "Release tag: ${{ steps.publish.outputs.github-tag }}" - echo "Release URL: ${{ steps.publish.outputs.github-url }}" - echo "Released files: ${{ steps.publish.outputs.github-files }}" + echo "Release tag: ${{ steps.release.outputs.github-tag }}" + echo "Release URL: ${{ steps.release.outputs.github-url }}" + echo "Released files: ${{ steps.release.outputs.github-files }}" diff --git a/.github/workflows/auto-publish.yml b/.github/workflows/auto-publish.yml index f5bef9d02c..209994f783 100644 --- a/.github/workflows/auto-publish.yml +++ b/.github/workflows/auto-publish.yml @@ -18,7 +18,7 @@ on: type: boolean default: true publishCurseForgeAndModrinth: - description: 'whether publish to curseforge and modrinth' + description: 'whether to publish to curseforge and modrinth' required: true type: boolean default: true @@ -43,11 +43,15 @@ jobs: uses: ./.github/actions/build_setup - name: Build - run: ./gradlew build + uses: gradle/gradle-build-action@v2 + with: + arguments: build - if: ${{ inputs.publishMaven }} name: Publish to Maven - run: ./gradlew publish + uses: gradle/gradle-build-action@v2 + with: + arguments: publish - if: ${{ inputs.publishCurseForgeAndModrinth }} name: Get Version diff --git a/.github/workflows/build-on-push.yml b/.github/workflows/build-on-push.yml index 10df135b26..3941f2f555 100644 --- a/.github/workflows/build-on-push.yml +++ b/.github/workflows/build-on-push.yml @@ -19,7 +19,9 @@ jobs: uses: ./.github/actions/build_setup - name: Build - run: ./gradlew build + uses: gradle/gradle-build-action@v2 + with: + arguments: build - name: Upload Artifact uses: actions/upload-artifact@v4.0.0 diff --git a/.github/workflows/format-java.yml b/.github/workflows/format-java.yml new file mode 100644 index 0000000000..e8d233df43 --- /dev/null +++ b/.github/workflows/format-java.yml @@ -0,0 +1,29 @@ +# Runs formatting requirements +name: Java Formatting + +on: + push: + branches: + - master + paths: ['src/main/java/**', 'src/test/**'] + pull_request: + paths: ['src/main/java/**', 'src/test/**'] + +concurrency: + group: formatting-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + formatting: + name: Formatting + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup Build + uses: ./.github/actions/build_setup + + - name: Run Spotless Formatting Check with Gradle + run: ./gradlew spotlessCheck --warning-mode all --build-cache diff --git a/gradle/scripts/spotless.gradle b/gradle/scripts/spotless.gradle index 2e183c7750..46cd4be631 100644 --- a/gradle/scripts/spotless.gradle +++ b/gradle/scripts/spotless.gradle @@ -12,10 +12,10 @@ spotless { endWithNewline() } java { - target 'src/main/java/**/*.java', 'src/test/java/**/*.java' // exclude api as they are not our files + target 'src/main/java/**/*.java', 'src/test/java/**/*.java' - def orderFile = project.file('spotless/spotless.importorder') - def formatFile = project.file('spotless/spotless.eclipseformat.xml') + def orderFile = file("$rootDir/spotless/spotless.importorder") + def formatFile = file("$rootDir/spotless/spotless.eclipseformat.xml") toggleOffOn() importOrderFile(orderFile) @@ -23,4 +23,4 @@ spotless { endWithNewline() eclipse('4.31').configFile(formatFile) } -} \ No newline at end of file +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 20db9ad5c9..48c0a02ca4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip -networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/gregtechceu/gtceu/api/advancement/IAdvancementCriterion.java b/src/main/java/com/gregtechceu/gtceu/api/advancement/IAdvancementCriterion.java deleted file mode 100644 index 93624cc159..0000000000 --- a/src/main/java/com/gregtechceu/gtceu/api/advancement/IAdvancementCriterion.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.gregtechceu.gtceu.api.advancement; - -import net.minecraft.advancements.CriterionTriggerInstance; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; - -public interface IAdvancementCriterion extends CriterionTriggerInstance { - - boolean test(ServerPlayer player); - - void setId(ResourceLocation id); -} diff --git a/src/main/java/com/gregtechceu/gtceu/api/advancement/IAdvancementManager.java b/src/main/java/com/gregtechceu/gtceu/api/advancement/IAdvancementManager.java deleted file mode 100644 index bbf071b807..0000000000 --- a/src/main/java/com/gregtechceu/gtceu/api/advancement/IAdvancementManager.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.gregtechceu.gtceu.api.advancement; - -public interface IAdvancementManager { - - IAdvancementTrigger registerTrigger(String id, T criterion); -} diff --git a/src/main/java/com/gregtechceu/gtceu/api/advancement/IAdvancementTrigger.java b/src/main/java/com/gregtechceu/gtceu/api/advancement/IAdvancementTrigger.java deleted file mode 100644 index 00db7bff98..0000000000 --- a/src/main/java/com/gregtechceu/gtceu/api/advancement/IAdvancementTrigger.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.gregtechceu.gtceu.api.advancement; - -import net.minecraft.advancements.CriterionTrigger; -import net.minecraft.server.level.ServerPlayer; - -public interface IAdvancementTrigger extends CriterionTrigger { - - void trigger(ServerPlayer player); -} diff --git a/src/main/java/com/gregtechceu/gtceu/api/material/material/properties/HazardProperty.java b/src/main/java/com/gregtechceu/gtceu/api/material/material/properties/HazardProperty.java index 7040bc9612..7d28032f71 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/material/material/properties/HazardProperty.java +++ b/src/main/java/com/gregtechceu/gtceu/api/material/material/properties/HazardProperty.java @@ -1,15 +1,16 @@ package com.gregtechceu.gtceu.api.data.chemical.material.properties; import com.gregtechceu.gtceu.api.data.tag.TagPrefix; - import com.gregtechceu.gtceu.api.item.armor.ArmorComponentItem; import com.gregtechceu.gtceu.data.recipe.CustomTags; -import lombok.Getter; + import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ItemStack; + +import lombok.Getter; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -22,7 +23,7 @@ * @date 2024/2/12 * @implNote HazardProperty */ -public class HazardProperty implements IMaterialProperty{ +public class HazardProperty implements IMaterialProperty { @Getter @Nullable @@ -38,9 +39,8 @@ public class HazardProperty implements IMaterialProperty{ @Getter private final boolean applyToDerivatives; - - - public HazardProperty(HazardType hazardType, @Nullable HazardProperty.HazardEffect effect, @Nullable HazardProperty.HazardDamage damage, boolean applyToDerivatives) { + public HazardProperty(HazardType hazardType, @Nullable HazardProperty.HazardEffect effect, + @Nullable HazardProperty.HazardDamage damage, boolean applyToDerivatives) { this.damage = damage; this.hazardType = hazardType; this.applyToDerivatives = applyToDerivatives; @@ -50,52 +50,59 @@ public HazardProperty(HazardType hazardType, @Nullable HazardProperty.HazardEffe /** * Default property constructor. */ - public HazardProperty(){ - this(HazardType.CONTACT_POISON,null,null,false); + public HazardProperty() { + this(HazardType.CONTACT_POISON, null, null, false); } @Override - public void verifyProperty(MaterialProperties properties) { - } + public void verifyProperty(MaterialProperties properties) {} public enum HazardType { - INHALATION_POISON(ProtectionType.MASK, TagPrefix.dust,TagPrefix.dustImpure,TagPrefix.dustSmall,TagPrefix.dustPure,TagPrefix.dustTiny,TagPrefix.rawOre,TagPrefix.rawOreBlock,TagPrefix.crushed,TagPrefix.crushedRefined,TagPrefix.crushedPurified), + + INHALATION_POISON(ProtectionType.MASK, TagPrefix.dust, TagPrefix.dustImpure, TagPrefix.dustSmall, + TagPrefix.dustPure, TagPrefix.dustTiny, TagPrefix.rawOre, TagPrefix.rawOreBlock, TagPrefix.crushed, + TagPrefix.crushedRefined, TagPrefix.crushedPurified), CONTACT_POISON(ProtectionType.FULL), RADIOACTIVE(ProtectionType.FULL), - CORROSIVE(ProtectionType.HANDS,TagPrefix.dust,TagPrefix.dustSmall,TagPrefix.dustTiny), + CORROSIVE(ProtectionType.HANDS, TagPrefix.dust, TagPrefix.dustSmall, TagPrefix.dustTiny), NONE(ProtectionType.FULL); private final List affectedTagPrefixes = new ArrayList<>(); @Getter private final ProtectionType protectionType; - HazardType(ProtectionType protectionType, TagPrefix... tagPrefixes){ + + HazardType(ProtectionType protectionType, TagPrefix... tagPrefixes) { this.protectionType = protectionType; affectedTagPrefixes.addAll(Arrays.asList(tagPrefixes)); } - - public boolean isAffected(TagPrefix prefix){ - if(affectedTagPrefixes.isEmpty()) return true; //empty list means all prefixes are affected + public boolean isAffected(TagPrefix prefix) { + if (affectedTagPrefixes.isEmpty()) return true; // empty list means all prefixes are affected return affectedTagPrefixes.contains(prefix); } } - public enum ProtectionType{ + public enum ProtectionType { + MASK(ArmorItem.Type.HELMET), HANDS(ArmorItem.Type.CHESTPLATE), FULL(ArmorItem.Type.BOOTS, ArmorItem.Type.HELMET, ArmorItem.Type.CHESTPLATE, ArmorItem.Type.LEGGINGS); + private final List equipmentTypes; - ProtectionType(ArmorItem.Type... equipmentTypes){ + + ProtectionType(ArmorItem.Type... equipmentTypes) { this.equipmentTypes = List.of(equipmentTypes); } - public boolean isProtected(LivingEntity livingEntity){ + public boolean isProtected(LivingEntity livingEntity) { List correctArmorItems = new ArrayList<>(); - for (ArmorItem.Type equipmentType: equipmentTypes) { + for (ArmorItem.Type equipmentType : equipmentTypes) { ItemStack armor = livingEntity.getItemBySlot(equipmentType.getSlot()); - if(!armor.isEmpty() && ((armor.getItem() instanceof ArmorComponentItem armorItem && armorItem.getArmorLogic().isPPE()) || armor.getTags().anyMatch(tag -> tag.equals(CustomTags.PPE_ARMOR)))){ + if (!armor.isEmpty() && ((armor.getItem() instanceof ArmorComponentItem armorItem && + armorItem.getArmorLogic().isPPE()) || + armor.getTags().anyMatch(tag -> tag.equals(CustomTags.PPE_ARMOR)))) { correctArmorItems.add(equipmentType); } } @@ -106,14 +113,13 @@ public boolean isProtected(LivingEntity livingEntity){ /** * @param delay damage is applied every X seconds */ - public record HazardDamage(int damage, int delay){} - public record HazardEffect(int duration, MobEffect... effects){ - public void apply(LivingEntity entity) { - for(MobEffect effect: effects) - entity.addEffect(new MobEffectInstance(effect,duration)); + public record HazardDamage(int damage, int delay) {} - } + public record HazardEffect(int duration, MobEffect... effects) { + public void apply(LivingEntity entity) { + for (MobEffect effect : effects) + entity.addEffect(new MobEffectInstance(effect, duration)); + } } - } diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/armor/HazmatSuit.java b/src/main/java/com/gregtechceu/gtceu/common/item/armor/HazmatSuit.java index e170f47c6e..90c6b39c8c 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/armor/HazmatSuit.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/armor/HazmatSuit.java @@ -2,12 +2,15 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.item.armor.IArmorLogic; + import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ArmorItem; +import net.minecraft.world.item.ArmorMaterial; import net.minecraft.world.item.ItemStack; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,11 +33,12 @@ public int getArmorDisplay(Player player, @NotNull ItemStack armor, EquipmentSlo } @Override - public @Nullable ResourceLocation getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type) { + public @Nullable ResourceLocation getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, + ArmorMaterial.Layer layer) { String armorTexture = "hazmat"; return slot != EquipmentSlot.LEGS ? - GTCEu.id(String.format("textures/armor/%s_1.png", armorTexture)) : - GTCEu.id(String.format("textures/armor/%s_2.png", armorTexture)); + GTCEu.id(String.format("textures/armor/%s_1.png", armorTexture)) : + GTCEu.id(String.format("textures/armor/%s_2.png", armorTexture)); } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/data/material/UnknownCompositionMaterials.java b/src/main/java/com/gregtechceu/gtceu/data/material/UnknownCompositionMaterials.java index 39e4f0962a..1cc01d04a8 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/material/UnknownCompositionMaterials.java +++ b/src/main/java/com/gregtechceu/gtceu/data/material/UnknownCompositionMaterials.java @@ -557,6 +557,7 @@ public static void register() { PCBCoolant = new Material.Builder(GTCEu.id("pcb_coolant")) .fluid().color(0xD5D69C) - .hazard(HazardProperty.HazardType.INHALATION_POISON).buildAndRegister(); + .hazard(HazardProperty.HazardType.INHALATION_POISON) + .buildAndRegister(); } }