The sun will now burn bat ponies' eyes when they go outside

This commit is contained in:
Sollace 2021-08-08 16:51:12 +02:00
parent 96b65a5b1b
commit b11bd928ae
11 changed files with 296 additions and 92 deletions

View file

@ -1,5 +0,0 @@
package com.minelittlepony.unicopia;
public interface SidedAccess {
Race getObservingPlayerRace();
}

View file

@ -12,6 +12,8 @@ public interface USounds {
SoundEvent ENTITY_PLAYER_PEGASUS_WINGSFLAP = register("entity.player.pegasus.wingsflap");
SoundEvent ENTITY_PLAYER_CHANGELING_BUZZ = register("entity.player.changeling.buzz");
SoundEvent ENTITY_PLAYER_EARS_RINGING = register("entity.player.ears_ring");
SoundEvent ITEM_MAGIC_AURA = register("item.magic.aura");
SoundEvent RECORD_CRUSADE = register("record.crusade");

View file

@ -12,6 +12,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell;
import com.minelittlepony.unicopia.ability.magic.spell.SpellType;
import com.minelittlepony.unicopia.client.KeyBindingsHandler;
import com.minelittlepony.unicopia.entity.behaviour.Disguise;
import com.minelittlepony.unicopia.entity.effect.SunBlindnessStatusEffect;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.mojang.blaze3d.systems.RenderSystem;
@ -26,7 +27,9 @@ import net.minecraft.text.Text;
import net.minecraft.util.Arm;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Quaternion;
import net.minecraft.util.math.Vec3f;
public class UHud extends DrawableHelper {
@ -54,25 +57,52 @@ public class UHud extends DrawableHelper {
public void render(InGameHud hud, MatrixStack matrices, float tickDelta) {
if (client.currentScreen instanceof HidesHud) {
if (client.player == null) {
return;
}
if (client.player == null || client.player.isSpectator() || client.options.hudHidden) {
return;
}
font = client.textRenderer;
xDirection = client.player.getMainArm() == Arm.LEFT ? -1 : 1;
int scaledWidth = client.getWindow().getScaledWidth();
int scaledHeight = client.getWindow().getScaledHeight();
Pony pony = Pony.of(client.player);
boolean hasEffect = client.player.hasStatusEffect(SunBlindnessStatusEffect.INSTANCE);
if (hasEffect || (pony.getSpecies() == Race.BAT && SunBlindnessStatusEffect.hasSunExposure(client.player))) {
float i = hasEffect ? (client.player.getStatusEffect(SunBlindnessStatusEffect.INSTANCE).getDuration() - tickDelta) / SunBlindnessStatusEffect.MAX_DURATION : 0;
float pulse = (1 + (float)Math.sin(client.player.age / 108F)) * 0.25F;
float strength = MathHelper.clamp(pulse + i, 0.3F, 1F);
int alpha1 = (int)(strength * 205) << 24 & -16777216;
int alpha2 = (int)(alpha1 * 0.6F);
fillGradient(matrices, 0, 0, scaledWidth, scaledHeight / 2, 0xFFFFFF | alpha1, 0xFFFFFF | alpha2);
fillGradient(matrices, 0, scaledHeight / 2, scaledWidth, scaledHeight, 0xFFFFFF | alpha2, 0xFFFFFF | alpha1);
if (hasEffect) {
matrices.push();
matrices.translate(scaledWidth, 0, 0);
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(90));
fillGradient(matrices, 0, 0, scaledHeight, scaledWidth / 2, 0xFFFFFF | 0, 0xFFFFFF | alpha2);
fillGradient(matrices, 0, scaledWidth / 2, scaledHeight, scaledWidth, 0xFFFFFF | alpha2, 0xFFFFFF | 0);
matrices.pop();
}
}
if (client.currentScreen instanceof HidesHud || client.player.isSpectator() || client.options.hudHidden) {
return;
}
font = client.textRenderer;
xDirection = client.player.getMainArm() == Arm.LEFT ? -1 : 1;
matrices.push();
matrices.translate(((scaledWidth - 50) / 2) + (104 * xDirection), scaledHeight - 50, 0);
Pony pony = Pony.of(client.player);
AbilityDispatcher abilities = pony.getAbilities();
if (message != null && messageTime > 0) {

View file

@ -0,0 +1,76 @@
package com.minelittlepony.unicopia.client.sound;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.MovingSoundInstance;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.MathHelper;
public abstract class FadeOutSoundInstance extends MovingSoundInstance {
protected int transitionTicks = 10;
private float sourceVolume;
protected float targetVolume;
private int prevProgress;
private int progress;
private boolean fadingOut;
public FadeOutSoundInstance(SoundEvent sound, SoundCategory category, float volume) {
super(sound, category);
this.looping = true;
this.repeat = true;
this.volume = volume;
setTargetVolume(volume);
}
@Override
public boolean shouldAlwaysPlay() {
return true;
}
@Override
public final void tick() {
setFadingOut(!shouldKeepPlaying());
prevProgress = progress;
if (progress < transitionTicks) {
progress++;
}
if (fadingOut && getVolume() < 0.001F) {
setDone();
}
}
private void setFadingOut(boolean fadingOut) {
if (fadingOut == this.fadingOut) {
return;
}
this.fadingOut = fadingOut;
setTargetVolume(fadingOut ? 0 : volume);
}
protected abstract boolean shouldKeepPlaying();
protected void setTargetVolume(float target) {
sourceVolume = getLerpedVolume();
targetVolume = target;
progress = 0;
}
private float getLerpedVolume() {
float delta = MinecraftClient.getInstance().getTickDelta();
float interpolate = MathHelper.clamp(MathHelper.lerp(delta, prevProgress, progress) / transitionTicks, 0, 1);
return MathHelper.lerp(interpolate, sourceVolume, targetVolume);
}
@Override
public final float getVolume() {
return getLerpedVolume() * sound.getVolume();
}
}

View file

@ -0,0 +1,35 @@
package com.minelittlepony.unicopia.client.sound;
import java.util.function.Predicate;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.entity.Entity;
import net.minecraft.sound.SoundEvent;
public class LoopingSoundInstance<T extends Entity> extends FadeOutSoundInstance {
private final T source;
private final Predicate<T> shouldPlay;
public LoopingSoundInstance(T source, Predicate<T> shouldPlay, SoundEvent soundEvent, float volume, float pitch) {
super(soundEvent, source.getSoundCategory(), volume);
this.source = source;
this.shouldPlay = shouldPlay;
this.pitch = pitch;
this.attenuationType = SoundInstance.AttenuationType.NONE;
}
@Override
protected boolean shouldKeepPlaying() {
if (source.isRemoved() || !shouldPlay.test(source)) {
return false;
}
x = source.getX();
y = source.getY();
z = source.getZ();
return true;
}
}

View file

@ -7,37 +7,20 @@ import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.item.enchantment.SimpleEnchantment;
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
import net.minecraft.client.sound.MovingSoundInstance;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
public class MagicAuraSoundInstance extends MovingSoundInstance {
public class MagicAuraSoundInstance extends FadeOutSoundInstance {
private final Living<?> living;
private float sourceVolume;
private float targetVolume;
private float interpolate;
private boolean fadingOut;
public MagicAuraSoundInstance(SoundCategory category, Living<?> living) {
super(USounds.ITEM_MAGIC_AURA, category);
this.looping = true;
this.repeat = true;
super(USounds.ITEM_MAGIC_AURA, category, 1);
this.living = living;
this.volume = 0;
setTargetVolume(1);
}
@Override
public boolean shouldAlwaysPlay() {
return true;
}
@Override
public void tick() {
protected boolean shouldKeepPlaying() {
Optional<SimpleEnchantment.Data> data = living.getEnchants().getOrEmpty(UEnchantments.GEM_FINDER);
Vec3d pos = living.getOriginVector();
@ -50,24 +33,9 @@ public class MagicAuraSoundInstance extends MovingSoundInstance {
if (level != targetVolume) {
setTargetVolume(level);
}
} else {
fadingOut = true;
setTargetVolume(0);
return true;
}
if (interpolate < 1) {
interpolate = Math.min(interpolate + 0.4F, 1);
volume = MathHelper.lerp(interpolate, sourceVolume, targetVolume);
}
if (fadingOut && volume < 0.01F) {
setDone();
}
}
private void setTargetVolume(float target) {
sourceVolume = volume;
targetVolume = target;
interpolate = 0;
return false;
}
}

View file

@ -0,0 +1,62 @@
package com.minelittlepony.unicopia.entity.effect;
import org.jetbrains.annotations.Nullable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffectType;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.LightType;
public class SunBlindnessStatusEffect extends StatusEffect {
public static final int MAX_DURATION = 50;
public static final SunBlindnessStatusEffect INSTANCE = new SunBlindnessStatusEffect(0x886F0F);
private SunBlindnessStatusEffect(int color) {
super(StatusEffectType.NEUTRAL, color);
Registry.register(Registry.STATUS_EFFECT, new Identifier("unicopia", "sun_blindness"), this);
}
@Override
public void applyUpdateEffect(LivingEntity entity, int amplifier) {
StatusEffectInstance state = entity.getStatusEffect(this);
if (state == null) {
return;
}
if (!hasSunExposure(entity)) {
entity.setStatusEffect(new StatusEffectInstance(this, (int)(state.getDuration() * 0.8F), amplifier, true, false), entity);
} else {
if (entity.age % 15 == 0) {
entity.damage(DamageSource.IN_FIRE, amplifier / 20F);
}
}
}
@Override
public void applyInstantEffect(@Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) {
applyUpdateEffect(target, amplifier);
}
@Override
public boolean canApplyUpdateEffect(int duration, int amplifier) {
return duration > 0;
}
public static boolean hasSunExposure(LivingEntity entity) {
if (entity.world.isClient) {
entity.world.calculateAmbientDarkness();
}
int light = entity.world.getLightLevel(LightType.SKY, entity.getBlockPos());
return !(entity.isSubmergedInWater() || light < 12 || entity.world.isRaining() || entity.world.isThundering() || !entity.world.isDay());
}
}

View file

@ -1,5 +1,6 @@
package com.minelittlepony.unicopia.entity.effect;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.potion.Potion;
import net.minecraft.util.Identifier;
@ -22,5 +23,8 @@ public interface UPotions {
return Registry.register(Registry.POTION, new Identifier("unicopia", name), potion);
}
static void bootstrap() {}
static void bootstrap() {
@SuppressWarnings("unused")
StatusEffect e = SunBlindnessStatusEffect.INSTANCE;
}
}

View file

@ -9,8 +9,10 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.Affinity;
import com.minelittlepony.unicopia.client.UnicopiaClient;
import com.minelittlepony.unicopia.client.sound.LoopingSoundInstance;
import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.WorldTribeManager;
import com.minelittlepony.unicopia.ability.AbilityDispatcher;
import com.minelittlepony.unicopia.ability.magic.Spell;
@ -19,6 +21,7 @@ import com.minelittlepony.unicopia.entity.Physics;
import com.minelittlepony.unicopia.entity.PonyContainer;
import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.Trap;
import com.minelittlepony.unicopia.entity.effect.SunBlindnessStatusEffect;
import com.minelittlepony.unicopia.item.toxin.FoodType;
import com.minelittlepony.unicopia.item.toxin.Toxicity;
import com.minelittlepony.unicopia.item.toxin.Toxin;
@ -36,12 +39,14 @@ import com.minelittlepony.common.util.animation.Interpolator;
import com.mojang.authlib.GameProfile;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
@ -88,6 +93,8 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
private boolean invisible = false;
private int ticksInSun;
public Pony(PlayerEntity player) {
super(player, EFFECT);
this.mana = new ManaContainer(this);
@ -116,7 +123,7 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
public void setSpecies(Race race) {
race = race.validate(entity);
speciesSet = true;
ticksInSun = 0;
entity.getDataTracker().set(RACE, race.ordinal());
gravity.updateFlightState();
@ -276,6 +283,24 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
ticksHanging = 0;
}
if (getSpecies() == Race.BAT) {
if (SunBlindnessStatusEffect.hasSunExposure(entity)) {
if (ticksInSun < 200) {
ticksInSun++;
}
if (ticksInSun == 1) {
entity.addStatusEffect(new StatusEffectInstance(SunBlindnessStatusEffect.INSTANCE, SunBlindnessStatusEffect.MAX_DURATION * 10, 1, true, false));
if (isClient()) {
MinecraftClient.getInstance().getSoundManager().play(new LoopingSoundInstance<>(entity, e -> e.hasStatusEffect(SunBlindnessStatusEffect.INSTANCE), USounds.ENTITY_PLAYER_EARS_RINGING, 1F, 1F));
}
}
} else if (ticksInSun > 0) {
ticksInSun--;
}
}
tickers.forEach(Tickable::tick);
super.tick();

View file

@ -10,31 +10,31 @@
]
},
"item.magic.aura": {
"category": "player",
"sounds": [
"unicopia:aura/aura0"
]
"category": "player",
"sounds": [
"unicopia:aura/aura0"
]
},
"entity.player.rebound": {
"category": "player",
"sounds": [
"unicopia:boing/boing0",
"unicopia:boing/boing1",
"unicopia:boing/boing2",
"unicopia:boing/boing3",
"unicopia:boing/boing4",
"unicopia:boing/boing5"
]
"category": "player",
"sounds": [
"unicopia:boing/boing0",
"unicopia:boing/boing1",
"unicopia:boing/boing2",
"unicopia:boing/boing3",
"unicopia:boing/boing4",
"unicopia:boing/boing5"
]
},
"entity.player.batpony.screech": {
"category": "player",
"subtitle": "unicopia.subtitle.batpony_eeee",
"sounds": [
"unicopia:batpony/reep",
"unicopia:batpony/eeep",
"unicopia:batpony/screep0",
"unicopia:batpony/screep1"
]
"category": "player",
"subtitle": "unicopia.subtitle.batpony_eeee",
"sounds": [
"unicopia:batpony/reep",
"unicopia:batpony/eeep",
"unicopia:batpony/screep0",
"unicopia:batpony/screep1"
]
},
"entity.player.changeling.buzz": {
"category": "player",
@ -45,6 +45,13 @@
"unicopia:cicada/cicada_6"
]
},
"entity.player.ears_ring": {
"category": "ambient",
"subtitle": "unicopia.subtitle.ears_ringing",
"sounds": [
"unicopia:ears/ringing"
]
},
"ambient.wind.gust": {
"category": "ambient",
"subtitle": "unicopia.subtitle.wind_rush",
@ -54,28 +61,28 @@
]
},
"record.crusade": {
"category": "blocks",
"sounds": [
{ "name": "unicopia:record/crusade", "stream": true}
]
"category": "blocks",
"sounds": [
{ "name": "unicopia:record/crusade", "stream": true}
]
},
"record.popular": {
"category": "blocks",
"sounds": [
{ "name": "unicopia:record/popular", "stream": true}
]
"category": "blocks",
"sounds": [
{ "name": "unicopia:record/popular", "stream": true}
]
},
"record.pet": {
"category": "blocks",
"stream": true,
"sounds": [
{ "name": "unicopia:record/pet", "stream": true}
]
"category": "blocks",
"stream": true,
"sounds": [
{ "name": "unicopia:record/pet", "stream": true}
]
},
"record.funk": {
"category": "blocks",
"sounds": [
{ "name": "unicopia:record/funk", "stream": true, "attenuation_distance": 21120}
]
"category": "blocks",
"sounds": [
{ "name": "unicopia:record/funk", "stream": true, "attenuation_distance": 21120}
]
}
}