diff --git a/src/main/java/dev/symphony/harmony/config/HarmonyConfig.java b/src/main/java/dev/symphony/harmony/config/HarmonyConfig.java index a9eeb87..eeccda6 100644 --- a/src/main/java/dev/symphony/harmony/config/HarmonyConfig.java +++ b/src/main/java/dev/symphony/harmony/config/HarmonyConfig.java @@ -14,12 +14,13 @@ public class HarmonyConfig extends MidnightConfig { @Entry(category = TRANS) public static boolean exitVehicleOnDamage = true; @HarmonyConfigCondition.ResourceConfigName(config_name = "recipe/saddle") @Entry(category = TRANS) public static boolean saddleRecipe = true; @Entry(category = TRANS) public static boolean horseArmorPreventsBucking = true; + @Entry(category = TRANS) public static boolean enderPearlsTeleportVehicles = true; + @Entry(category = TRANS) public static boolean enderPearlsDamageVehicles = true; @Entry(category = TRANS, isSlider = true, min = 0f, max = 1f) public static float riptideAccelerationOnWater = 0.1f; @Entry(category = TRANS) public static boolean riptideCooldown = true; @Entry(category = TRANS) public static int riptideTimeMultiplier = 5; @Entry(category = TRANS) public static boolean reduceRiptideWaterDrag = true; - // Food public static final String FOOD = "food"; @Entry(category = FOOD) public static int stewStackSize = 16; diff --git a/src/main/java/dev/symphony/harmony/mixin/transportation/EnderPearlsDontDismount.java b/src/main/java/dev/symphony/harmony/mixin/transportation/EnderPearlsDontDismount.java new file mode 100644 index 0000000..a8c4bf9 --- /dev/null +++ b/src/main/java/dev/symphony/harmony/mixin/transportation/EnderPearlsDontDismount.java @@ -0,0 +1,61 @@ +package dev.symphony.harmony.mixin.transportation; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import dev.symphony.harmony.config.HarmonyConfig; +import net.minecraft.entity.Entity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.projectile.thrown.EnderPearlEntity; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.TeleportTarget; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +/** + * FEATURE: Allowed Ender Pearls to teleport all riders and passengers, all taking damage. + * @author RandomVideos + */ +@Mixin(EnderPearlEntity.class) +public class EnderPearlsDontDismount { + + @WrapOperation(method = "onCollision",at= @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;teleportTo(Lnet/minecraft/world/TeleportTarget;)Lnet/minecraft/server/network/ServerPlayerEntity;")) + ServerPlayerEntity TeleportMount(ServerPlayerEntity instance, TeleportTarget teleportTarget, Operation original){ + if(instance.hasVehicle() && HarmonyConfig.enderPearlsTeleportVehicles){ + //Find the mount that isnt riding any other mount and teleport it instead of the player + Entity vehicle = instance.getVehicle(); + while(vehicle.hasVehicle()) { + vehicle = vehicle.getVehicle(); + } + vehicle.teleportTo(teleportTarget); + return instance; + } + else return original.call(instance,teleportTarget); + } + + @WrapOperation(method = "onCollision",at= @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;damage(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/damage/DamageSource;F)Z")) + boolean DamageAfterTeleportation(ServerPlayerEntity instance, ServerWorld world, DamageSource source, float amount, Operation original){ + if(instance.hasVehicle() && HarmonyConfig.enderPearlsDamageVehicles && HarmonyConfig.enderPearlsTeleportVehicles) { + //The damage each entity takes from teleporting is halved to be consistent with horses taking fall damage + amount /= 2; + //Find the mount that isnt riding any other mount + Entity vehicle = instance.getVehicle(); + while (vehicle.hasVehicle()) { + vehicle = vehicle.getVehicle(); + } + //Damage that vehicle + vehicle.damage(world, source, amount); + //For each passenger of the vehicle(this counts passengers of passengers), damage that entity + for (Entity entity : vehicle.getPassengersDeep()) { + entity.damage(world, source, amount); + } + return true; + } + else return original.call(instance, world, source, amount); + } + + //Stop the player from leaving their vehicle when using an Ender Pearl + @WrapOperation(method = "onCollision",at= @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;detach()V")) + void StopDetaching(Entity instance, Operation original){if(!HarmonyConfig.enderPearlsTeleportVehicles) {original.call(instance);}} + +} diff --git a/src/main/java/dev/symphony/harmony/mixin/transportation/ExitVehicleOnDamage.java b/src/main/java/dev/symphony/harmony/mixin/transportation/ExitVehicleOnDamage.java index c218ebe..a24319f 100644 --- a/src/main/java/dev/symphony/harmony/mixin/transportation/ExitVehicleOnDamage.java +++ b/src/main/java/dev/symphony/harmony/mixin/transportation/ExitVehicleOnDamage.java @@ -32,6 +32,7 @@ private void exitVehicleOnDamage(ServerWorld world, DamageSource source, float a if(HarmonyConfig.exitVehicleOnDamage) { if (amount <= 0) return; if (this.isPlayer()) return; + if (source == getDamageSources().enderPearl()) return; Entity vehicle = this.getVehicle(); diff --git a/src/main/resources/assets/harmony/lang/en_us.json b/src/main/resources/assets/harmony/lang/en_us.json index 8718d8d..106810b 100644 --- a/src/main/resources/assets/harmony/lang/en_us.json +++ b/src/main/resources/assets/harmony/lang/en_us.json @@ -12,6 +12,9 @@ "harmony.midnightconfig.saddleRecipe": "Craftable Saddle", "harmony.midnightconfig.horseArmorPreventsBucking": "Horse armor decreases bucking chance on damage", "harmony.midnightconfig.horseArmorPreventsBucking.tooltip": "Horse armor has a chance from preventing the horse from bucking, depending of material: \n \n-Leather: 45% \n-Gold: 60% \n-Iron: 75% \n-Diamond: 90% \n-Netherite (Melody Integration): 100% ", + "harmony.midnightconfig.enderPearlsTeleportVehicles": "Ender Pearls teleport the entity the player is riding", + "harmony.midnightconfig.enderPearlsDamageVehicles": "Ender Pearls damage mounts when teleporting", + "harmony.midnightconfig.enderPearlsDamageVehicles.tooltip": "All entities teleported(passengers and mounts) using an Ender Pearl receive half of the damage the player normally would", "harmony.midnightconfig.riptideAccelerationOnWater": "Riptide acceleration on water", "harmony.midnightconfig.riptideCooldown": "Tridents with riptide have cooldown", "harmony.midnightconfig.riptideCooldown.tooltip": "Tridents with riptide cant be used until riptide animation has finished. \nThis prevents the player from accumulating acceleration when using the \"Riptide Acceleration on Water\" feature.", diff --git a/src/main/resources/harmony.mixins.json b/src/main/resources/harmony.mixins.json index 676d450..c22779d 100644 --- a/src/main/resources/harmony.mixins.json +++ b/src/main/resources/harmony.mixins.json @@ -23,6 +23,7 @@ "food.GlowBerryMixin", "transportation.ExitVehicleOnDamage", "transportation.HorseArmorPreventsBucking", + "transportation.EnderPearlsDontDismount", "transportation.elytra.LivingEntityMixin", "transportation.riptide.LivingEntityMixin", "transportation.riptide.TridentItemMixin"