Skip to content

Commit

Permalink
add spotless formatting to 1.20.1 (#1334)
Browse files Browse the repository at this point in the history
* add spotless to 1.20.1

* clean up the GH actions

* run spotless 🥰

* remove some unused classes

* add spotless check action

* reviews
  • Loading branch information
screret committed Jun 1, 2024
1 parent 1e9608a commit 62f7efc
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 79 deletions.
5 changes: 0 additions & 5 deletions .editorconfig

This file was deleted.

2 changes: 1 addition & 1 deletion .github/actions/build_setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
update-cache:
description: If cache should be updated
required: false
default: false
default: true

runs:
using: 'composite'
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/auto-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}"
10 changes: 7 additions & 3 deletions .github/workflows/auto-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/build-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/format-java.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions gradle/scripts/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ 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)
removeUnusedImports('cleanthat-javaparser-unnecessaryimport')
endWithNewline()
eclipse('4.31').configFile(formatFile)
}
}
}
1 change: 0 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,7 +23,7 @@
* @date 2024/2/12
* @implNote HazardProperty
*/
public class HazardProperty implements IMaterialProperty<HazardProperty>{
public class HazardProperty implements IMaterialProperty<HazardProperty> {

@Getter
@Nullable
Expand All @@ -38,9 +39,8 @@ public class HazardProperty implements IMaterialProperty<HazardProperty>{
@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;
Expand All @@ -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<TagPrefix> 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<ArmorItem.Type> 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<ArmorItem.Type> 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);
}
}
Expand All @@ -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));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 62f7efc

Please sign in to comment.