Skip to content

Commit

Permalink
Significantly improve the experience of dying
Browse files Browse the repository at this point in the history
Dying in Aylyth no longer brings up the teleportation screen. We now just directly respawn the player in Aylyth, rather than teleport them back from an Overworld respawn. This is how it should have always been
  • Loading branch information
dhyces committed Apr 3, 2024
1 parent 8d4c817 commit 91b6977
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public abstract class InGameHudMixin implements AylythGameHud {
@Shadow
protected abstract void renderOverlay(DrawContext context, Identifier texture, float opacity);

@Shadow @Final private static Identifier ICONS;

@Shadow protected abstract void drawHeart(DrawContext context, InGameHud.HeartType type, int x, int y, int v, boolean blinking, boolean halfHeart);

@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;lerp(FFF)F", ordinal = 1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public static void init(){
ServerLivingEntityEvents.AFTER_DEATH.register(LivingEntityDeathEvents::checkVital);
ServerLivingEntityEvents.AFTER_DEATH.register(LivingEntityDeathEvents::spawnRippedSoul);

ServerPlayerEvents.AFTER_RESPAWN.register(LivingEntityDeathEvents::afterRespawn);
ServerPlayerEvents.AFTER_RESPAWN.register(LivingEntityDeathEvents::restoreInv);
}

Expand Down Expand Up @@ -138,12 +137,6 @@ private static void spawnRippedSoul(LivingEntity livingEntity, DamageSource sour
}
}

private static void afterRespawn(ServerPlayerEntity oldPlayer, ServerPlayerEntity newPlayer, boolean alive) {
if (oldPlayer.getWorld().getRegistryKey().equals(ModDimensionKeys.AYLYTH)) {
AylythUtil.teleportTo(ModDimensionKeys.AYLYTH, newPlayer, 0);
}
}

private static boolean allowDeath(LivingEntity livingEntity, DamageSource damageSource, float damageAmount) {
if(livingEntity instanceof ServerPlayerEntity player){
if (damageSource.isOf(DamageTypes.OUT_OF_WORLD)) {
Expand All @@ -164,8 +157,7 @@ private static boolean allowDeath(LivingEntity livingEntity, DamageSource damage
case HARD -> 0.3f;
};
// TODO: take another look at this later if people complain abt this not working with an advancement removal mod
Advancement netherRoot = player.server.getAdvancementLoader().get(new Identifier("nether/root"));
if (player.getRandom().nextFloat() <= chance && player.getAdvancementTracker().getProgress(netherRoot).isDone()) {
if (player.getRandom().nextFloat() <= chance && hasPlayerBeenToNether(player)) {
if (damageSource.getAttacker() instanceof WitchEntity) {
teleport = true;
}
Expand Down Expand Up @@ -209,4 +201,9 @@ private static boolean allowDeath(LivingEntity livingEntity, DamageSource damage
}
return true;
}

private static boolean hasPlayerBeenToNether(ServerPlayerEntity player) {
Advancement advancement = player.server.getAdvancementLoader().get(new Identifier("nether/root"));
return player.getAdvancementTracker().getProgress(advancement).isDone();
}
}
22 changes: 22 additions & 0 deletions src/main/java/moriyashiine/aylyth/mixin/PlayerManagerMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package moriyashiine.aylyth.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import moriyashiine.aylyth.common.registry.key.ModDimensionKeys;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(PlayerManager.class)
public class PlayerManagerMixin {

@ModifyVariable(method = "respawnPlayer", at = @At(value = "STORE"), ordinal = 1)
private ServerWorld respawnPlayerInAylyth(ServerWorld serverWorld, @Local(argsOnly = true) ServerPlayerEntity original) {
if (original.getWorld().getRegistryKey() == ModDimensionKeys.AYLYTH) {
return original.getServerWorld();
}
return serverWorld;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/aylyth.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
"EntityMixin",
"GeneratorOptionsMixin",
"LivingEntityMixin",
"MilkBucketItemMixin",
"MobEntityAccessor",
"NoiseChunkGeneratorMixin",
"PlayerEntityMixin",
"PlayerManagerMixin",
"SaplingBlockAccessor",
"ServerPlayerEntityMixin",
"VineBlockMixin",
"WorldMixin",
"MilkBucketItemMixin",
"cimmerian.MobEntityMixin",
"cimmerian.ZoglinEntityMixin"
],
Expand Down

0 comments on commit 91b6977

Please sign in to comment.