diff --git a/gradle.properties b/gradle.properties index 5c02f4622..886fdfa7d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ min_loader_version=0.16.9 # Mod Properties - mod_version = 1.9.8 + mod_version = 1.9.9 maven_group = net.frozenblock archives_base_name = FrozenLib diff --git a/src/main/java/net/frozenblock/lib/gravity/api/GravityAPI.java b/src/main/java/net/frozenblock/lib/gravity/api/GravityAPI.java index 35f941101..33c7551dd 100644 --- a/src/main/java/net/frozenblock/lib/gravity/api/GravityAPI.java +++ b/src/main/java/net/frozenblock/lib/gravity/api/GravityAPI.java @@ -28,20 +28,15 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; -import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; public final class GravityAPI { - private GravityAPI() {} - - public static final Vec3 DEFAULT_GRAVITY = new Vec3(0.0, 1.0, 0.0); - - public static final Event MODIFICATIONS = FrozenEvents.createEnvironmentEvent(GravityModification.class, callbacks -> context -> { - for (GravityModification callback : callbacks) { - callback.modifyGravity(context); - } - }); - + public static final double DEFAULT_GRAVITY = 0.45D; + public static final Event MODIFICATIONS = FrozenEvents.createEnvironmentEvent(GravityModification.class, callbacks -> context -> { + for (GravityModification callback : callbacks) { + callback.modifyGravity(context); + } + }); private static final Map, List>> GRAVITY_BELTS = new HashMap<>(); public static void register(ResourceKey dimension, GravityBelt gravityBelt) { @@ -53,7 +48,7 @@ public static List> getAllBelts(ResourceKey dimension) { return GRAVITY_BELTS.computeIfAbsent(dimension, dimension1 -> new ArrayList<>()); } - public static List> getAllBelts(Level level) { + public static @NotNull List> getAllBelts(@NotNull Level level) { return getAllBelts(level.dimension()); } @@ -69,25 +64,15 @@ public static List> getAllBelts(Level level) { }); } - public static Vec3 calculateGravity(ResourceKey dimension, double y) { - GravityContext context = new GravityContext(dimension, y, null); - MODIFICATIONS.invoker().modifyGravity(context); - return context.gravity; - } - - public static Vec3 calculateGravity(Level level, double y) { - return calculateGravity(level.dimension(), y); - } - - public static Vec3 calculateGravity(Entity entity) { + public static double calculateGravity(@NotNull Entity entity) { ResourceKey dimension = entity.level().dimension(); double y = entity.getY(); - GravityContext context = new GravityContext(dimension, y, entity); + GravityContext context = new GravityContext(dimension, y, entity, entity.getInBlockState()); MODIFICATIONS.invoker().modifyGravity(context); return context.gravity; } - public static Optional> getAffectingGravityBelt(List> belts, double y) { + public static Optional> getAffectingGravityBelt(@NotNull List> belts, double y) { Optional> optionalGravityBelt = Optional.empty(); for (GravityBelt belt : belts) { if (belt.affectsPosition(y)) { diff --git a/src/main/java/net/frozenblock/lib/gravity/api/GravityBelt.java b/src/main/java/net/frozenblock/lib/gravity/api/GravityBelt.java index 6211e2f98..a905b5f38 100644 --- a/src/main/java/net/frozenblock/lib/gravity/api/GravityBelt.java +++ b/src/main/java/net/frozenblock/lib/gravity/api/GravityBelt.java @@ -20,20 +20,16 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.world.entity.Entity; -import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public record GravityBelt(double minY, double maxY, boolean renderBottom, boolean renderTop, - T function) { - public GravityBelt(double minY, double maxY, T function) { - this(minY, maxY, false, false, function); - } +public record GravityBelt(double minY, double maxY, T function) { public boolean affectsPosition(double y) { return y >= minY && y < maxY; } - public Vec3 getGravity(@Nullable Entity entity, double y) { + public double getGravity(@Nullable Entity entity, double y) { if (this.affectsPosition(y)) { return this.function.get(entity, y, this.minY, this.maxY); } @@ -51,7 +47,7 @@ public static > Codec> c } @Nullable - public static > Codec> codec(T gravityFunction) { + public static > Codec> codec(@NotNull T gravityFunction) { Codec codec = gravityFunction.codec(); if (codec == null) return null; return codec(codec); diff --git a/src/main/java/net/frozenblock/lib/gravity/api/GravityContext.java b/src/main/java/net/frozenblock/lib/gravity/api/GravityContext.java index 8b1cc9b6a..3a273512d 100644 --- a/src/main/java/net/frozenblock/lib/gravity/api/GravityContext.java +++ b/src/main/java/net/frozenblock/lib/gravity/api/GravityContext.java @@ -20,31 +20,29 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; -import net.minecraft.world.phys.Vec3; +import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; public class GravityContext { - public final ResourceKey dimension; - public final double y; - /** * A mutable property that will determine the outputting gravity */ - public Vec3 gravity; - + public double gravity; @Nullable public final Entity entity; + public final BlockState state; - public GravityContext(ResourceKey dimension, double y, @Nullable Entity entity) { - this(dimension, y, GravityAPI.DEFAULT_GRAVITY, entity); + public GravityContext(ResourceKey dimension, double y, @Nullable Entity entity, BlockState state) { + this(dimension, y, GravityAPI.DEFAULT_GRAVITY, entity, state); } - public GravityContext(ResourceKey dimension, double y, Vec3 gravity, @Nullable Entity entity) { + public GravityContext(ResourceKey dimension, double y, double gravity, @Nullable Entity entity, BlockState state) { this.dimension = dimension; this.y = y; this.gravity = gravity; this.entity = entity; + this.state = state; } } diff --git a/src/main/java/net/frozenblock/lib/gravity/api/GravityFunction.java b/src/main/java/net/frozenblock/lib/gravity/api/GravityFunction.java index a18468d86..5f25bcf30 100644 --- a/src/main/java/net/frozenblock/lib/gravity/api/GravityFunction.java +++ b/src/main/java/net/frozenblock/lib/gravity/api/GravityFunction.java @@ -18,7 +18,6 @@ package net.frozenblock.lib.gravity.api; import net.minecraft.world.entity.Entity; -import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; @FunctionalInterface @@ -30,5 +29,5 @@ public interface GravityFunction { * @param maxY The maximum Y position of the gravity belt * @return The gravity value */ - Vec3 get(@Nullable Entity entity, double y, double minY, double maxY); + double get(@Nullable Entity entity, double y, double minY, double maxY); } diff --git a/src/main/java/net/frozenblock/lib/gravity/api/functions/AbsoluteGravityFunction.java b/src/main/java/net/frozenblock/lib/gravity/api/functions/AbsoluteGravityFunction.java index c35ed26ff..72b4aa8d6 100644 --- a/src/main/java/net/frozenblock/lib/gravity/api/functions/AbsoluteGravityFunction.java +++ b/src/main/java/net/frozenblock/lib/gravity/api/functions/AbsoluteGravityFunction.java @@ -25,18 +25,17 @@ import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; -public record AbsoluteGravityFunction(Vec3 gravity) implements SerializableGravityFunction { - +public record AbsoluteGravityFunction(double gravity) implements SerializableGravityFunction { public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - Vec3.CODEC.fieldOf("gravity").forGetter(AbsoluteGravityFunction::gravity) + Codec.DOUBLE.fieldOf("gravity").forGetter(AbsoluteGravityFunction::gravity) ).apply(instance, AbsoluteGravityFunction::new) ); public static final Codec> BELT_CODEC = GravityBelt.codec(CODEC); @Override - public Vec3 get(@Nullable Entity entity, double y, double minY, double maxY) { + public double get(@Nullable Entity entity, double y, double minY, double maxY) { return gravity(); } diff --git a/src/main/java/net/frozenblock/lib/gravity/api/functions/InterpolatedGravityFunction.java b/src/main/java/net/frozenblock/lib/gravity/api/functions/InterpolatedGravityFunction.java deleted file mode 100644 index ce1bf6319..000000000 --- a/src/main/java/net/frozenblock/lib/gravity/api/functions/InterpolatedGravityFunction.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2024 FrozenBlock - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.frozenblock.lib.gravity.api.functions; - -import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.frozenblock.lib.gravity.api.GravityBelt; -import net.frozenblock.lib.gravity.api.SerializableGravityFunction; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.phys.Vec3; -import org.jetbrains.annotations.Nullable; - -public record InterpolatedGravityFunction( - Vec3 gravity - //double minLerpGravity, - //double maxLerpGravity, - //double minLerpY, - //double maxLerpY -) implements SerializableGravityFunction { - - public static final Codec CODEC = RecordCodecBuilder.create(instance -> - instance.group( - Vec3.CODEC.fieldOf("gravity").forGetter(InterpolatedGravityFunction::gravity) - //Codec.DOUBLE.fieldOf("minLerpGravity").forGetter(InterpolatedGravityFunction::minLerpGravity), - //Codec.DOUBLE.fieldOf("maxLerpGravity").forGetter(InterpolatedGravityFunction::maxLerpY), - //Codec.DOUBLE.fieldOf("minLerpY").forGetter(InterpolatedGravityFunction::minLerpY), - //Codec.DOUBLE.fieldOf("maxLerpY").forGetter(InterpolatedGravityFunction::maxLerpY) - ).apply(instance, InterpolatedGravityFunction::new) - ); - - public static final Codec> BELT_CODEC = GravityBelt.codec(CODEC); - - @Override - public Vec3 get(@Nullable Entity entity, double y, double minY, double maxY) { - double normalizedY = (y - minY) / (maxY - minY); - //double normalizedY = (y - minLerpY) / (maxLerpY - minLerpY); - - return gravity.scale(normalizedY); - /*if (normalizedY < 0.5) { - return Mth.clamp(Mth.lerp(normalizedY, minLerpGravity, gravity), minLerpGravity, gravity); - } - if (normalizedY < 1.0) return Mth.lerp(normalizedY, gravity, maxLerpGravity); - return maxLerpGravity;*/ - } - - @Override - public Codec codec() { - return CODEC; - } -} diff --git a/src/main/java/net/frozenblock/lib/gravity/impl/EntityGravityInterface.java b/src/main/java/net/frozenblock/lib/gravity/impl/EntityGravityInterface.java deleted file mode 100644 index 599c95309..000000000 --- a/src/main/java/net/frozenblock/lib/gravity/impl/EntityGravityInterface.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2024 FrozenBlock - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.frozenblock.lib.gravity.impl; - -import net.minecraft.world.phys.Vec3; - -public interface EntityGravityInterface { - - double frozenLib$getGravity(); - - Vec3 frozenLib$getEffectiveGravity(); -} diff --git a/src/main/java/net/frozenblock/lib/gravity/mixin/AbstractBoatMixin.java b/src/main/java/net/frozenblock/lib/gravity/mixin/AbstractBoatMixin.java deleted file mode 100644 index 16a1fc011..000000000 --- a/src/main/java/net/frozenblock/lib/gravity/mixin/AbstractBoatMixin.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2024 FrozenBlock - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.frozenblock.lib.gravity.mixin; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import net.frozenblock.lib.gravity.impl.EntityGravityInterface; -import net.minecraft.world.entity.vehicle.AbstractBoat; -import net.minecraft.world.phys.Vec3; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -@Mixin(AbstractBoat.class) -public abstract class AbstractBoatMixin implements EntityGravityInterface { - - @WrapOperation(method = "floatBoat", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/entity/vehicle/AbstractBoat;setDeltaMovement(DDD)V", - ordinal = 0 - ) - ) - private void frozenLib$useGravity(AbstractBoat instance, double x, double y, double z, Operation original) { - double newY = y + this.frozenLib$getGravity(); - - Vec3 newVec = new Vec3(x, newY, z).subtract(this.frozenLib$getEffectiveGravity()); - original.call(instance, newVec.x, newVec.y, newVec.z); - } -} diff --git a/src/main/java/net/frozenblock/lib/gravity/mixin/EntityMixin.java b/src/main/java/net/frozenblock/lib/gravity/mixin/EntityMixin.java index 93e830954..bf077b22e 100644 --- a/src/main/java/net/frozenblock/lib/gravity/mixin/EntityMixin.java +++ b/src/main/java/net/frozenblock/lib/gravity/mixin/EntityMixin.java @@ -17,65 +17,30 @@ package net.frozenblock.lib.gravity.mixin; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; import net.frozenblock.lib.gravity.api.GravityAPI; -import net.frozenblock.lib.gravity.impl.EntityGravityInterface; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(Entity.class) -public abstract class EntityMixin implements EntityGravityInterface { +public abstract class EntityMixin { @Shadow public float fallDistance; - // TODO: convert to directional - @WrapOperation(method = "getGravity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getDefaultGravity()D")) - private double getGravity(Entity instance, Operation original) { - return original.call(instance) * GravityAPI.calculateGravity(instance).length(); - } - @Inject(method = "checkFallDamage", at = @At("TAIL")) private void frozenLib$checkFallDamage(double y, boolean onGround, BlockState state, BlockPos pos, CallbackInfo info) { - Vec3 gravity = GravityAPI.calculateGravity(Entity.class.cast(this)); - double gravityDistance = gravity.length(); - this.fallDistance *= (float) gravityDistance; - } - - @WrapOperation( - method = "applyGravity", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/phys/Vec3;add(DDD)Lnet/minecraft/world/phys/Vec3;" - ) - ) - public Vec3 frozenLib$applyGravity(Vec3 instance, double x, double y, double z, Operation original, @Local(ordinal = 0) double originalGravity) { - Vec3 gravityVec = GravityAPI.calculateGravity(Entity.class.cast(this)).scale(originalGravity); - Vec3 directional = new Vec3(x, y + originalGravity, z).subtract(gravityVec); - - return original.call(instance, directional.x, directional.y, directional.z); - } - - @Unique - @Override - public double frozenLib$getGravity() { - return 0.04D; + this.fallDistance *= (float) GravityAPI.calculateGravity(Entity.class.cast(this)); } - @Unique - @Override - public Vec3 frozenLib$getEffectiveGravity() { - Entity entity = Entity.class.cast(this); - return GravityAPI.calculateGravity(entity).scale(this.frozenLib$getGravity()); + @ModifyReturnValue(method = "getGravity", at = @At("RETURN")) + public double frozenLib$modifyGravity(double original) { + return original * GravityAPI.calculateGravity(Entity.class.cast(this)); } } diff --git a/src/main/java/net/frozenblock/lib/gravity/mixin/LivingEntityMixin.java b/src/main/java/net/frozenblock/lib/gravity/mixin/LivingEntityMixin.java deleted file mode 100644 index 5dfe958da..000000000 --- a/src/main/java/net/frozenblock/lib/gravity/mixin/LivingEntityMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2024 FrozenBlock - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.frozenblock.lib.gravity.mixin; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import com.llamalad7.mixinextras.sugar.Local; -import net.frozenblock.lib.gravity.api.GravityAPI; -import net.frozenblock.lib.gravity.impl.EntityGravityInterface; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.phys.Vec3; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -@Mixin(LivingEntity.class) -public abstract class LivingEntityMixin implements EntityGravityInterface { - - @WrapOperation( - method = "travelInAir", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/entity/LivingEntity;setDeltaMovement(DDD)V", - ordinal = 1 - ) - ) - private void frozenLib$newGravity(LivingEntity instance, double x, double y, double z, Operation original, @Local(ordinal = 0) double originalGravity) { - LivingEntity entity = LivingEntity.class.cast(this); - Vec3 gravityVec = GravityAPI.calculateGravity(entity).scale(originalGravity); - Vec3 directional = new Vec3(x, y + originalGravity, z).subtract(gravityVec); - - original.call(instance, directional.x, directional.y, directional.z); - } -} diff --git a/src/main/java/net/frozenblock/lib/gravity/mixin/ThrowableProjectileMixin.java b/src/main/java/net/frozenblock/lib/gravity/mixin/ThrowableProjectileMixin.java deleted file mode 100644 index 52bb696f7..000000000 --- a/src/main/java/net/frozenblock/lib/gravity/mixin/ThrowableProjectileMixin.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2024 FrozenBlock - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.frozenblock.lib.gravity.mixin; - -import net.frozenblock.lib.gravity.impl.EntityGravityInterface; -import net.minecraft.world.entity.projectile.ThrowableProjectile; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; - -@Mixin(ThrowableProjectile.class) -public abstract class ThrowableProjectileMixin implements EntityGravityInterface { - - @Shadow - protected abstract double getDefaultGravity(); - - @Unique - @Override - public double frozenLib$getGravity() { - return this.getDefaultGravity(); - } -} diff --git a/src/main/java/net/frozenblock/lib/gravity/mixin/client/ParticleMixin.java b/src/main/java/net/frozenblock/lib/gravity/mixin/client/ParticleMixin.java deleted file mode 100644 index fd45b81a9..000000000 --- a/src/main/java/net/frozenblock/lib/gravity/mixin/client/ParticleMixin.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2024 FrozenBlock - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.frozenblock.lib.gravity.mixin.client; - -import com.llamalad7.mixinextras.sugar.Share; -import com.llamalad7.mixinextras.sugar.ref.LocalDoubleRef; -import net.frozenblock.lib.gravity.api.GravityAPI; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.particle.Particle; -import net.minecraft.world.phys.Vec3; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(Particle.class) -public class ParticleMixin { - - @Unique - private static final double BASE_GRAVITY = 0.04; - - @Shadow - protected double xd; - - @Shadow - protected double yd; - - @Shadow - protected double zd; - - @Shadow - @Final - protected ClientLevel level; - - @Shadow - public double y; - - @Shadow - protected float gravity; - - @Inject(method = "tick", at = @At("HEAD")) - private void frozenLib$storeY( - CallbackInfo ci, - @Share("oldX") LocalDoubleRef oldX, - @Share("oldY") LocalDoubleRef oldY, - @Share("oldZ") LocalDoubleRef oldZ - ) { - oldX.set(this.xd); - oldY.set(this.yd); - oldZ.set(this.zd); - } - - @Inject( - method = "tick", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/client/particle/Particle;move(DDD)V", - ordinal = 0 - ) - ) - private void frozenLib$useGravity( - CallbackInfo ci, - @Share("oldX") LocalDoubleRef oldX, - @Share("oldY") LocalDoubleRef oldY, - @Share("oldZ") LocalDoubleRef oldZ - ) { - Vec3 gravity = GravityAPI.calculateGravity(this.level, this.y).scale(this.gravity).scale(BASE_GRAVITY); - this.xd = oldX.get() - gravity.x; - this.yd = oldY.get() - gravity.y; - this.zd = oldZ.get() - gravity.z; - } -} diff --git a/src/main/resources/mixin/frozenlib.gravity.mixins.json b/src/main/resources/mixin/frozenlib.gravity.mixins.json index 3c173765c..ef5da06a4 100644 --- a/src/main/resources/mixin/frozenlib.gravity.mixins.json +++ b/src/main/resources/mixin/frozenlib.gravity.mixins.json @@ -7,12 +7,6 @@ "defaultRequire": 1 }, "mixins": [ - "AbstractBoatMixin", - "EntityMixin", - "LivingEntityMixin", - "ThrowableProjectileMixin" - ], - "client": [ - "client.ParticleMixin" + "EntityMixin" ] } diff --git a/src/test/java/net/frozenblock/lib/GravityTests.java b/src/test/java/net/frozenblock/lib/GravityTests.java deleted file mode 100644 index 5aa85596a..000000000 --- a/src/test/java/net/frozenblock/lib/GravityTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2024 FrozenBlock - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.frozenblock.lib; - -import net.frozenblock.lib.gravity.api.GravityAPI; -import net.frozenblock.lib.gravity.api.GravityBelt; -import net.frozenblock.lib.gravity.api.functions.AbsoluteGravityFunction; -import net.minecraft.world.level.Level; -import net.minecraft.world.phys.Vec3; -import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -class GravityTests { - - @BeforeAll - public static void setup() { - TestUtil.setup(); - } - - @Test - void testGravity() { - // gravity 0.1 y 300..319 - GravityAPI.register(Level.OVERWORLD, new GravityBelt<>(300.0, 319.0, new AbsoluteGravityFunction(new Vec3(0.0, 0.1, 0.0)))); - // gravity 100.0 y -64..-32 - GravityAPI.register(Level.OVERWORLD, new GravityBelt<>(-64.0, -32.0, new AbsoluteGravityFunction(new Vec3(0.0, 100.0, 0.0)))); - // gravity 0.5 y 0..15 - GravityAPI.register(Level.OVERWORLD, new GravityBelt<>(0.0, 15.0, new AbsoluteGravityFunction(new Vec3(0.0, 0.5, 0.0)))); - - assertEquals(new Vec3(0.0, 0.1, 0.0), GravityAPI.calculateGravity(Level.OVERWORLD, 300)); - assertEquals(new Vec3(0.0, 100.0, 0.0), GravityAPI.calculateGravity(Level.OVERWORLD, -64)); - assertEquals(new Vec3(0.0, 0.5, 0.0), GravityAPI.calculateGravity(Level.OVERWORLD, 0)); - } -} diff --git a/src/testmod/java/net/frozenblock/lib/testmod/FrozenTestMain.java b/src/testmod/java/net/frozenblock/lib/testmod/FrozenTestMain.java index d71eb228a..d83fb62ac 100644 --- a/src/testmod/java/net/frozenblock/lib/testmod/FrozenTestMain.java +++ b/src/testmod/java/net/frozenblock/lib/testmod/FrozenTestMain.java @@ -17,7 +17,6 @@ package net.frozenblock.lib.testmod; -import com.mojang.datafixers.schemas.Schema; import java.util.List; import net.fabricmc.api.ModInitializer; //import net.fabricmc.frozenblock.datafixer.api.FabricDataFixerBuilder; @@ -25,13 +24,9 @@ //import net.fabricmc.frozenblock.datafixer.api.SimpleFixes; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; -import net.frozenblock.lib.FrozenSharedConstants; import net.frozenblock.lib.advancement.api.AdvancementAPI; import net.frozenblock.lib.advancement.api.AdvancementEvents; import net.frozenblock.lib.block.api.tick.BlockScheduledTicks; -import net.frozenblock.lib.gravity.api.GravityAPI; -import net.frozenblock.lib.gravity.api.GravityBelt; -import net.frozenblock.lib.gravity.api.functions.AbsoluteGravityFunction; import net.frozenblock.lib.testmod.config.TestConfig; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementRequirements; @@ -42,12 +37,9 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; -import net.minecraft.util.datafix.schemas.NamespacedSchema; -import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.storage.loot.BuiltInLootTables; -import net.minecraft.world.phys.Vec3; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,13 +59,6 @@ public void onInitialize() { BlockScheduledTicks.TICKS.put(Blocks.DIAMOND_BLOCK, (state, world, pos, random) -> world.setBlock(pos, Blocks.BEDROCK.defaultBlockState(), 3)); - GravityAPI.MODIFICATIONS.register((ctx) -> { - ctx.gravity = new Vec3(0.05, 0.8, 0.05); - }); - - GravityAPI.register(Level.OVERWORLD, new GravityBelt<>(300, 319, true, true, new AbsoluteGravityFunction(new Vec3(0.0, 0.1, 0.0)))); - assert GravityAPI.calculateGravity(Level.OVERWORLD, 300).y == 0.1; - //GravityAPI.register(BuiltinDimensionTypes.OVERWORLD, new GravityBelt<>(0, 192, new InterpolatedGravityFunction(0.1))); AdvancementEvents.INIT.register((holder, registries) -> {