Skip to content

Commit

Permalink
Added some Thalassophobia stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
MysticKoko committed Feb 9, 2024
1 parent 3f4b1f0 commit 9d58ccc
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.hybridlabs.aquatic.fog;

import dev.hybridlabs.aquatic.effect.HybridAquaticStatusEffects;
import net.minecraft.client.render.BackgroundRenderer;
import net.minecraft.client.render.FogShape;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.util.math.MathHelper;

public class ThalassophobiaFogModifier implements BackgroundRenderer.StatusEffectFogModifier {
@Override
public StatusEffect getStatusEffect() {
return HybridAquaticStatusEffects.INSTANCE.getTHALASSOPHOBIA();
}

@Override
public void applyStartEndModifier(BackgroundRenderer.FogData fogData, LivingEntity entity, StatusEffectInstance effect, float viewDistance, float tickDelta) {

float fogDistanceMultiplier = 0.5f;

float f = effect.isInfinite() ? 5.0F : MathHelper.lerp(Math.min(1.0F, (float) effect.getDuration() / 20.0F), viewDistance, 5.0F);
fogData.fogStart = f * 2.0F * fogDistanceMultiplier;
fogData.fogEnd = f * 4.0F * fogDistanceMultiplier;
fogData.fogShape = FogShape.SPHERE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@

import dev.hybridlabs.aquatic.effect.HybridAquaticStatusEffects;
import dev.hybridlabs.aquatic.fog.ClarityFogModifier;
import dev.hybridlabs.aquatic.fog.ThalassophobiaFogModifier;
import dev.hybridlabs.aquatic.utils.MeasurementUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.BackgroundRenderer;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.CameraSubmersionType;
import net.minecraft.client.render.FogShape;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.BiomeTags;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -31,8 +30,12 @@
@Mixin(BackgroundRenderer.class)
public class BackgroundRendererMixin {

@Shadow private static float red, green, blue;
@Mutable @Final @Shadow private static List<BackgroundRenderer.StatusEffectFogModifier> FOG_MODIFIERS;
@Shadow
private static float red, green, blue;
@Mutable
@Final
@Shadow
private static List<BackgroundRenderer.StatusEffectFogModifier> FOG_MODIFIERS;


// @Inject(method = "render", at=@At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;clearColor(FFFF)V"), locals = LocalCapture.CAPTURE_FAILHARD)
Expand Down Expand Up @@ -77,14 +80,17 @@ public class BackgroundRendererMixin {
if (entity instanceof ClientPlayerEntity clientPlayerEntity) {
World world = clientPlayerEntity.getWorld();
StatusEffectInstance clarityEffect = clientPlayerEntity.getStatusEffect(HybridAquaticStatusEffects.INSTANCE.getCLARITY());
StatusEffectInstance thalassophobiaEffect = clientPlayerEntity.getStatusEffect(HybridAquaticStatusEffects.INSTANCE.getTHALASSOPHOBIA());

if (clarityEffect != null) {
new ClarityFogModifier().applyStartEndModifier(fogData, clientPlayerEntity, clarityEffect, viewDistance, tickDelta);
} else if (thalassophobiaEffect != null) {
new ThalassophobiaFogModifier().applyStartEndModifier(fogData, clientPlayerEntity, thalassophobiaEffect, viewDistance, tickDelta);
} else {

switch (cameraSubmersionType) {
case LAVA, POWDER_SNOW -> {
}
case WATER -> {
case WATER, NONE -> {
fogData.fogStart = -8.0F;
int topY = world.getSeaLevel();
float fogStep = (float) (topY - camera.getPos().y) / 32.0f;
Expand All @@ -101,16 +107,8 @@ public class BackgroundRendererMixin {
}
fogData.fogEnd = Math.max(fogData.fogEnd, 12.0f);
}
case NONE -> {
RegistryEntry<Biome> biomeEntry = world.getBiome(entity.getBlockPos());

if (biomeEntry.isIn(BiomeTags.IS_OCEAN) && (world.isRaining() || world.isNight())) {
fogData.fogStart = -0.8f;
fogData.fogEnd = MeasurementUtils.Block(16);
}
}
}
}
}
}
}
}
9 changes: 9 additions & 0 deletions src/generated/resources/assets/hybrid-aquatic/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"block.hybrid-aquatic.whale_shark_plushie": "Whale Shark Plushie",
"effect.hybrid-aquatic.bleeding": "Bleeding",
"effect.hybrid-aquatic.clarity": "Clarity",
"effect.hybrid-aquatic.thalassophobia": "Thalassophobia",
"enchantment.hybrid-aquatic.live_catch": "Live Catch",
"entity.hybrid-aquatic.anglerfish": "Anglerfish",
"entity.hybrid-aquatic.atolla_jellyfish": "Atolla Jellyfish",
Expand Down Expand Up @@ -252,9 +253,17 @@
"item.hybrid-aquatic.yeti_crab_claw": "Yeti Crab Claw",
"item.hybrid-aquatic.yeti_crab_spawn_egg": "Yeti Crab Spawn Egg",
"item.hybrid-aquatic.zebra_danio_spawn_egg": "Zebra Danio Spawn Egg",
"item.minecraft.lingering_potion.effect.clarity": "Lingering Potion of Clarity",
"item.minecraft.lingering_potion.effect.glowing": "Lingering Potion of Glowing",
"item.minecraft.lingering_potion.effect.thalassophobia": "Lingering Potion of Thalassophobia",
"item.minecraft.potion.effect.clarity": "Potion of Clarity",
"item.minecraft.potion.effect.glowing": "Potion of Glowing",
"item.minecraft.potion.effect.thalassophobia": "Potion of Thalassophobia",
"item.minecraft.splash_potion.effect.clarity": "Splash Potion of Clarity",
"item.minecraft.splash_potion.effect.glowing": "Splash Potion of Glowing",
"item.minecraft.splash_potion.effect.thalassophobia": "Splash Potion of Thalassophobia",
"item.minecraft.tipped_arrow.effect.clarity": "Arrow of Clarity",
"item.minecraft.tipped_arrow.effect.glowing": "Arrow of Glowing",
"item.minecraft.tipped_arrow.effect.thalassophobia": "Arrow of Thalassophobia",
"itemGroup.hybrid-aquatic": "Hybrid Aquatic"
}
18 changes: 18 additions & 0 deletions src/main/java/dev/hybridlabs/aquatic/mixin/PlayerEntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package dev.hybridlabs.aquatic.mixin;

import dev.hybridlabs.aquatic.access.CustomPlayerEntityData;
import dev.hybridlabs.aquatic.effect.HybridAquaticStatusEffects;
import dev.hybridlabs.aquatic.entity.shark.HybridAquaticSharkEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.TargetPredicate;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.tag.BiomeTags;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -58,4 +61,19 @@ private void setCustomHurtTimeOnDamage(DamageSource source, float amount, Callba
if (foundEntity != null) hybrid_aquatic$setHurtTime(200);
}
}
@Inject(method = "tick", at = @At("TAIL"))
private void tickDownCustomHurtTime(CallbackInfo ci) {
int cHurtTime = hybrid_aquatic$getHurtTime();
if (cHurtTime > 0) {
hybrid_aquatic$setHurtTime(cHurtTime - 1);
}

var player = (PlayerEntity)(Object)this;
var world = player.getWorld();
if(!world.isClient) {
if (world.getBiome(player.getBlockPos()).isIn(BiomeTags.IS_OCEAN) && world.isNight() && player.isSubmergedInWater()) {
player.addStatusEffect(new StatusEffectInstance(HybridAquaticStatusEffects.INSTANCE.getTHALASSOPHOBIA(), 100, 0, true, false));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class LanguageProvider(output: FabricDataOutput) : FabricLanguageProvider(output
mapOf(
HybridAquaticStatusEffects.BLEEDING to "Bleeding",
HybridAquaticStatusEffects.CLARITY to "Clarity",
HybridAquaticStatusEffects.THALASSOPHOBIA to "Thalassophobia",
).forEach { (effect, translation) ->
val identifier = Registries.STATUS_EFFECT.getId(effect)
builder.add("effect.${identifier?.namespace}.${identifier?.path}", translation)
Expand All @@ -162,7 +163,9 @@ class LanguageProvider(output: FabricDataOutput) : FabricLanguageProvider(output
}

mapOf(
"glowing" to "Glowing"
"glowing" to "Glowing",
"clarity" to "Clarity",
"thalassophobia" to "Thalassophobia"
).forEach { (potion, translation) ->
builder.add("item.minecraft.potion.effect.$potion", "Potion of $translation")
builder.add("item.minecraft.splash_potion.effect.$potion", "Splash Potion of $translation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import net.minecraft.util.Identifier
object HybridAquaticStatusEffects {
val BLEEDING = register("bleeding", Bleeding())
val CLARITY = register("clarity", Clarity())
val THALASSOPHOBIA = register("thalassophobia", Thalassophobia())
private fun register(id: String, effect: StatusEffect): StatusEffect {
return Registry.register(Registries.STATUS_EFFECT, Identifier(HybridAquatic.MOD_ID, id), effect)
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/dev/hybridlabs/aquatic/effect/Thalassophobia.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.hybridlabs.aquatic.effect

import net.minecraft.entity.effect.StatusEffect
import net.minecraft.entity.effect.StatusEffectCategory

class Thalassophobia : StatusEffect(StatusEffectCategory.HARMFUL, 0x606060) {

override fun canApplyUpdateEffect(duration: Int, amplifier: Int): Boolean {
return duration % 40 == 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ object HybridAquaticPotions {
Potions.AWKWARD,
HybridAquaticItems.GLOW_SLIME
)

val CLARITY_POTION = registerPotionWithRecipe(
"clarity",
Potion(StatusEffectInstance(HybridAquaticStatusEffects.CLARITY, 3600, 0)),
Potions.AWKWARD,
HybridAquaticItems.PEARL
)

val THALASSOPHOBIA_POTION = registerPotionWithRecipe(
"thalassophobia",
Potion(StatusEffectInstance(HybridAquaticStatusEffects.THALASSOPHOBIA, 3600, 0)),
Potions.AWKWARD,
HybridAquaticItems.BLACK_PEARL
)

private fun registerPotionWithRecipe(id: String, potion: Potion, inputPotion: Potion, ingredient: Item): Potion {
BrewingRecipeRegistry.registerPotionRecipe(inputPotion, ingredient, potion)
return register(id, potion)
Expand Down

0 comments on commit 9d58ccc

Please sign in to comment.