-
Notifications
You must be signed in to change notification settings - Fork 0
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
Kitsune traits #2
Conversation
feat: added the ability to add or remove multiple traits simultaneously
int lightLevel = world.getLightLevel(LightType.SKY, this.getBlockPos()); | ||
if (!(lightLevel <= 11 || | ||
!world.isSkyVisible(this.getBlockPos()) || this.isTouchingWaterOrRain() || this.isInLava() || | ||
this.hasStatusEffect(StatusEffect.byRawId(AbilityMod.FIRE_RESISTANCE_STATUS_EFFECT)) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasStatusEffect(StatusEffects.FIRE_RESISTANCE);
There is no need to add magical numbers that can change in the next update of the game. You can just use existing values.
@@ -33,10 +40,99 @@ public class AbilityMod implements DedicatedServerModInitializer { | |||
|
|||
public static final double BOAT_ATTRACTION_FACTOR = 0.1; | |||
|
|||
public static final int FIRE_RESISTANCE_STATUS_EFFECT = 12; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary magical number. See the comment at line 96 of PlayerEntityMixin.
@@ -33,10 +40,99 @@ public class AbilityMod implements DedicatedServerModInitializer { | |||
|
|||
public static final double BOAT_ATTRACTION_FACTOR = 0.1; | |||
|
|||
public static final int FIRE_RESISTANCE_STATUS_EFFECT = 12; | |||
|
|||
public static final int FIRING_CHANCE_PER_TICK = 55; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No linkage to the trait this parameter corresponds to. Change the name or move it somewhere to make it obvious that it affects "DAMAGED_BY_DAYLIGHT" trait effect.
And also... Why is catching flame on daylight has a probability to happen? It makes sense for zombies, as they need to vary their flames a little so they wouldn't take damage at the exact same ticks. But I highly doubt there will every be a crowd of players with this trait purposefully syncing their flaming ticks.
EntityType.TRADER_LLAMA | ||
)); | ||
|
||
public static final double FAST_COEFFICIENT = 0.3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, these names are a little awkward... May be move these coefficients to the place they are used at?
Even though it s hell of a wrong code practice, we need it to follow it on order to preserve consistency with the Minecraft code.
)); | ||
|
||
public static final double FAST_COEFFICIENT = 0.3; | ||
public static final UUID FAST_MODIFIER_UUID = new UUID(Random.createLocal().nextLong(), Random.createLocal().nextLong()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using random numbers as unique identifiers is a practice you use when you want your game to crash in random ways at random moments.
Please see if there is a way to generate truly unique UUID without affecting other important game systems, such as player account identification.
@@ -22,11 +26,12 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { | |||
literal("trait").requires(source -> source.hasPermissionLevel(2)) | |||
.then(literal("add") | |||
.then(argument("players", EntityArgumentType.players()) | |||
.then(argument("trait", StringArgumentType.word()).suggests(SuggestionProviders.ALL_RECIPES) | |||
.then(argument("trait", StringArgumentType.greedyString()) | |||
.suggests(SuggestionProviders.ALL_RECIPES) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These arguments are not recipes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I remind who made this code line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you noticed an inconvenience and decided to blindly copy it, that's on you, even though I was the one who forgot to remove the test line from the code.
|
||
if (trait.equals(AbilityMod.TRAIT_FAST)) { | ||
EntityAttributeInstance speed = player.getAttributes().getCustomInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED); | ||
EntityAttributeModifier speedModifier = new EntityAttributeModifier(AbilityMod.FAST_MODIFIER_UUID, "Fast", AbilityMod.FAST_COEFFICIENT, EntityAttributeModifier.Operation.MULTIPLY_BASE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at this long boiiiiiiiiiii
} | ||
if (trait.equals(AbilityMod.TRAIT_STRONG)) { | ||
EntityAttributeInstance strength = player.getAttributes().getCustomInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE); | ||
EntityAttributeModifier strengthModifier = new EntityAttributeModifier(AbilityMod.STRONG_MODIFIER_UUID, "Strong", AbilityMod.STRONG_COEFFICIENT, EntityAttributeModifier.Operation.MULTIPLY_BASE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long boiiiiiiiiii
|
||
if (trait.equals(AbilityMod.TRAIT_FAST)) { | ||
EntityAttributeInstance speed = player.getAttributes().getCustomInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED); | ||
EntityAttributeModifier speedModifier = new EntityAttributeModifier(AbilityMod.FAST_MODIFIER_UUID, "Fast", AbilityMod.FAST_COEFFICIENT, EntityAttributeModifier.Operation.MULTIPLY_BASE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, I really should have got a wide monitor for this review...
Anyway, there is another LONG BOIIIIIIIIII
} | ||
if (trait.equals(AbilityMod.TRAIT_STRONG)) { | ||
EntityAttributeInstance strength = player.getAttributes().getCustomInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE); | ||
EntityAttributeModifier strengthModifier = new EntityAttributeModifier(AbilityMod.STRONG_MODIFIER_UUID, "Strong", AbilityMod.STRONG_COEFFICIENT, EntityAttributeModifier.Operation.MULTIPLY_BASE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static long long boiiii this_line = ". . ."
private void tickIronBurn() { | ||
if (ServerState.hasTrait((PlayerEntity)(Object)this, AbilityMod.TRAIT_HOT_IRON)) { | ||
boolean doDamage = false; | ||
for (int i = 0; i < 41; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is time to start a witch hunt and burn every magical number.
You can use this.getInventory().size()
to get the size of the player's inventory.
And also, even though it is a little controversial, it would be cool if you renamed iterator to something like stackId
instead of single-character i
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the issues highlighted in comments.
Items.WATER_BUCKET | ||
)); | ||
|
||
public static final HashSet<EntityType> NEUTRAL_MOBS = new HashSet<>(List.of( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a way to implement "hated" trait without this list.
refactor: refactored some bad-looking code refactor: now per-tick functions stop immediately, if it's need feat: added correct suggestions to /trait command
Items.WATER_BUCKET | ||
)); | ||
|
||
public static final double MOVEMENT_SPEED_BASE_MULTIPLY_COEFFICIENT = 0.3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THIS_IS_HELL_OF_A_LONG_VARIABLE_NAME
And even the name above is shorter than the name of the variable in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
He doesn't like obscure names, he doesn't like understandable names...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The very reason why I asked you to change the variable name was that it didn't represent the trait it relates to.
Now let's take a look at you 40-character long (holy ****) variable name. May be I am a dummy, after all, and you really need that many words to describe what is going on.
How does the word "BASE" contribute to the variable name? Is this variable the root of some obscure tree? Or is it some value that will be gradually changed later? But why is it final
, then?
That's because it is not, it's just a constant you need to multiply the player's movement at one point in the code. So the word "BASE" is unnecessary at best and misleading at worst.
"MULTIPLY_COEFFICIENT". It's called "multiplication coefficient" if you really want to preserve that Shakespearian vibe you are going with in your code. Programmers usually call this "multiplier", unless it occurs in some form of series or equations with other parameters, where it should be called "coefficient". In this case the word "multiplier" is more than enough.
"MOVEMENT_SPEED". There are not many parameters related to "movement". At least not many you would ever want to change. Just the word "movement" or "speed" should be enough.
So, we end up with "SPEED_MULTIPLIER" or "MOVEMENT_SPEED_MULTIPLIER", if you don't like the last transformation. These names are shorter than the original and less misleading than the original. Yet, neither them, nor the original 40-ch. long name describe where this multiplier is applied. It could relate to cobweb speed reduction (I mean, this coefficient is less than 1, so it should relate to slowing down something), it could relate to speed potion effect change, it could just mean that every player is now 3 times slower than they originally were. This extremely long misleading nonsensical variable name does not do ANYTHING to describe the very thing I asked for in the original review. So what's the purpose of all this circus?
|
||
public static final double MOVEMENT_SPEED_BASE_MULTIPLY_COEFFICIENT = 0.3; | ||
|
||
public static final double ATTACK_DAMAGE_BASE_MULTIPLY_COEFFICIENT = 0.3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WOW_THIS_NAME_IS_ALSO_SUPER_LONG
"Fast", AbilityMod.MOVEMENT_SPEED_BASE_MULTIPLY_COEFFICIENT, | ||
EntityAttributeModifier.Operation.MULTIPLY_BASE); | ||
if (!speed.hasModifier(speedModifier)) { | ||
speed.addPersistentModifier(speedModifier); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is, like, 5-6 tabs before the start of the line. I know, this can be classified as a java syntax, but at least it is a hint to wrap this part of the code into function.
Who knows, may be you will even be able to generalize the logic and not repeat the same code again and again.
@@ -87,4 +149,30 @@ private static int printTraits(CommandContext<ServerCommandSource> context) thro | |||
|
|||
return 1; | |||
} | |||
|
|||
private static class TraitsSuggestionProvider implements SuggestionProvider<ServerCommandSource> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that... is that a subclass declared in the middle of nowhere, lost in the forest of method definitions?
First I thought you created a completely new class when you used it inside register()
function.
Subclasses deserve their place on top of the class definition, they are not part of the all structurally insignificant code written inside method definitions.
} | ||
} | ||
|
||
private void tickBoatMagnet() { | ||
if (ServerState.hasTrait((PlayerEntity)(Object)this, AbilityMod.TRAIT_BOAT_MAGNET) && hasVehicle() && | ||
if (!ServerState.hasTrait((PlayerEntity)(Object)this, AbilityMod.TRAIT_BOAT_MAGNET) && hasVehicle() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You did not inverse the condition. The code above (and a few lines below) do not represent the same logic there was before.
This code just does not work correctly.
} | ||
} | ||
|
||
private void tickLightBurn() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tickLightDamage
? It corelates a bit more with the trait name.
It's just a suggestion, though.
} | ||
} | ||
} | ||
|
||
private void tickIronBurn() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tickHotIron
?
this.hasStatusEffect(StatusEffects.FIRE_RESISTANCE) || | ||
this.getBlockStateAtPos().getBlock().equals(Blocks.COBWEB) || (time >= 12542 && time < 23460) || | ||
!world.getRegistryKey().getValue().equals(DimensionTypes.OVERWORLD_ID))) { | ||
if (world.random.nextInt(AbilityMod.DAYLIGHT_BURNING_CHANCE_PER_TICK) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nested if
-statements.
No description provided.