From abcd2bdc1729712c6e5902f46d384672321db021 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Mon, 30 Dec 2024 19:37:39 -0500 Subject: [PATCH 1/3] bruh --- gradle.properties | 2 +- .../lib/gravity/api/GravityAPI.java | 10 ++- .../functions/AbsoluteGravityFunction.java | 2 - .../InterpolatedGravityFunction.java | 65 ------------------- 4 files changed, 5 insertions(+), 74 deletions(-) delete mode 100644 src/main/java/net/frozenblock/lib/gravity/api/functions/InterpolatedGravityFunction.java diff --git a/gradle.properties b/gradle.properties index 15588957a..a2d0929fb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ min_loader_version=0.16.0 # Mod Properties - mod_version = 1.9.7 + 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..7ef40aed0 100644 --- a/src/main/java/net/frozenblock/lib/gravity/api/GravityAPI.java +++ b/src/main/java/net/frozenblock/lib/gravity/api/GravityAPI.java @@ -32,9 +32,7 @@ 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 double DEFAULT_GRAVITY = 1D; public static final Event MODIFICATIONS = FrozenEvents.createEnvironmentEvent(GravityModification.class, callbacks -> context -> { for (GravityModification callback : callbacks) { @@ -53,7 +51,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()); } @@ -75,11 +73,11 @@ public static Vec3 calculateGravity(ResourceKey dimension, double y) { return context.gravity; } - public static Vec3 calculateGravity(Level level, double y) { + public static Vec3 calculateGravity(@NotNull Level level, double y) { return calculateGravity(level.dimension(), y); } - public static Vec3 calculateGravity(Entity entity) { + public static Vec3 calculateGravity(@NotNull Entity entity) { ResourceKey dimension = entity.level().dimension(); double y = entity.getY(); GravityContext context = new GravityContext(dimension, y, entity); 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..a86682252 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 @@ -26,13 +26,11 @@ import org.jetbrains.annotations.Nullable; public record AbsoluteGravityFunction(Vec3 gravity) implements SerializableGravityFunction { - public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Vec3.CODEC.fieldOf("gravity").forGetter(AbsoluteGravityFunction::gravity) ).apply(instance, AbsoluteGravityFunction::new) ); - public static final Codec> BELT_CODEC = GravityBelt.codec(CODEC); @Override 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; - } -} From 184c9ea556ca965bbef61007e6a7ac8afe54ebbc Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Mon, 30 Dec 2024 19:47:26 -0500 Subject: [PATCH 2/3] simplify gravity api --- .../lib/gravity/api/GravityAPI.java | 31 ++--- .../lib/gravity/api/GravityBelt.java | 12 +- .../lib/gravity/api/GravityContext.java | 16 ++- .../lib/gravity/api/GravityFunction.java | 3 +- .../functions/AbsoluteGravityFunction.java | 7 +- .../gravity/impl/EntityGravityInterface.java | 27 ----- .../gravity/impl/GravityRenderingImpl.java | 114 ------------------ .../lib/gravity/mixin/BoatMixin.java | 48 -------- .../lib/gravity/mixin/EntityMixin.java | 41 +------ .../lib/gravity/mixin/LivingEntityMixin.java | 62 ---------- .../mixin/ThrowableProjectileMixin.java | 37 ------ .../mixin/client/LevelRendererMixin.java | 58 --------- .../gravity/mixin/client/ParticleMixin.java | 90 -------------- .../mixin/frozenlib.gravity.mixins.json | 9 +- .../lib/testmod/FrozenTestMain.java | 15 --- 15 files changed, 32 insertions(+), 538 deletions(-) delete mode 100644 src/main/java/net/frozenblock/lib/gravity/impl/EntityGravityInterface.java delete mode 100644 src/main/java/net/frozenblock/lib/gravity/impl/GravityRenderingImpl.java delete mode 100644 src/main/java/net/frozenblock/lib/gravity/mixin/BoatMixin.java delete mode 100644 src/main/java/net/frozenblock/lib/gravity/mixin/LivingEntityMixin.java delete mode 100644 src/main/java/net/frozenblock/lib/gravity/mixin/ThrowableProjectileMixin.java delete mode 100644 src/main/java/net/frozenblock/lib/gravity/mixin/client/LevelRendererMixin.java delete mode 100644 src/main/java/net/frozenblock/lib/gravity/mixin/client/ParticleMixin.java 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 7ef40aed0..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,18 +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 { - public static final double DEFAULT_GRAVITY = 1D; - - 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) { @@ -67,25 +64,15 @@ public static List> getAllBelts(ResourceKey dimension) { }); } - 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(@NotNull Level level, double y) { - return calculateGravity(level.dimension(), y); - } - - public static Vec3 calculateGravity(@NotNull 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 a86682252..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,16 +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/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/impl/GravityRenderingImpl.java b/src/main/java/net/frozenblock/lib/gravity/impl/GravityRenderingImpl.java deleted file mode 100644 index e0f74d7ca..000000000 --- a/src/main/java/net/frozenblock/lib/gravity/impl/GravityRenderingImpl.java +++ /dev/null @@ -1,114 +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 com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferUploader; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.blaze3d.vertex.VertexFormat; -import com.mojang.math.Axis; -import net.frozenblock.lib.gravity.api.GravityAPI; -import net.frozenblock.lib.gravity.api.GravityBelt; -import net.minecraft.client.Camera; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Mth; -import org.jetbrains.annotations.ApiStatus; -import org.joml.Matrix4f; - -@ApiStatus.Internal -public final class GravityRenderingImpl { - private GravityRenderingImpl() {} - - private static final ResourceLocation FORCEFIELD_LOCATION = ResourceLocation.withDefaultNamespace("textures/misc/forcefield.png"); - - public static void renderGravityBelts(ClientLevel level, Camera camera, PoseStack poseStack) { - // not working properly - if (true) return; - RenderSystem.defaultBlendFunc(); - double y = camera.getPosition().y(); - for (GravityBelt gravityBelt : GravityAPI.getAllBelts(level)) { - poseStack.pushPose(); - poseStack.mulPose(Axis.YP.rotationDegrees(-90F)); - if (gravityBelt.renderTop()) { - float distance = (float) (gravityBelt.maxY() - y); - float alpha = Mth.lerp(Mth.clamp(Math.abs(distance), 0, 32) / 32F, 1F, 0F); - if (alpha > 0) { - RenderSystem.setShaderColor(0.25f, 0.45f, 1.0f, 1.0f); - poseStack.pushPose(); - poseStack.translate(0, distance, 0); - //poseStack.mulPose(Axis.XP.rotationDegrees((rotation - xRot) * 360F)); - Matrix4f matrix4f3 = poseStack.last().pose(); - - float k = 130; - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderTexture(0, FORCEFIELD_LOCATION); - var firstBuffer = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - firstBuffer.addVertex(matrix4f3, -k, 0F, -k).setUv(0.0f, 0.0f); - firstBuffer.addVertex(matrix4f3, k, 0F, -k).setUv(1.0f, 0.0f); - firstBuffer.addVertex(matrix4f3, k, 0F, k).setUv(1.0f, 1.0f); - firstBuffer.addVertex(matrix4f3, -k, 0F, k).setUv(0.0f, 1.0f); - BufferUploader.drawWithShader(firstBuffer.build()); - - var secondBuffer = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - secondBuffer.addVertex(matrix4f3, -k, 0F, k).setUv(0.0f, 0.0f); - secondBuffer.addVertex(matrix4f3, k, 0F, k).setUv(1.0f, 0.0f); - secondBuffer.addVertex(matrix4f3, k, 0F, -k).setUv(1.0f, 1.0f); - secondBuffer.addVertex(matrix4f3, -k, 0F, -k).setUv(0.0f, 1.0f); - BufferUploader.drawWithShader(secondBuffer.build()); - poseStack.popPose(); - } - } - - if (gravityBelt.renderBottom()) { - float distance = (float) (gravityBelt.minY() - y); - float alpha = Mth.lerp(Mth.clamp(Math.abs(distance), 0, 32) / 32F, 1F, 0F); - if (alpha > 0) { - RenderSystem.setShaderColor(0.25f, 0.45f, 1.0f, 1.0f); - poseStack.pushPose(); - poseStack.translate(0, distance, 0); - //poseStack.mulPose(Axis.XP.rotationDegrees((rotation - xRot) * 360F)); - Matrix4f matrix4f3 = poseStack.last().pose(); - - float k = 130; - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderTexture(0, FORCEFIELD_LOCATION); - var firstBuffer = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - firstBuffer.addVertex(matrix4f3, -k, 0F, -k).setUv(0.0f, 0.0f); - firstBuffer.addVertex(matrix4f3, k, 0F, -k).setUv(1.0f, 0.0f); - firstBuffer.addVertex(matrix4f3, k, 0F, k).setUv(1.0f, 1.0f); - firstBuffer.addVertex(matrix4f3, -k, 0F, k).setUv(0.0f, 1.0f); - BufferUploader.drawWithShader(firstBuffer.build()); - - var secondBuffer = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - secondBuffer.addVertex(matrix4f3, -k, 0F, k).setUv(0.0f, 0.0f); - secondBuffer.addVertex(matrix4f3, k, 0F, k).setUv(1.0f, 0.0f); - secondBuffer.addVertex(matrix4f3, k, 0F, -k).setUv(1.0f, 1.0f); - secondBuffer.addVertex(matrix4f3, -k, 0F, -k).setUv(0.0f, 1.0f); - BufferUploader.drawWithShader(secondBuffer.build()); - poseStack.popPose(); - } - } - poseStack.popPose(); - } - RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); - } -} diff --git a/src/main/java/net/frozenblock/lib/gravity/mixin/BoatMixin.java b/src/main/java/net/frozenblock/lib/gravity/mixin/BoatMixin.java deleted file mode 100644 index c58a037f8..000000000 --- a/src/main/java/net/frozenblock/lib/gravity/mixin/BoatMixin.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 net.frozenblock.lib.gravity.impl.EntityGravityInterface; -import net.minecraft.world.entity.vehicle.Boat; -import net.minecraft.world.phys.Vec3; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArgs; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; - -@Mixin(Boat.class) -public abstract class BoatMixin implements EntityGravityInterface { - - @ModifyArgs(method = "floatBoat", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/entity/vehicle/Boat;setDeltaMovement(DDD)V", - ordinal = 0 - ) - ) - private void frozenLib$useGravity(Args args) { - double x = args.get(0); - double y = (double) args.get(1) + this.frozenLib$getGravity(); - double z = args.get(2); - - Vec3 newVec = new Vec3(x, y, z).subtract(this.frozenLib$getEffectiveGravity()); - args.set(0, newVec.x); - args.set(1, newVec.y); - args.set(2, 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 027acf4bb..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,59 +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; @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; + this.fallDistance *= (float) GravityAPI.calculateGravity(Entity.class.cast(this)); } - @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; - } - - @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 686a4f590..000000000 --- a/src/main/java/net/frozenblock/lib/gravity/mixin/LivingEntityMixin.java +++ /dev/null @@ -1,62 +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.ModifyExpressionValue; -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 { - - // TODO: convert to directional - @ModifyExpressionValue( - method = "travel", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/entity/LivingEntity;getGravity()D" - ) - ) - private double frozenLib$useGravity(double original) { - LivingEntity entity = LivingEntity.class.cast(this); - return original * GravityAPI.calculateGravity(entity).length(); - } - - @WrapOperation( - method = "travel", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/entity/LivingEntity;setDeltaMovement(DDD)V", - ordinal = 3 - ) - ) - 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/LevelRendererMixin.java b/src/main/java/net/frozenblock/lib/gravity/mixin/client/LevelRendererMixin.java deleted file mode 100644 index e87eea125..000000000 --- a/src/main/java/net/frozenblock/lib/gravity/mixin/client/LevelRendererMixin.java +++ /dev/null @@ -1,58 +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.Local; -import com.mojang.blaze3d.vertex.PoseStack; -import net.frozenblock.lib.gravity.impl.GravityRenderingImpl; -import net.minecraft.client.Camera; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.LevelRenderer; -import org.jetbrains.annotations.Nullable; -import org.joml.Matrix4f; -import org.spongepowered.asm.mixin.Mixin; -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; - -@Mixin(LevelRenderer.class) -public class LevelRendererMixin { - - @Shadow - @Nullable - private ClientLevel level; - - @Inject( - method = "renderSky", - at = @At( - value = "INVOKE", - target = "Lcom/mojang/blaze3d/systems/RenderSystem;depthMask(Z)V", - ordinal = 1, - shift = At.Shift.AFTER, - remap = false - ), - require = 0 - ) - private void frozenLib$renderSky( - Matrix4f matrix4f, Matrix4f matrix4f2, float f, Camera camera, boolean bl, Runnable runnable, CallbackInfo info, - @Local(ordinal = 0) PoseStack poseStack - ) { - GravityRenderingImpl.renderGravityBelts(level, camera, poseStack); - } -} 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 70807b71a..ef5da06a4 100644 --- a/src/main/resources/mixin/frozenlib.gravity.mixins.json +++ b/src/main/resources/mixin/frozenlib.gravity.mixins.json @@ -7,13 +7,6 @@ "defaultRequire": 1 }, "mixins": [ - "BoatMixin", - "EntityMixin", - "LivingEntityMixin", - "ThrowableProjectileMixin" - ], - "client": [ - "client.LevelRendererMixin", - "client.ParticleMixin" + "EntityMixin" ] } diff --git a/src/testmod/java/net/frozenblock/lib/testmod/FrozenTestMain.java b/src/testmod/java/net/frozenblock/lib/testmod/FrozenTestMain.java index d0e6e69bc..7c4910d09 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; /* @@ -27,13 +26,9 @@ */ 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; @@ -44,12 +39,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; @@ -69,13 +61,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) -> { From b8a8509a6b71f0abc4b517e769e8752a26f0b150 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Mon, 30 Dec 2024 19:53:50 -0500 Subject: [PATCH 3/3] Delete GravityTests.java --- .../net/frozenblock/lib/GravityTests.java | 49 ------------------- 1 file changed, 49 deletions(-) delete mode 100644 src/test/java/net/frozenblock/lib/GravityTests.java 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)); - } -}