Revert blindness

This commit is contained in:
2025-11-15 16:02:45 +01:00
parent 6fb361e9a6
commit 99be5edf3e
6 changed files with 3 additions and 104 deletions
@@ -4,5 +4,4 @@ public class ClientData {
public static float SANITY = 80f; public static float SANITY = 80f;
public static float INSANITY = 0f; public static float INSANITY = 0f;
public static int TEMPO = 0; public static int TEMPO = 0;
public static boolean IDENTITY_BLIND = false;
} }
@@ -1,29 +0,0 @@
package net.fretux.mindmotion.client;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber(modid = "mindmotion", value = Dist.CLIENT)
public class IdentityBlindnessFaceHider {
@SubscribeEvent
public static void hideFaces(RenderLivingEvent.Pre<?, ?> event) {
if (!ClientData.IDENTITY_BLIND) return;
if (event.getRenderer().getModel() instanceof HumanoidModel<?> model) {
model.head.visible = false;
model.hat.visible = false;
}
}
@SubscribeEvent
public static void restoreFaces(RenderLivingEvent.Post<?, ?> event) {
if (event.getRenderer().getModel() instanceof HumanoidModel<?> model) {
model.head.visible = true;
model.hat.visible = true;
}
}
}
@@ -1,17 +0,0 @@
package net.fretux.mindmotion.client;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderNameTagEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber(modid = "mindmotion", value = Dist.CLIENT)
public class IdentityBlindnessRenderer {
@SubscribeEvent
public static void hideNameTags(RenderNameTagEvent event) {
if (ClientData.IDENTITY_BLIND) {
event.setResult(RenderNameTagEvent.Result.DENY);
}
}
}
@@ -1,7 +1,6 @@
package net.fretux.mindmotion.event; package net.fretux.mindmotion.event;
import net.fretux.mindmotion.network.ModMessages; import net.fretux.mindmotion.network.ModMessages;
import net.fretux.mindmotion.network.SyncIdentityBlindS2CPacket;
import net.fretux.mindmotion.network.SyncStatsS2CPacket; import net.fretux.mindmotion.network.SyncStatsS2CPacket;
import net.fretux.mindmotion.player.PlayerCapabilityProvider; import net.fretux.mindmotion.player.PlayerCapabilityProvider;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
@@ -12,7 +11,6 @@ import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.network.NetworkDirection;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@@ -25,15 +23,12 @@ public class PlayerTickHandler {
private static final int TEMPO_TICK_INTERVAL = 15; private static final int TEMPO_TICK_INTERVAL = 15;
private static final int COMBAT_DECAY_DELAY = 100; private static final int COMBAT_DECAY_DELAY = 100;
private static final Map<UUID, Integer> lastCombatTick = new ConcurrentHashMap<>(); private static final Map<UUID, Integer> lastCombatTick = new ConcurrentHashMap<>();
private static final Map<UUID, Integer> identityBlindUntil = new ConcurrentHashMap<>();
private static final int IDENTITY_BLIND_DURATION = 30 * 20;
@SubscribeEvent @SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event) { public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
if (event.phase != TickEvent.Phase.END) return; if (event.phase != TickEvent.Phase.END) return;
Player player = event.player; Player player = event.player;
if (player.level().isClientSide) return; if (player.level().isClientSide) return;
boolean blindActive = identityBlindUntil.getOrDefault(player.getUUID(), 0) > player.tickCount;
int tick = player.tickCount; int tick = player.tickCount;
boolean sanityTick = tick % SANITY_TICK_INTERVAL == 0; boolean sanityTick = tick % SANITY_TICK_INTERVAL == 0;
boolean tempoTick = tick % TEMPO_TICK_INTERVAL == 0; boolean tempoTick = tick % TEMPO_TICK_INTERVAL == 0;
@@ -56,13 +51,6 @@ public class PlayerTickHandler {
) )
); );
} }
if (player instanceof ServerPlayer serverPlayer && (sanityTick || tempoTick)) {
ModMessages.CHANNEL.sendTo(
new SyncIdentityBlindS2CPacket(blindActive),
serverPlayer.connection.connection,
NetworkDirection.PLAY_TO_CLIENT
);
}
} }
private static void handleSanityAndInsanity(Player player) { private static void handleSanityAndInsanity(Player player) {
@@ -101,13 +89,13 @@ public class PlayerTickHandler {
sanity.setInsanity(Math.max(0, insanity - 0.15f)); sanity.setInsanity(Math.max(0, insanity - 0.15f));
} }
float percent = (value / sanity.getMaxSanity()) * 100f; float percent = (value / sanity.getMaxSanity()) * 100f;
if (percent <= 70 && percent > 50 && Math.random() < 0.03) { if (percent <= 70 && Math.random() < 0.03) {
applyShiver(player); applyShiver(player);
} }
if (percent <= 30 && percent > 10 && Math.random() < 0.015) { if (percent <= 50 && Math.random() < 0.015) {
applyPanic(player); applyPanic(player);
} }
if (percent <= 10 && percent > 0 && Math.random() < 0.02) { if (percent <= 10 && Math.random() < 0.02) {
applyScratching(player); applyScratching(player);
} }
float insanityPercent = (insanity / sanity.getMaxSanity()) * 100f; float insanityPercent = (insanity / sanity.getMaxSanity()) * 100f;
@@ -138,10 +126,6 @@ public class PlayerTickHandler {
lastCombatTick.put(player.getUUID(), player.tickCount); lastCombatTick.put(player.getUUID(), player.tickCount);
} }
public static void triggerIdentityBlindness(Player player) {
identityBlindUntil.put(player.getUUID(), player.tickCount + IDENTITY_BLIND_DURATION);
}
private static void applyShiver(Player player) { private static void applyShiver(Player player) {
player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 40, 0)); player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 40, 0));
} }
@@ -150,13 +134,11 @@ public class PlayerTickHandler {
player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 20, 1)); player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 20, 1));
player.hurt(player.damageSources().magic(), 1f); player.hurt(player.damageSources().magic(), 1f);
applyShiver(player); applyShiver(player);
triggerIdentityBlindness(player);
} }
private static void applyScratching(Player player) { private static void applyScratching(Player player) {
player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 30, 1)); player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 30, 1));
player.hurt(player.damageSources().magic(), 2f); player.hurt(player.damageSources().magic(), 2f);
applyShiver(player); applyShiver(player);
triggerIdentityBlindness(player);
} }
} }
@@ -26,10 +26,5 @@ public class ModMessages {
.decoder(SyncStatsS2CPacket::decode) .decoder(SyncStatsS2CPacket::decode)
.consumerMainThread(SyncStatsS2CPacket::handle) .consumerMainThread(SyncStatsS2CPacket::handle)
.add(); .add();
CHANNEL.messageBuilder(SyncIdentityBlindS2CPacket.class, nextId(), NetworkDirection.PLAY_TO_CLIENT)
.encoder(SyncIdentityBlindS2CPacket::encode)
.decoder(SyncIdentityBlindS2CPacket::decode)
.consumerMainThread(SyncIdentityBlindS2CPacket::handle)
.add();
} }
} }
@@ -1,31 +0,0 @@
package net.fretux.mindmotion.network;
import net.fretux.mindmotion.client.ClientData;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;
import java.util.function.Supplier;
public class SyncIdentityBlindS2CPacket {
private final boolean blind;
public SyncIdentityBlindS2CPacket(boolean blind) {
this.blind = blind;
}
public static void encode(SyncIdentityBlindS2CPacket msg, FriendlyByteBuf buf) {
buf.writeBoolean(msg.blind);
}
public static SyncIdentityBlindS2CPacket decode(FriendlyByteBuf buf) {
return new SyncIdentityBlindS2CPacket(buf.readBoolean());
}
public static void handle(SyncIdentityBlindS2CPacket msg, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
ClientData.IDENTITY_BLIND = msg.blind;
});
ctx.get().setPacketHandled(true);
}
}