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 pre-commit formatting #771

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.14.0
hooks:
- id: pretty-format-java
args: [--autofix, --aosp]
- id: pretty-format-kotlin
args: [--ktfmt, --autofix, --ktfmt-style=kotlinlang]
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,18 @@
// yoinky sploinky

/**
* A purely-documentative annotation.
* This annotation is used by developers in xplat code. The annotated method is intended
* to "soft implement" a certain method in a loader specific interface that cannot be
* named in xplat code and thus cannot be checked with @Override.
* In this context, "soft implement" means to implement the method by matching the signature
* with the intended interface method.
* Examples of interfaces that we would use this for is IForgeItem or FabricItem.
* <p>
* The intent is that we audit such sites every major Minecraft version or so, to ensure
* that they still properly override the intended target.
* A purely-documentative annotation. This annotation is used by developers in xplat code. The
* annotated method is intended to "soft implement" a certain method in a loader specific interface
* that cannot be named in xplat code and thus cannot be checked with @Override. In this context,
* "soft implement" means to implement the method by matching the signature with the intended
* interface method. Examples of interfaces that we would use this for is IForgeItem or FabricItem.
*
* <p>The intent is that we audit such sites every major Minecraft version or so, to ensure that
* they still properly override the intended target.
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.METHOD)
public @interface SoftImplement {
/**
* What interface we're soft implementing
*/
/** What interface we're soft implementing */
String value();
}
183 changes: 94 additions & 89 deletions Common/src/main/java/at/petrak/hexcasting/api/HexAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.player.Sentinel;
import at.petrak.hexcasting.xplat.IXplatAbstractions;

import com.google.common.base.Suppliers;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
Expand All @@ -16,14 +18,14 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.Mob;
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 net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.phys.Vec3;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
Expand All @@ -36,23 +38,27 @@ public interface HexAPI {
String MOD_ID = "hexcasting";
Logger LOGGER = LogManager.getLogger(MOD_ID);

Supplier<HexAPI> INSTANCE = Suppliers.memoize(() -> {
try {
return (HexAPI) Class.forName("at.petrak.hexcasting.common.impl.HexAPIImpl")
.getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException e) {
LogManager.getLogger().warn("Unable to find HexAPIImpl, using a dummy");
return new HexAPI() {
};
}
});
Supplier<HexAPI> INSTANCE =
Suppliers.memoize(
() -> {
try {
return (HexAPI)
Class.forName("at.petrak.hexcasting.common.impl.HexAPIImpl")
.getDeclaredConstructor()
.newInstance();
} catch (ReflectiveOperationException e) {
LogManager.getLogger().warn("Unable to find HexAPIImpl, using a dummy");
return new HexAPI() {};
}
});

/**
* Return the localization key for the given action.
* <p>
* Note we're allowed to have action <em>resource keys</em> on the client, just no actual actions.
* <p>
* Special handlers should be calling {@link SpecialHandler#getName()}
*
* <p>Note we're allowed to have action <em>resource keys</em> on the client, just no actual
* actions.
*
* <p>Special handlers should be calling {@link SpecialHandler#getName()}
*/
default String getActionI18nKey(ResourceKey<ActionRegistryEntry> action) {
return "hexcasting.action.%s".formatted(action.location().toString());
Expand All @@ -63,37 +69,40 @@ default String getSpecialHandlerI18nKey(ResourceKey<SpecialHandler.Factory<?>> a
}

/**
* Currently introspection/retrospection/consideration are hardcoded, but at least their names won't be
* Currently introspection/retrospection/consideration are hardcoded, but at least their names
* won't be
*/
default String getRawHookI18nKey(ResourceLocation name) {
return "hexcasting.rawhook.%s".formatted(name);
}

default Component getActionI18n(ResourceKey<ActionRegistryEntry> key, boolean isGreat) {
return Component.translatable(getActionI18nKey(key))
.withStyle(isGreat ? ChatFormatting.GOLD : ChatFormatting.LIGHT_PURPLE);
.withStyle(isGreat ? ChatFormatting.GOLD : ChatFormatting.LIGHT_PURPLE);
}

default Component getSpecialHandlerI18n(ResourceKey<SpecialHandler.Factory<?>> key) {
return Component.translatable(getSpecialHandlerI18nKey(key))
.withStyle(ChatFormatting.LIGHT_PURPLE);
.withStyle(ChatFormatting.LIGHT_PURPLE);
}

default Component getRawHookI18n(ResourceLocation name) {
return Component.translatable(getRawHookI18nKey(name)).withStyle(ChatFormatting.LIGHT_PURPLE);
return Component.translatable(getRawHookI18nKey(name))
.withStyle(ChatFormatting.LIGHT_PURPLE);
}

/**
* Register an entity with the given ID to have its velocity as perceived by OpEntityVelocity be different
* than it's "normal" velocity
* Register an entity with the given ID to have its velocity as perceived by OpEntityVelocity be
* different than it's "normal" velocity
*/
// Should be OK to use the type directly as the key as they're singleton identity objects
default <T extends Entity> void registerSpecialVelocityGetter(EntityType<T> key, EntityVelocityGetter<T> getter) {
}
default <T extends Entity> void registerSpecialVelocityGetter(
EntityType<T> key, EntityVelocityGetter<T> getter) {}

/**
* If the entity has had a special getter registered with {@link HexAPI#registerSpecialVelocityGetter} then
* return that, otherwise return its normal delta movement
* If the entity has had a special getter registered with {@link
* HexAPI#registerSpecialVelocityGetter} then return that, otherwise return its normal delta
* movement
*/
default Vec3 getEntityVelocitySpecial(Entity entity) {
return entity.getDeltaMovement();
Expand All @@ -106,36 +115,34 @@ interface EntityVelocityGetter<T extends Entity> {

/**
* Register an entity type to have a custom behavior when getting brainswept.
* <p>
* This knocks out the normal behavior; if you want that behavior you should call
*
* <p>This knocks out the normal behavior; if you want that behavior you should call
*/
default <T extends Mob> void registerCustomBrainsweepingBehavior(EntityType<T> key, Consumer<T> hook) {
}
default <T extends Mob> void registerCustomBrainsweepingBehavior(
EntityType<T> key, Consumer<T> hook) {}

/**
* The default behavior when an entity gets brainswept.
* <p>
* Something registered with {@link HexAPI#registerCustomBrainsweepingBehavior} doesn't call this automatically;
* you can use this to add things on top of the default behavior
*
* <p>Something registered with {@link HexAPI#registerCustomBrainsweepingBehavior} doesn't call
* this automatically; you can use this to add things on top of the default behavior
*/
default Consumer<Mob> defaultBrainsweepingBehavior() {
return mob -> {
};
return mob -> {};
}

/**
* If something special's been returned with {@link HexAPI#registerCustomBrainsweepingBehavior}, return that,
* otherwise return the default behavior
* If something special's been returned with {@link HexAPI#registerCustomBrainsweepingBehavior},
* return that, otherwise return the default behavior
*/
default <T extends Mob> Consumer<T> getBrainsweepBehavior(EntityType<T> mobType) {
return mob -> {
};
return mob -> {};
}

/**
* Brainsweep (flay the mind of) the given mob.
* <p>
* This ignores the unbrainsweepable tag.
*
* <p>This ignores the unbrainsweepable tag.
*/
default void brainsweep(Mob mob) {
var type = (EntityType<? extends Mob>) mob.getType();
Expand Down Expand Up @@ -165,61 +172,59 @@ default FrozenPigment getColorizer(Player player) {
return FrozenPigment.DEFAULT.get();
}

ArmorMaterial DUMMY_ARMOR_MATERIAL = new ArmorMaterial() {
@Override
public int getDurabilityForType(ArmorItem.Type type) {
return 0;
}

@Override
public int getDefenseForType(ArmorItem.Type type) {
return 0;
}

@Override
public int getEnchantmentValue() {
return 0;
}

@NotNull
@Override
public SoundEvent getEquipSound() {
return SoundEvents.ARMOR_EQUIP_LEATHER;
}

@NotNull
@Override
public Ingredient getRepairIngredient() {
return Ingredient.EMPTY;
}

@Override
public String getName() {
return "missingno";
}

@Override
public float getToughness() {
return 0;
}

@Override
public float getKnockbackResistance() {
return 0;
}
};
ArmorMaterial DUMMY_ARMOR_MATERIAL =
new ArmorMaterial() {
@Override
public int getDurabilityForType(ArmorItem.Type type) {
return 0;
}

@Override
public int getDefenseForType(ArmorItem.Type type) {
return 0;
}

@Override
public int getEnchantmentValue() {
return 0;
}

@NotNull
@Override
public SoundEvent getEquipSound() {
return SoundEvents.ARMOR_EQUIP_LEATHER;
}

@NotNull
@Override
public Ingredient getRepairIngredient() {
return Ingredient.EMPTY;
}

@Override
public String getName() {
return "missingno";
}

@Override
public float getToughness() {
return 0;
}

@Override
public float getKnockbackResistance() {
return 0;
}
};

default ArmorMaterial robesMaterial() {
return DUMMY_ARMOR_MATERIAL;
}

/**
* Location in the userdata of the ravenmind
*/
/** Location in the userdata of the ravenmind */
String RAVENMIND_USERDATA = modLoc("ravenmind").toString();
/**
* Location in the userdata of the number of ops executed
*/

/** Location in the userdata of the number of ops executed */
String OP_COUNT_USERDATA = modLoc("op_count").toString();

String MARKED_MOVED_USERDATA = modLoc("impulsed").toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import at.petrak.hexcasting.api.casting.iota.Iota;
import at.petrak.hexcasting.api.pigment.FrozenPigment;

import net.minecraft.server.level.ServerLevel;

import org.jetbrains.annotations.Nullable;

import java.util.List;
Expand All @@ -20,5 +22,6 @@ public interface ADHexHolder {

void clearHex();

@Nullable FrozenPigment getPigment();
@Nullable
FrozenPigment getPigment();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import at.petrak.hexcasting.api.casting.iota.Iota;
import at.petrak.hexcasting.api.casting.iota.IotaType;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;

import org.jetbrains.annotations.Nullable;

public interface ADIotaHolder {
Expand Down
Loading
Loading