Skip to content

Commit

Permalink
style: remove "TRAIT_" prefix from all traits
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigmarik committed Jul 1, 2023
1 parent f3c5121 commit 0a5830e
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.command.suggestion.SuggestionProviders;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public EnderPearlEntityMixin(EntityType<? extends ThrownItemEntity> entityType,
target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")
)
private boolean traitedDamage(Entity entity, DamageSource damageSource, float amount) {
if (ServerState.hasTrait((PlayerEntity) entity, Traits.TRAIT_EASY_PEARLS)) {
if (ServerState.hasTrait((PlayerEntity) entity, Traits.EASY_PEARLS)) {
return false;
} else return entity.damage(damageSource, amount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public EnderPearlItemMixin(Settings settings) {
shift = At.Shift.AFTER
))
private void traiedSetDelay(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
if (ServerState.hasTrait(user, Traits.TRAIT_EASY_PEARLS)) {
if (ServerState.hasTrait(user, Traits.EASY_PEARLS)) {
user.getItemCooldownManager().set(Items.ENDER_PEARL, 0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ protected EndermanEntityMixin(EntityType<? extends HostileEntity> entityType, Wo

@Inject(method = "isPlayerStaring", at = @At("HEAD"), cancellable = true)
private void traitedIsStaring(PlayerEntity player, CallbackInfoReturnable<Boolean> cir) {
if (ServerState.hasTrait(player, Traits.TRAIT_NO_EYE_AGGRO)) cir.setReturnValue(false);
if (ServerState.hasTrait(player, Traits.NO_EYE_AGGRO)) cir.setReturnValue(false);
}
}
22 changes: 11 additions & 11 deletions src/main/java/net/sigmarik/abilitymod/mixin/PlayerEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ private boolean hasTrait(String trait) {
}

private void tickFearOfWater() {
if (!hasTrait(Traits.TRAIT_FEAR_OF_WATER) || !isWet()) return;
if (!hasTrait(Traits.FEAR_OF_WATER) || !isWet()) return;

damage(getDamageSources().magic(), 3);
}

private void tickAddiction() {
if (!hasTrait(Traits.TRAIT_ADDICTION)) return;
if (!hasTrait(Traits.ADDICTION)) return;

ServerState.tickAddictionTimer((PlayerEntity)(Object)this);

Expand All @@ -71,7 +71,7 @@ private void tickAddiction() {
}

private void tickBoatMagnet() {
if (!hasTrait(Traits.TRAIT_BOAT_MAGNET)) return;
if (!hasTrait(Traits.BOAT_MAGNET)) return;
if (!hasVehicle() || !(getVehicle() instanceof BoatEntity)) return;

Box attractionBox = Box.of(getPos(), 8, 8, 8);
Expand All @@ -93,7 +93,7 @@ private void tickBoatMagnet() {
}

private void tickDirtSickness() {
if (!hasTrait(Traits.TRAIT_DIRT_SICKNESS) || hasVehicle() || fallDistance > 0.0) return;
if (!hasTrait(Traits.DIRT_SICKNESS) || hasVehicle() || fallDistance > 0.0) return;

if (isTouchingWater() &&
(getWorld().getBiome(getBlockPos()).matchesKey(BiomeKeys.SWAMP) ||
Expand All @@ -105,7 +105,7 @@ private void tickDirtSickness() {
}

private void tickHated() {
if (!hasTrait(Traits.TRAIT_HATED)) return;
if (!hasTrait(Traits.HATED)) return;

Box aggroBox = Box.of(getPos(), 20, 10, 20);

Expand All @@ -119,23 +119,23 @@ private void tickHated() {
}

private void tickFast() {
if (hasTrait(Traits.TRAIT_FAST)) {
if (hasTrait(Traits.FAST)) {
Objects.requireNonNull(getAttributeInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED)).setBaseValue(0.15);
} else { // PlayerEntity::createPlayerAttributes --v
Objects.requireNonNull(getAttributeInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED)).setBaseValue(0.1);
}
}

private void tickStrong() {
if (hasTrait(Traits.TRAIT_STRONG)) {
if (hasTrait(Traits.STRONG)) {
Objects.requireNonNull(getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE)).setBaseValue(1.5);
} else { // PlayerEntity::createPlayerAttributes --v
Objects.requireNonNull(getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE)).setBaseValue(1.0);
}
}

private void tickHotIron() {
if (!hasTrait(Traits.TRAIT_HOT_IRON)) return;
if (!hasTrait(Traits.HOT_IRON)) return;

if (getInventory().containsAny(PropSets.IRON_ITEMS)) setOnFireFor(3);
}
Expand All @@ -156,7 +156,7 @@ private boolean isAffectedByDaylight() {

// Adapted version of ZombieEntity::tickMovement
private void tickDamagedByLight() {
if (!hasTrait(Traits.TRAIT_DAMAGED_BY_LIGHT)) return;
if (!hasTrait(Traits.DAMAGED_BY_LIGHT)) return;
if (!isAffectedByDaylight()) return;

ItemStack helmet = this.getEquippedStack(EquipmentSlot.HEAD);
Expand Down Expand Up @@ -189,8 +189,8 @@ private void traitedTick(CallbackInfo ci) {

@Inject(method = "eatFood", at = @At("RETURN"))
private void traitedEatFood(World world, ItemStack stack, CallbackInfoReturnable<ItemStack> cir) {
if (stack.getItem().equals(Items.ROTTEN_FLESH) && hasTrait(Traits.TRAIT_HARMFUL_ROTTEN_FLESH)) {
if (hasTrait(Traits.TRAIT_INVERT_EFFECTS)) {
if (stack.getItem().equals(Items.ROTTEN_FLESH) && hasTrait(Traits.HARMFUL_ROTTEN_FLESH)) {
if (hasTrait(Traits.INVERT_EFFECTS)) {
addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 30 * 20));
} else {
addStatusEffect(new StatusEffectInstance(StatusEffects.POISON, 30 * 20));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public PotionItemMixin(Settings settings) {
@Inject(method = "finishUsing", at = @At("HEAD"))
private void traitedFinishUsing(ItemStack stack, World world, LivingEntity user, CallbackInfoReturnable<ItemStack> cir) {
if (user instanceof PlayerEntity && PotionUtil.getPotion(stack) == Potions.THICK &&
ServerState.hasTrait((PlayerEntity)user, Traits.TRAIT_ADDICTION) &&
ServerState.hasTrait((PlayerEntity)user, Traits.ADDICTION) &&
ServerState.getAddictionTimer((PlayerEntity)user) < net.sigmarik.abilitymod.util.Settings.ADDICTION_MID_TIMER) {
ServerState.setAddictionTimer((PlayerEntity)user, net.sigmarik.abilitymod.util.Settings.ADDICTION_MID_TIMER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public abstract class StatusEffectMixin {
@Inject(method = "applyUpdateEffect", at = @At("HEAD"), cancellable = true)
private void invertRegeneration(LivingEntity entity, int amplifier, CallbackInfo ci) {
if (entity instanceof PlayerEntity && ServerState.hasTrait((PlayerEntity)entity, Traits.TRAIT_INVERT_EFFECTS)) {
if (entity instanceof PlayerEntity && ServerState.hasTrait((PlayerEntity)entity, Traits.INVERT_EFFECTS)) {
if ((Object)this == StatusEffects.REGENERATION) {
if (entity.getHealth() > 1.0F) {
entity.damage(entity.getDamageSources().magic(), 1.0F);
Expand All @@ -36,6 +36,6 @@ private void invertRegeneration(LivingEntity entity, int amplifier, CallbackInfo
private boolean traitedIsUndead(LivingEntity entity) {
return entity.isUndead() ||
(entity instanceof PlayerEntity &&
ServerState.hasTrait((PlayerEntity)entity, Traits.TRAIT_INVERT_EFFECTS));
ServerState.hasTrait((PlayerEntity)entity, Traits.INVERT_EFFECTS));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private void checkUndead(@Nullable LivingEntity baseEntity, LivingEntity targetE
if (baseEntity == null) return;
if (baseEntity.isUndead() &&
targetEntity instanceof PlayerEntity &&
ServerState.hasTrait((PlayerEntity)targetEntity, Traits.TRAIT_IGNORED_BY_UNDEAD) &&
ServerState.hasTrait((PlayerEntity)targetEntity, Traits.IGNORED_BY_UNDEAD) &&
baseEntity.getAttacker() != targetEntity) {
cir.setReturnValue(false);
}
Expand Down
47 changes: 33 additions & 14 deletions src/main/java/net/sigmarik/abilitymod/util/Traits.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
package net.sigmarik.abilitymod.util;

import java.util.Set;

public class Traits {
public static final String TRAIT_EASY_PEARLS = "easy_pearls";
public static final String TRAIT_NO_EYE_AGGRO = "no_eye_aggro";
public static final String TRAIT_FEAR_OF_WATER = "fear_of_water";
public static final String TRAIT_IGNORED_BY_UNDEAD = "ignored_by_undead";
public static final String TRAIT_DAMAGED_BY_LIGHT = "damaged_by_light";
public static final String TRAIT_HARMFUL_ROTTEN_FLESH = "harmful_rotten_flesh";
public static final String TRAIT_INVERT_EFFECTS = "invert_effects";
public static final String TRAIT_BOAT_MAGNET = "boat_magnet";
public static final String TRAIT_DIRT_SICKNESS = "dirt_sickness";
public static final String TRAIT_ADDICTION = "addiction";
public static final String TRAIT_FAST = "fast";
public static final String TRAIT_STRONG = "strong";
public static final String TRAIT_HATED = "hated";
public static final String TRAIT_HOT_IRON = "hot_iron";
public static final String EASY_PEARLS = "easy_pearls";
public static final String NO_EYE_AGGRO = "no_eye_aggro";
public static final String FEAR_OF_WATER = "fear_of_water";
public static final String IGNORED_BY_UNDEAD = "ignored_by_undead";
public static final String DAMAGED_BY_LIGHT = "damaged_by_light";
public static final String HARMFUL_ROTTEN_FLESH = "harmful_rotten_flesh";
public static final String INVERT_EFFECTS = "invert_effects";
public static final String BOAT_MAGNET = "boat_magnet";
public static final String DIRT_SICKNESS = "dirt_sickness";
public static final String ADDICTION = "addiction";
public static final String FAST = "fast";
public static final String STRONG = "strong";
public static final String HATED = "hated";
public static final String HOT_IRON = "hot_iron";

public static final Set<String> TRAITS = Set.of(
EASY_PEARLS,
NO_EYE_AGGRO,
FEAR_OF_WATER,
IGNORED_BY_UNDEAD,
DAMAGED_BY_LIGHT,
HARMFUL_ROTTEN_FLESH,
INVERT_EFFECTS,
BOAT_MAGNET,
DIRT_SICKNESS,
ADDICTION,
FAST,
STRONG,
HATED,
HOT_IRON
);
}

0 comments on commit 0a5830e

Please sign in to comment.