Skip to content

Commit

Permalink
Add MinecraftClientUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Sep 29, 2023
1 parent 64864b1 commit 8349b7c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public void load(Map<ResourceLocation, String> scripts) {

scope.put("MTRClientData", scope, new NativeJavaClass(scope, ClientData.class));

scope.put("MinecraftClient", scope, new NativeJavaClass(scope, MinecraftClientUtil.class));

try {
String[] classesToLoad = {
"util.AddParticleHelper",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cn.zbx1425.mtrsteamloco.render.scripting.util;

import cn.zbx1425.sowcer.math.Vector3f;
import net.minecraft.client.Minecraft;

public class MinecraftClientUtil {

public static boolean worldIsRaining() {
return Minecraft.getInstance().level != null
&& Minecraft.getInstance().level.isRaining();
}

public static boolean worldIsRainingAt(Vector3f pos) {
return Minecraft.getInstance().level != null
&& Minecraft.getInstance().level.isRainingAt(pos.toBlockPos());
}

public static int worldDayTime() {
return Minecraft.getInstance().level != null
? (int) Minecraft.getInstance().level.getDayTime() : 0;
}
}
5 changes: 5 additions & 0 deletions common/src/main/java/cn/zbx1425/sowcer/math/Vector3f.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.zbx1425.sowcer.math;

import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;

public class Vector3f {
Expand Down Expand Up @@ -165,6 +166,10 @@ public float distanceSq(Vector3f other) {
return (float)(dx * dx + dy * dy + dz * dz);
}

public BlockPos toBlockPos() {
return new BlockPos(Mth.floor(x()), Mth.floor(y()), Mth.floor(z()));
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down

0 comments on commit 8349b7c

Please sign in to comment.