Skip to content
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

Allowed Ender Pearls to teleport all riders and passengers #59

Merged
merged 2 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/dev/symphony/harmony/config/HarmonyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ServerPlayerEntity> 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<Boolean> 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<Void> original){if(!HarmonyConfig.enderPearlsTeleportVehicles) {original.call(instance);}}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/harmony/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/harmony.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"food.GlowBerryMixin",
"transportation.ExitVehicleOnDamage",
"transportation.HorseArmorPreventsBucking",
"transportation.EnderPearlsDontDismount",
"transportation.elytra.LivingEntityMixin",
"transportation.riptide.LivingEntityMixin",
"transportation.riptide.TridentItemMixin"
Expand Down