Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Jun 17, 2024
1 parent 0965f6e commit 49ce2e1
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = true

# Mod Properties
mod_version = 0.1.2
mod_version = 0.1.3
maven_group = ru.pinkgoosik
archives_base_name = dimensional-revive

Expand Down
24 changes: 17 additions & 7 deletions src/main/java/ru/pinkgoosik/dimrevive/DimensionalRevive.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.fabricmc.fabric.api.entity.event.v1.ServerEntityWorldChangeEvents;
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.registry.RegistryKey;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
Expand All @@ -15,6 +17,7 @@
import org.apache.commons.lang3.text.WordUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.pinkgoosik.dimrevive.extension.PlayerExtension;
import ru.pinkgoosik.dimrevive.extension.WorldExtension;

public class DimensionalRevive implements ModInitializer {
Expand All @@ -24,24 +27,31 @@ public class DimensionalRevive implements ModInitializer {
@Override
public void onInitialize() {

ServerLivingEntityEvents.ALLOW_DEATH.register((entity, damageSource, damageAmount) -> {
if(entity instanceof ServerPlayerEntity player && player instanceof PlayerExtension ex && player.getServer().isHardcore() && !player.isSpectator()) {
ex.onSilentDeath(damageSource);
return false;
}
return true;
});

ServerEntityWorldChangeEvents.AFTER_PLAYER_CHANGE_WORLD.register((player, origin, destination) -> {
var visitedDimensions = ((WorldExtension)player.getServer().getOverworld()).getVisitedDimensions().visitedDimensions;
var visitedDimensions = ((WorldExtension)player.getServer().getOverworld()).getVisitedDimensions();

if(!player.isSpectator() && player.getServer().isHardcore() && !destination.getRegistryKey().equals(World.OVERWORLD) && !visitedDimensions.contains(destination.getRegistryKey().getValue().toString())) {
if(!player.isSpectator() && player.getServer().isHardcore() && !destination.getRegistryKey().equals(World.OVERWORLD) && !visitedDimensions.wasVisited(destination.getRegistryKey())) {

player.getServer().getPlayerManager().broadcast(Text.literal("New dimension was discovered: §6" + formatDimensionName(destination.getRegistryKey()) + "§f. All players are revived."), false);
visitedDimensions.add(destination.getRegistryKey().getValue().toString());
((WorldExtension)player.getServer().getOverworld()).getVisitedDimensions().setDirty(true);
visitedDimensions.addDimension(destination.getRegistryKey());

player.getServer().getPlayerManager().getPlayerList().forEach(serverPlayerEntity -> {
if(serverPlayerEntity.isSpectator()) {
FabricDimensions.teleport(serverPlayerEntity, destination, new TeleportTarget(player.getPos(), new Vec3d(0, 0, 0), player.getYaw(), player.getPitch()));
serverPlayerEntity.changeGameMode(GameMode.SURVIVAL);
serverPlayerEntity.setPortalCooldown(20 * 5);

serverPlayerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 5, 5, false, true));
serverPlayerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.SATURATION, 5, 5, false, true));
serverPlayerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.RESISTANCE, 5, 255, false, true));
serverPlayerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 10, 5, false, true));
serverPlayerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.SATURATION, 10, 5, false, true));
serverPlayerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.RESISTANCE, 10, 255, false, true));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package ru.pinkgoosik.dimrevive;
package ru.pinkgoosik.dimrevive.data;

import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryKey;
import net.minecraft.world.PersistentState;
import net.minecraft.world.World;

import java.util.ArrayList;

Expand Down Expand Up @@ -30,4 +32,14 @@ public static VisitedDimensionsState fromNbt(NbtCompound nbt) {

return manager;
}


public boolean wasVisited(RegistryKey<World> key) {
this.setDirty(true);
return visitedDimensions.contains(key.getValue().toString());
}

public void addDimension(RegistryKey<World> key) {
this.visitedDimensions.add(key.getValue().toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ru.pinkgoosik.dimrevive.extension;

import net.minecraft.entity.damage.DamageSource;

public interface PlayerExtension {

void onSilentDeath(DamageSource source);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ru.pinkgoosik.dimrevive.extension;

import ru.pinkgoosik.dimrevive.VisitedDimensionsState;
import ru.pinkgoosik.dimrevive.data.VisitedDimensionsState;

public interface WorldExtension {

Expand Down
82 changes: 82 additions & 0 deletions src/main/java/ru/pinkgoosik/dimrevive/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package ru.pinkgoosik.dimrevive.mixin;

import com.mojang.authlib.GameProfile;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.scoreboard.ScoreboardCriterion;
import net.minecraft.scoreboard.ScoreboardPlayerScore;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.GlobalPos;
import net.minecraft.world.GameMode;
import net.minecraft.world.GameRules;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import ru.pinkgoosik.dimrevive.extension.PlayerExtension;

import java.util.Optional;

@Mixin(ServerPlayerEntity.class)
public abstract class PlayerMixin extends PlayerEntity implements PlayerExtension {

@Shadow
@Final
public MinecraftServer server;

@Shadow
protected abstract void forgiveMobAnger();

@Shadow
public abstract boolean changeGameMode(GameMode gameMode);

public PlayerMixin(World world, BlockPos pos, float yaw, GameProfile gameProfile) {
super(world, pos, yaw, gameProfile);
}

@Override
public void onSilentDeath(DamageSource source) {
this.setHealth(this.getMaxHealth());
this.emitGameEvent(GameEvent.ENTITY_DIE);
boolean bl = this.getWorld().getGameRules().getBoolean(GameRules.SHOW_DEATH_MESSAGES);
if (bl) {
Text text = this.getDamageTracker().getDeathMessage();
server.getPlayerManager().broadcast(text, false);
}

this.dropShoulderEntities();
if (this.getWorld().getGameRules().getBoolean(GameRules.FORGIVE_DEAD_PLAYERS)) {
forgiveMobAnger();
}

if (!this.isSpectator()) {
this.drop(source);
}

this.getScoreboard().forEachScore(ScoreboardCriterion.DEATH_COUNT, this.getEntityName(), ScoreboardPlayerScore::incrementScore);
LivingEntity livingEntity = this.getPrimeAdversary();
if (livingEntity != null) {
this.incrementStat(Stats.KILLED_BY.getOrCreateStat(livingEntity.getType()));
livingEntity.updateKilledAdvancementCriterion(this, this.scoreAmount, source);
this.onKilledBy(livingEntity);
}

this.getWorld().sendEntityStatus(this, (byte)3);
this.incrementStat(Stats.DEATHS);
this.resetStat(Stats.CUSTOM.getOrCreateStat(Stats.TIME_SINCE_DEATH));
this.resetStat(Stats.CUSTOM.getOrCreateStat(Stats.TIME_SINCE_REST));
this.extinguish();
this.setFrozenTicks(0);
this.setOnFire(false);
this.getDamageTracker().update();
this.setLastDeathPos(Optional.of(GlobalPos.create(this.getWorld().getRegistryKey(), this.getBlockPos())));
this.changeGameMode(GameMode.SPECTATOR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.pinkgoosik.dimrevive.VisitedDimensionsState;
import ru.pinkgoosik.dimrevive.data.VisitedDimensionsState;
import ru.pinkgoosik.dimrevive.extension.WorldExtension;

import java.util.List;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/dimrevive.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"package": "ru.pinkgoosik.dimrevive.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"PlayerMixin",
"WorldMixin"
],
"client": [
Expand Down

0 comments on commit 49ce2e1

Please sign in to comment.