gamerule for toggling player crits

This commit is contained in:
2022-11-14 20:10:28 +01:00
parent b7d1b02d56
commit 28021c389a
5 changed files with 35 additions and 1 deletions
@@ -12,6 +12,8 @@ public class ExtraGameRule {
public static GameRules.Key<GameRules.IntRule> ELYTRA_DAMAGE_FROM_FIREWORK_BOOST;
public static GameRules.Key<GameRules.IntRule> ELYTRA_DAMAGE_FROM_RIPTIDE_BOOST;
public static GameRules.Key<GameRules.BooleanRule> PLAYER_CRITS;
protected static void init() {
MAGMA_BLOCK_DAMAGE = GameRuleRegistry.register(
"magmaBlockDamage",
@@ -38,6 +40,11 @@ public class ExtraGameRule {
GameRules.Category.MISC,
GameRuleFactory.createIntRule(0, 0, Integer.MAX_VALUE)
);
PLAYER_CRITS = GameRuleRegistry.register(
"playerCrits",
GameRules.Category.PLAYER,
GameRuleFactory.createBooleanRule(true)
);
}
}
@@ -0,0 +1,21 @@
package me.youhavetrouble.moregamerules.mixin;
import me.youhavetrouble.moregamerules.ExtraGameRule;
import net.minecraft.entity.player.PlayerEntity;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(PlayerEntity.class)
public class PlayerEntityMixin {
@Redirect(method = "attack", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerEntity;fallDistance:F", opcode = Opcodes.GETFIELD))
private float injected(PlayerEntity instance) {
if (instance.world.getGameRules().getBoolean(ExtraGameRule.PLAYER_CRITS)) {
return instance.fallDistance;
}
return 0f;
}
}
@@ -8,5 +8,7 @@
"gamerule.elytraDamageFromFirework": "Elytra damage from firework boost",
"gamerule.elytraDamageFromFirework.description": "Controls how much damage elytras take when boosting with a firework",
"gamerule.elytraDamageFromRiptideTrident": "Elytra damage from firework boost",
"gamerule.elytraDamageFromRiptideTrident.description": "Controls how much damage elytras take when boosting with a riptide trident"
"gamerule.elytraDamageFromRiptideTrident.description": "Controls how much damage elytras take when boosting with a riptide trident",
"gamerule.playerCrits": "Player crits",
"gamerule.playerCrits.description": "Decides if players should be able to crit"
}
@@ -6,6 +6,7 @@
"mixins": [
"FireworkItemMixin",
"LivingEntityMixin",
"PlayerEntityMixin",
"ServerWorldMixin",
"TridentItemMixin"
],