Skip to content

Commit

Permalink
fix #176
Browse files Browse the repository at this point in the history
  • Loading branch information
MoriyaShiine committed Apr 19, 2024
1 parent 4971ed1 commit cfa9d70
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import moriyashiine.enchancement.common.init.ModEnchantments;
import moriyashiine.enchancement.common.packet.BuoyPacket;
import moriyashiine.enchancement.common.util.EnchancementUtil;
import moriyashiine.enchancement.common.util.SubmersionGate;
import moriyashiine.enchancement.mixin.util.LivingEntityAccessor;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.PlayerEntity;
Expand Down Expand Up @@ -46,7 +47,7 @@ public void tick() {
hasBuoy = buoyLevel > 0;
if (hasBuoy) {
if (shouldBoost) {
if (EnchancementUtil.isSubmerged(obj, true, true, true) && EnchancementUtil.isGroundedOrAirborne(obj, true)) {
if (EnchancementUtil.isSubmerged(obj, SubmersionGate.ALL) && EnchancementUtil.isGroundedOrAirborne(obj, true)) {
boost = (float) MathHelper.clamp(boost + 0.0025, buoyLevel * 0.075, buoyLevel);
obj.addVelocity(0, boost, 0);
} else {
Expand All @@ -71,11 +72,11 @@ public void clientTick() {
double y = obj.getY();
double z = obj.getZ();
ParticleEffect bubbleColumn = ParticleTypes.BUBBLE_COLUMN_UP, splash = ParticleTypes.SPLASH, bubble = ParticleTypes.BUBBLE;
if (EnchancementUtil.isSubmerged(obj, false, true, false)) {
if (EnchancementUtil.isSubmerged(obj, SubmersionGate.LAVA_ONLY)) {
bubbleColumn = ParticleTypes.LAVA;
splash = ParticleTypes.LAVA;
bubble = ParticleTypes.LAVA;
} else if (EnchancementUtil.isSubmerged(obj, false, false, true)) {
} else if (EnchancementUtil.isSubmerged(obj, SubmersionGate.POWDER_SNOW_ONLY)) {
bubbleColumn = ParticleTypes.SNOWFLAKE;
splash = ParticleTypes.SNOWFLAKE;
bubble = ParticleTypes.SNOWFLAKE;
Expand Down Expand Up @@ -110,6 +111,6 @@ public boolean hasBuoy() {
}

public boolean canUse() {
return !shouldBoost && EnchancementUtil.isSubmerged(obj, true, true, true);
return !shouldBoost && EnchancementUtil.isSubmerged(obj, SubmersionGate.ALL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import moriyashiine.enchancement.common.init.ModEnchantments;
import moriyashiine.enchancement.common.init.ModEntityComponents;
import moriyashiine.enchancement.common.util.EnchancementUtil;
import moriyashiine.enchancement.common.util.SubmersionGate;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.LivingEntity;
import net.minecraft.world.World;
Expand All @@ -17,7 +18,7 @@ public class BuoyEvent implements MultiplyMovementSpeedEvent {
public float multiply(float currentMultiplier, World world, LivingEntity living) {
int level = EnchantmentHelper.getEquipmentLevel(ModEnchantments.BUOY, living);
if (level > 0) {
if (ModEntityComponents.EXTENDED_WATER.get(living).getTicksWet() > 0 || EnchancementUtil.isSubmerged(living, true, false, false)) {
if (ModEntityComponents.EXTENDED_WATER.get(living).getTicksWet() > 0 || EnchancementUtil.isSubmerged(living, SubmersionGate.WATER_ONLY)) {
currentMultiplier = EnchancementUtil.capMovementMultiplier(currentMultiplier * (1 + level * 0.75F));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import moriyashiine.enchancement.common.init.ModEnchantments;
import moriyashiine.enchancement.common.init.ModTags;
import moriyashiine.enchancement.mixin.util.ItemEntityAccessor;
import net.fabricmc.fabric.api.tag.convention.v1.ConventionalFluidTags;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
Expand All @@ -22,12 +24,10 @@
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.PersistentProjectileEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.item.*;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.recipe.Recipe;
import net.minecraft.registry.Registries;
import net.minecraft.registry.tag.FluidTags;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.random.Random;
Expand Down Expand Up @@ -161,10 +161,16 @@ public static boolean isGroundedOrAirborne(LivingEntity living) {
return isGroundedOrAirborne(living, false);
}

public static boolean isSubmerged(Entity entity, boolean allowWater, boolean allowLava, boolean allowPowderSnow) {
public static boolean isSubmerged(Entity entity, SubmersionGate gate) {
for (int i = 0; i <= 1; i++) {
FluidState fluidState = entity.getWorld().getFluidState(entity.getBlockPos().up(i));
if ((allowWater && fluidState.isIn(FluidTags.WATER)) || (allowLava && fluidState.isIn(FluidTags.LAVA)) || (allowPowderSnow && entity.getWorld().getBlockState(entity.getBlockPos().up(i)).isOf(Blocks.POWDER_SNOW))) {
BlockState blockState = entity.getWorld().getBlockState(entity.getBlockPos().up(i));
if (gate.allowsWater() && !blockState.isOf(Blocks.BUBBLE_COLUMN) && blockState.getFluidState().isIn(ConventionalFluidTags.WATER)) {
return true;
}
if (gate.allowsLava() && blockState.getFluidState().isIn(ConventionalFluidTags.LAVA)) {
return true;
}
if (gate.allowsPowderSnow() && blockState.isOf(Blocks.POWDER_SNOW)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package moriyashiine.enchancement.common.util;

public enum SubmersionGate {
ALL(true, true, true),
WATER_ONLY(true, false, false),
LAVA_ONLY(false, true, false),
POWDER_SNOW_ONLY(false, false, true);

private final boolean allowsWater, allowsLava, allowsPowderSnow;

SubmersionGate(boolean allowsWater, boolean allowsLava, boolean allowsPowderSnow) {
this.allowsWater = allowsWater;
this.allowsLava = allowsLava;
this.allowsPowderSnow = allowsPowderSnow;
}

public boolean allowsWater() {
return allowsWater;
}

public boolean allowsLava() {
return allowsLava;
}

public boolean allowsPowderSnow() {
return allowsPowderSnow;
}
}

This file was deleted.

1 change: 0 additions & 1 deletion src/main/resources/enchancement.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"brimstone.CrossbowItemMixin",
"brimstone.ItemStackMixin",
"brimstone.ServerPlayerInteractionManagerMixin",
"buoy.EntityMixin",
"buoy.LivingEntityMixin",
"buoy.PlayerEntityMixin",
"buoy.PowderSnowBlockMixin",
Expand Down

0 comments on commit cfa9d70

Please sign in to comment.