elytra damage control gamerules

This commit is contained in:
2022-11-13 21:12:22 +01:00
parent dfefed1286
commit ddb47f96c4
7 changed files with 109 additions and 9 deletions
@@ -8,6 +8,9 @@ public class ExtraGameRule {
public static GameRules.Key<GameRules.BooleanRule> MAGMA_BLOCK_DAMAGE; public static GameRules.Key<GameRules.BooleanRule> MAGMA_BLOCK_DAMAGE;
public static GameRules.Key<GameRules.IntRule> LIGHTNING_ROD_RANGE; public static GameRules.Key<GameRules.IntRule> LIGHTNING_ROD_RANGE;
public static GameRules.Key<GameRules.IntRule> ELYTRA_DAMAGE_PER_SECOND;
public static GameRules.Key<GameRules.IntRule> ELYTRA_DAMAGE_FROM_FIREWORK_BOOST;
public static GameRules.Key<GameRules.IntRule> ELYTRA_DAMAGE_FROM_RIPTIDE_BOOST;
protected static void init() { protected static void init() {
MAGMA_BLOCK_DAMAGE = GameRuleRegistry.register( MAGMA_BLOCK_DAMAGE = GameRuleRegistry.register(
@@ -20,6 +23,21 @@ public class ExtraGameRule {
GameRules.Category.MISC, GameRules.Category.MISC,
GameRuleFactory.createIntRule(128, 0, Integer.MAX_VALUE) GameRuleFactory.createIntRule(128, 0, Integer.MAX_VALUE)
); );
ELYTRA_DAMAGE_PER_SECOND = GameRuleRegistry.register(
"elytraDamagePerSecond",
GameRules.Category.MISC,
GameRuleFactory.createIntRule(1, 0, Integer.MAX_VALUE)
);
ELYTRA_DAMAGE_FROM_FIREWORK_BOOST = GameRuleRegistry.register(
"elytraDamageFromFirework",
GameRules.Category.MISC,
GameRuleFactory.createIntRule(0, 0, Integer.MAX_VALUE)
);
ELYTRA_DAMAGE_FROM_RIPTIDE_BOOST = GameRuleRegistry.register(
"elytraDamageFromRiptideTrident",
GameRules.Category.MISC,
GameRuleFactory.createIntRule(0, 0, Integer.MAX_VALUE)
);
} }
} }
@@ -0,0 +1,31 @@
package me.youhavetrouble.moregamerules.mixin;
import me.youhavetrouble.moregamerules.ExtraGameRule;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(FireworkRocketItem.class)
public class FireworkItemMixin {
@Inject(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/projectile/FireworkRocketEntity;<init>(Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;Lnet/minecraft/entity/LivingEntity;)V", shift = At.Shift.AFTER))
private void injected(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
ItemStack chestItem = user.getEquippedStack(EquipmentSlot.CHEST);
int damage = user.world.getGameRules().getInt(ExtraGameRule.ELYTRA_DAMAGE_FROM_FIREWORK_BOOST);
if (!chestItem.isOf(Items.ELYTRA) || damage == 0) return;
if (chestItem.getDamage() + damage >= chestItem.getMaxDamage() ) {
chestItem.setDamage(chestItem.getMaxDamage()-1);
} else {
chestItem.damage(damage, (LivingEntity)user, ((player) -> player.sendEquipmentBreakStatus(EquipmentSlot.CHEST)));
}
}
}
@@ -0,0 +1,18 @@
package me.youhavetrouble.moregamerules.mixin;
import me.youhavetrouble.moregamerules.ExtraGameRule;
import net.minecraft.entity.LivingEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
@Mixin(LivingEntity.class)
public class LivingEntityMixin {
@ModifyArg(method = "tickFallFlying", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damage(ILnet/minecraft/entity/LivingEntity;Ljava/util/function/Consumer;)V"), index = 0)
private int injectedGetLightningRodPos(int range) {
LivingEntity livingEntity = (LivingEntity)(Object) this;
return livingEntity.world.getGameRules().getInt(ExtraGameRule.ELYTRA_DAMAGE_PER_SECOND);
}
}
@@ -1,7 +1,6 @@
package me.youhavetrouble.moregamerules.mixin; package me.youhavetrouble.moregamerules.mixin;
import me.youhavetrouble.moregamerules.ExtraGameRule; import me.youhavetrouble.moregamerules.ExtraGameRule;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.MagmaBlock; import net.minecraft.block.MagmaBlock;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@@ -13,11 +12,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(MagmaBlock.class) @Mixin(MagmaBlock.class)
public class MagmaBlockMixin extends Block { public class MagmaBlockMixin {
public MagmaBlockMixin(Settings settings) {
super(settings);
}
@Inject(at = @At("HEAD"), method = "onSteppedOn", cancellable = true) @Inject(at = @At("HEAD"), method = "onSteppedOn", cancellable = true)
private void injectedOnSteppedOn(World world, BlockPos pos, BlockState state, Entity entity, CallbackInfo info) { private void injectedOnSteppedOn(World world, BlockPos pos, BlockState state, Entity entity, CallbackInfo info) {
@@ -0,0 +1,30 @@
package me.youhavetrouble.moregamerules.mixin;
import me.youhavetrouble.moregamerules.ExtraGameRule;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.TridentItem;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(TridentItem.class)
public class TridentItemMixin {
@Inject(method = "onStoppedUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;addVelocity(DDD)V", shift = At.Shift.BEFORE))
private void injected(ItemStack stack, World world, LivingEntity user, int remainingUseTicks, CallbackInfo ci) {
ItemStack chestItem = user.getEquippedStack(EquipmentSlot.CHEST);
int damage = user.world.getGameRules().getInt(ExtraGameRule.ELYTRA_DAMAGE_FROM_RIPTIDE_BOOST);
if (!chestItem.isOf(Items.ELYTRA) || damage == 0) return;
if (chestItem.getDamage() + damage >= chestItem.getMaxDamage() ) {
chestItem.setDamage(chestItem.getMaxDamage()-1);
} else {
chestItem.damage(damage, user, ((player) -> player.sendEquipmentBreakStatus(EquipmentSlot.CHEST)));
}
}
}
@@ -2,5 +2,11 @@
"gamerule.magmaBlockDamage": "Magma block damage", "gamerule.magmaBlockDamage": "Magma block damage",
"gamerule.magmaBlockDamage.description": "Controls if magma blocks should do damage when stepped on", "gamerule.magmaBlockDamage.description": "Controls if magma blocks should do damage when stepped on",
"gamerule.lightningRodRange": "Lightning rod range", "gamerule.lightningRodRange": "Lightning rod range",
"gamerule.lightningRodRange.description": "Sets the range in which lightning rod will redirect lightning" "gamerule.lightningRodRange.description": "Sets the range in which lightning rod will redirect lightning",
"gamerule.elytraDamagePerSecond": "Elytra damage per second",
"gamerule.elytraDamagePerSecond.description": "Controls how much damage elytras take when flying",
"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"
} }
+4 -2
View File
@@ -4,13 +4,15 @@
"package": "me.youhavetrouble.moregamerules.mixin", "package": "me.youhavetrouble.moregamerules.mixin",
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_17",
"mixins": [ "mixins": [
"ServerWorldMixin" "FireworkItemMixin",
"LivingEntityMixin",
"ServerWorldMixin",
"TridentItemMixin"
], ],
"client": [ "client": [
], ],
"server": [ "server": [
"MagmaBlockMixin" "MagmaBlockMixin"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1