Skip to content

Commit

Permalink
Merge pull request #27 from Lilyp3892/master
Browse files Browse the repository at this point in the history
Update to 1.20.1 (latest version) and fix texture issue, fix config saving, fix left hand bug
  • Loading branch information
segovo authored Jul 19, 2023
2 parents 5818c0a + d78ab84 commit b423098
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 59 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


plugins {
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'maven-publish'
}

Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.19
yarn_mappings=1.19+build.1
loader_version=0.14.6
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.9
loader_version=0.14.21

# Mod Properties
mod_version = 1.1.1
mod_version = 1.1.2
maven_group = net.fabricmc
archives_base_name = TrajectoryFabric

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.55.1+1.19
night_config_version=3.6.3
fabric_version=0.85.0+1.20.1
night_config_version=3.6.6
# cloth_events_version=1.2.0
# cloth_config_version=4.5.6
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
15 changes: 6 additions & 9 deletions src/main/java/net/Segovo/TrajectoryFabric/RenderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
//shamelessly ripped from https://github.com/ate47/Xray/blob/fabric-1.19/src/main/java/fr/atesab/xray/utils/RenderUtils.java
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.Matrix3f;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.math.Vec3f;
import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.joml.Vector3f;

public class RenderUtils {

public static void renderSingleLine(MatrixStack stack, VertexConsumer buffer, float x1, float y1, float z1,
float x2, float y2,
float z2, float r, float g, float b, float a) {
Vec3f normal = new Vec3f(x2 - x1, y2 - y1, z2 - z1);
Vector3f normal = new Vector3f(x2 - x1, y2 - y1, z2 - z1);
normal.normalize();
renderSingleLine(stack, buffer, x1, y1, z1, x2, y2, z2, r, g, b, a, normal.getX(), normal.getY(),
normal.getZ());
renderSingleLine(stack, buffer, x1, y1, z1, x2, y2, z2, r, g, b, a, normal.x(), normal.y(),
normal.z());
}

public static void renderSingleLine(MatrixStack stack, VertexConsumer buffer, float x1, float y1, float z1,
Expand All @@ -28,7 +28,4 @@ public static void renderSingleLine(MatrixStack stack, VertexConsumer buffer, fl
buffer.vertex(matrix4f, x2, y2, z2).color(r, g, b, a)
.normal(matrix3f, normalX, normalY, normalZ).next();
}

private RenderUtils() {
}
}
57 changes: 20 additions & 37 deletions src/main/java/net/Segovo/TrajectoryFabric/TrajectoryFabric.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import com.electronwill.nightconfig.core.ConfigSpec;
import com.electronwill.nightconfig.core.file.FileConfig;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.*;
Expand All @@ -26,7 +24,6 @@
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import java.io.File;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.util.math.Box;
Expand Down Expand Up @@ -66,9 +63,7 @@ public int[] getConfigIntegers() {

public static void renderBox(MatrixStack stack, VertexConsumer buffer, double x1, double y1, double z1, double x2, double y2, double z2, int[] color) {
Box aabb = new Box(x1, y1, z1, x2, y2, z2);
WorldRenderer.drawBox(stack, buffer, aabb, color[0], color[1], color[2], 1);


WorldRenderer.drawBox(stack, buffer, aabb, color[0]/255, color[1]/255, color[2]/255, color[3]/100);
}

public static void renderCurve(MatrixStack stack, VertexConsumer buffer, Camera camera, World world, BlockPos pos, float pitch, float yaw, double eye, PlayerEntity player, int[] color, float speed, float gravity, boolean[] booleans, int[] integers, boolean mainHand) {
Expand All @@ -79,18 +74,12 @@ public static void renderCurve(MatrixStack stack, VertexConsumer buffer, Camera
double accurateY = player.getY();
double accurateZ = player.getZ();

// Simulation


//float ngravity = 0.03f;
float drag = 0.99f;

float entityVelX = -MathHelper.sin(yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F);
float entityVelY = -MathHelper.sin(pitch * 0.017453292F);
float entityVelZ = MathHelper.cos(yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F);
Vec3d vec3d = (new Vec3d(entityVelX, entityVelY, entityVelZ)).normalize().multiply(speed);
Vec3d playerVelocity = player.getVelocity();
vec3d = vec3d.add(playerVelocity.x, player.isOnGround() ? 0.0D : playerVelocity.y, playerVelocity.z);
Vec3d entityVelocity = new Vec3d(vec3d.x, vec3d.y, vec3d.z);
Vec3d entityPosition = new Vec3d(0, 0 + 1.5, 0);

Expand All @@ -101,6 +90,11 @@ public static void renderCurve(MatrixStack stack, VertexConsumer buffer, Camera
playerside = (mainHand ? 1 : -1);
}

var preferredHand = MinecraftClient.getInstance().player.getMainArm();
if (preferredHand.getId()==0){
playerside = playerside*(-1);
}

double offsetX = 0 * Math.cos(Math.toRadians((yaw + 90) * -1)) + playerside * Math.sin(Math.toRadians((yaw + 90) * -1));
double offsetZ = 0 * Math.sin(Math.toRadians((yaw + 90) * -1)) + playerside * Math.cos(Math.toRadians((yaw + 90) * -1));

Expand Down Expand Up @@ -155,8 +149,10 @@ public static void renderCurve(MatrixStack stack, VertexConsumer buffer, Camera

@Override
public void onInitializeClient() {

//Night Config
System.out.println("Config path: " + FabricLoader.getInstance().getConfigDirectory());
config.load();

ConfigSpec spec = new ConfigSpec();
spec.defineInRange("lineOrigin", 3, 1, 3);
spec.define("lineVisibility", true);
Expand All @@ -168,37 +164,36 @@ public void onInitializeClient() {
spec.defineInRange("lineColorB", 255, 0, 255);
spec.defineInRange("lineColorA", 100, 0, 100);

System.out.println(FabricLoader.getInstance().getConfigDirectory());
ConfigSpec.CorrectionListener listener = (action, path, incorrectValue, correctedValue) -> {
String pathString = String.join(",", path);
System.out.println("Corrected " + pathString + ": was " + incorrectValue + ", is now " + correctedValue);
};
int numberOfCorrections = spec.correct(config, listener);

if (!spec.isCorrect(config)) {
System.out.println("Config incorrect! resetting...");
spec.correct(config);
if (numberOfCorrections >= 1) {
System.out.println("Saved config");
config.save();
}

config.load();

// Rendering
Set<Item> itemsSimple = new HashSet<>();
itemsSimple.add(Items.ENDER_PEARL.asItem());
itemsSimple.add(Items.SNOWBALL.asItem());
//items.add(Items.SPLASH_POTION.asItem());
itemsSimple.add(Items.EGG.asItem());

Set<Item> itemsComplex = new HashSet<>();
itemsComplex.add(Items.BOW.asItem());

MinecraftClient client = MinecraftClient.getInstance();

WorldRenderEvents.AFTER_ENTITIES.register((WorldRenderContext context) -> {
WorldRenderEvents.END.register((WorldRenderContext context) -> {
MatrixStack stack = context.matrixStack();

RenderSystem.setShader(GameRenderer::getPositionColorShader);
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
RenderSystem.depthMask(false);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.disableTexture();
if (smoothLines) GL11.glEnable(GL11.GL_LINE_SMOOTH);

stack.push();
Expand All @@ -210,13 +205,9 @@ public void onInitializeClient() {
Camera camera = client.gameRenderer.getCamera();
Vec3d cameraPos = camera.getPos();


//GL11.glLineWidth(2.0f);
//GL11.glBegin(GL11.GL_LINES);

PlayerEntity playerEntity = client.player;
World world = client.world;
BlockPos blockPos = new BlockPos(playerEntity.getX(), playerEntity.getY(), playerEntity.getZ());
BlockPos blockPos = new BlockPos((int)playerEntity.getX(), (int)playerEntity.getY(), (int)playerEntity.getZ());
float pitch = playerEntity.getPitch();
float yaw = playerEntity.getYaw();
double eye = playerEntity.getEyeY();
Expand All @@ -229,14 +220,12 @@ public void onInitializeClient() {
else if (itemsSimple.contains(itemStackAlt.getItem()) || itemsComplex.contains(itemStackAlt.getItem())) { mainHand = false; };

if (itemsSimple.contains(itemStack.getItem()) || itemsSimple.contains(itemStackAlt.getItem())) {
System.out.println("A");
float speed = 1.5f;
int[] color = getConfigColor();
boolean[] booleans = getConfigBooleans();
int[] integers = getConfigIntegers();
TrajectoryFabric.renderCurve(stack, buffer, camera, world, blockPos, pitch, yaw, eye, playerEntity, color, speed, 0.03f, booleans, integers, mainHand);
} else if (itemsComplex.contains(itemStack.getItem()) || itemsComplex.contains(itemStackAlt.getItem()) && ((boolean)config.get("arrowTrajectory"))) {
System.out.println("B");
} else if ((itemsComplex.contains(itemStack.getItem()) || itemsComplex.contains(itemStackAlt.getItem())) && ((boolean)config.get("arrowTrajectory"))) {
float bowMultiplier = (72000.0f - playerEntity.getItemUseTimeLeft()) / 20.0f;
bowMultiplier = (bowMultiplier * bowMultiplier + bowMultiplier * 2.0f) / 3.0f;
if (bowMultiplier > 1.0f) {
Expand All @@ -250,21 +239,15 @@ public void onInitializeClient() {
TrajectoryFabric.renderCurve(stack, buffer, camera, world, blockPos, pitch, yaw, eye, playerEntity, color, speed, 0.05f, booleans, integers, mainHand);
}


//GL11.glEnd();
tessellator.draw();
stack.pop();
RenderSystem.applyModelViewMatrix();
RenderSystem.setShaderColor(1, 1, 1, 1);

RenderSystem.disableBlend();
RenderSystem.enableTexture();
if (smoothLines) GL11.glDisable(GL11.GL_LINE_SMOOTH);
});
TrajectoryCommands.registerCommands();

}



}
10 changes: 5 additions & 5 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
"Segovo"
],
"contact": {
"homepage": "https://NA.net/",
"sources": "https://github.com/NA/NA"
"homepage": "https://github.com/segovo/TrajectoryFabric",
"sources": "https://github.com/segovo/TrajectoryFabric"
},

"license": "MIT",
"icon": "assets/modid/icon.png",
"icon": "assets/trajectoryfabric/icon.png",

"environment": "client",
"entrypoints": {
"client": [ "net.Segovo.TrajectoryFabric.TrajectoryFabric" ]
},
"mixins": [],
"depends": {
"fabricloader": ">=0.14.6",
"fabricloader": ">=0.14.21",
"fabric": "*",
"minecraft": "~1.19",
"minecraft": "~1.20.1",
"java": ">=17"
},
"suggests": {
Expand Down

0 comments on commit b423098

Please sign in to comment.