Compare commits
3
Commits
de4ccc40f0
...
dfe2c124e6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dfe2c124e6 | ||
|
|
1537d45e4d | ||
|
|
9ef6d49163 |
+27
-2
@@ -8,10 +8,10 @@ On folia, entity usually cannot move out of the tickregion, but sometimes it act
|
||||
Reference from : https://github.com/KaiijuMC/Kaiiju/blob/ver/1.20.1/patches/server/0040-Teleport-async-if-we-cannot-move-entity-off-main.patch
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index d89696bd0a0bd0b7c565b647ea97f24fb7b53ce0..58054c571757eca2e86d53706bed7a2ce5259d6f 100644
|
||||
index d89696bd0a0bd0b7c565b647ea97f24fb7b53ce0..6e09efff84414d5507a639b6c14362f32b3c5416 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -1164,6 +1164,19 @@ public abstract class Entity
|
||||
@@ -1164,6 +1164,20 @@ public abstract class Entity
|
||||
this.moveStartZ = this.getZ();
|
||||
this.moveVector = delta;
|
||||
}
|
||||
@@ -27,10 +27,35 @@ index d89696bd0a0bd0b7c565b647ea97f24fb7b53ce0..58054c571757eca2e86d53706bed7a2c
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ // Guard delta too large at the initial input
|
||||
+ // Shiroha end
|
||||
try {
|
||||
// Paper end - detailed watchdog information
|
||||
if (this.noPhysics) {
|
||||
@@ -1202,6 +1216,23 @@ public abstract class Entity
|
||||
}
|
||||
// Paper end
|
||||
|
||||
+ // Shiroha start - Fix high velocity moving issue
|
||||
+ // Filter the threads as it may be called by the chunk system worker thread
|
||||
+ if (io.nanachiyo0721.shiroha.config.modules.fixes.FoliaEntityMovingFixConfig.enabled && ca.spottedleaf.moonrise.common.util.TickThread.isTickThread()){
|
||||
+ var finalPosition = delta.add(this.position);
|
||||
+ // not NaN (Prevent incorrect checks under NaN minecarts)
|
||||
+ if (!Double.isNaN(finalPosition.x) && !Double.isNaN(finalPosition.y) && !Double.isNaN(finalPosition.z)) {
|
||||
+ // kill tick passively if it's moving out of region and we'll catch this exception
|
||||
+ if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(this.level, finalPosition)) {
|
||||
+ throw new io.nanachiyo0721.shiroha.utils.entity.EntityMoveOutOfRegionException(this, delta, moverType);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ // Guard against delta too large when it was processed above
|
||||
+ // note: following method call "maybeBackOffFromEdge" have indirect access to world data, so gurad is needed.
|
||||
+ // We ignore to check the final delta movemnt after calling "colliding" as it's clamped at least unless the AABB of the entity is
|
||||
+ // in a large scale, but it's never allowed and reasonable to have
|
||||
+ // Shiroha end
|
||||
delta = this.maybeBackOffFromEdge(delta, moverType);
|
||||
Vec3 movement = this.collide(delta);
|
||||
double movementLength = movement.lengthSqr();
|
||||
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
|
||||
index a0eb1f608a99301e0197ab1d1a6fbbb0a0be4ce0..21b3fcba9e80082ad33a4331f27758cffef163f8 100644
|
||||
--- a/net/minecraft/world/level/Level.java
|
||||
|
||||
+3
-3
@@ -30,10 +30,10 @@ index ea93ac07ec6d4e83d1d0904daf721132e2bbecc3..947413df55b972a5f866d5717fdb9e92
|
||||
|
||||
public static class IntBounds {
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 58054c571757eca2e86d53706bed7a2ce5259d6f..f97c1aa936d1a9b1ea80b701b279b24553d0ecd2 100644
|
||||
index 6e09efff84414d5507a639b6c14362f32b3c5416..dbf449e258bcd66d0182f003e029bde3b58558cc 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -4725,7 +4725,7 @@ public abstract class Entity
|
||||
@@ -4743,7 +4743,7 @@ public abstract class Entity
|
||||
portalInfoCompletable.complete(
|
||||
new TeleportTransition(destination, Vec3.atCenterOf(targetPos), Vec3.ZERO,
|
||||
90.0f, 0.0f,
|
||||
@@ -42,7 +42,7 @@ index 58054c571757eca2e86d53706bed7a2ce5259d6f..f97c1aa936d1a9b1ea80b701b279b245
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -4737,7 +4737,7 @@ public abstract class Entity
|
||||
@@ -4755,7 +4755,7 @@ public abstract class Entity
|
||||
portalInfoCompletable.complete(
|
||||
net.minecraft.world.level.block.NetherPortalBlock.createDimensionTransition(
|
||||
destination, portal, originalPortalDirection, relativePos,
|
||||
|
||||
+2
-2
@@ -25,10 +25,10 @@ index 9933e59dfebf5d731ea73585c2b08f9e4ff42d53..01a93a747d2fec6248909165bd450833
|
||||
|
||||
// Folia start - region threading
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index f97c1aa936d1a9b1ea80b701b279b24553d0ecd2..98ce2b377e125c1de123a406c3978f495c5023db 100644
|
||||
index dbf449e258bcd66d0182f003e029bde3b58558cc..34dff91f9694b6a884bac2039891d05fdec7c12c 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -4744,10 +4744,10 @@ public abstract class Entity
|
||||
@@ -4762,10 +4762,10 @@ public abstract class Entity
|
||||
);
|
||||
|
||||
// kick off search for existing portal or creation
|
||||
|
||||
+5
-5
@@ -8,10 +8,10 @@ As part of: Kaiiju (https://github.com/KaiijuMC/Kaiiju/blob/c2b7aec8f7b418a39a2e
|
||||
Licensed under: GPL-3.0 (https://github.com/KaiijuMC/Kaiiju/blob/c2b7aec8f7b418a39a2ec408e6411e6f752379da/LICENSE)
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 98ce2b377e125c1de123a406c3978f495c5023db..9ed6850abef3afed5694f4862c18b39fbb97d3f2 100644
|
||||
index 34dff91f9694b6a884bac2039891d05fdec7c12c..453261efff85beec55fb0f9796be0269470670af 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -4642,15 +4642,19 @@ public abstract class Entity
|
||||
@@ -4660,15 +4660,19 @@ public abstract class Entity
|
||||
targetPos, 16, // load 16 blocks to be safe from block physics
|
||||
ca.spottedleaf.concurrentutil.util.Priority.HIGH,
|
||||
(chunks) -> {
|
||||
@@ -35,7 +35,7 @@ index 98ce2b377e125c1de123a406c3978f495c5023db..9ed6850abef3afed5694f4862c18b39f
|
||||
TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET),
|
||||
org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_PORTAL,
|
||||
TeleportTransition.PassengerTeleportationMode.POSITION_RIDER
|
||||
@@ -4666,13 +4670,17 @@ public abstract class Entity
|
||||
@@ -4684,13 +4688,17 @@ public abstract class Entity
|
||||
ca.spottedleaf.concurrentutil.util.Priority.HIGH,
|
||||
(chunks) -> {
|
||||
BlockPos adjustedSpawn = destination.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, spawnPos);
|
||||
@@ -56,7 +56,7 @@ index 98ce2b377e125c1de123a406c3978f495c5023db..9ed6850abef3afed5694f4862c18b39f
|
||||
TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET),
|
||||
org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_PORTAL,
|
||||
TeleportTransition.PassengerTeleportationMode.POSITION_RIDER
|
||||
@@ -4851,6 +4859,10 @@ public abstract class Entity
|
||||
@@ -4869,6 +4877,10 @@ public abstract class Entity
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ index 98ce2b377e125c1de123a406c3978f495c5023db..9ed6850abef3afed5694f4862c18b39f
|
||||
Vec3 initialPosition = this.position();
|
||||
ChunkPos initialPositionChunk = new ChunkPos(
|
||||
ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkX(initialPosition),
|
||||
@@ -4914,9 +4926,14 @@ public abstract class Entity
|
||||
@@ -4932,9 +4944,14 @@ public abstract class Entity
|
||||
info.postTeleportTransition().onTransition(teleported);
|
||||
}
|
||||
|
||||
|
||||
@@ -171,10 +171,10 @@ index f03fa06c0ba56f7f5e1e45bc1568a490751efde3..eee1c14249addbf4714df733870da974
|
||||
+ // KioCG end
|
||||
}
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 9ed6850abef3afed5694f4862c18b39fbb97d3f2..66593eb947035bd9489c4d31a0e9156c1c81b464 100644
|
||||
index 453261efff85beec55fb0f9796be0269470670af..b22211aaa7c2ec9b96a6de6d84200593b838cecc 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -6439,4 +6439,6 @@ public abstract class Entity
|
||||
@@ -6457,4 +6457,6 @@ public abstract class Entity
|
||||
return ((ServerLevel) this.level()).isPositionEntityTicking(this.blockPosition());
|
||||
}
|
||||
// Paper end
|
||||
|
||||
+3
-3
@@ -240,7 +240,7 @@ index 6e08d50794c4af4405f3e164a3fd46f376b3f78f..dd2d0940eece3e85078e574f66f71a4c
|
||||
|
||||
int getContainerSize();
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 66593eb947035bd9489c4d31a0e9156c1c81b464..280d6ff1fcbfb74d194a8ade94c2af02fe2cd41b 100644
|
||||
index b22211aaa7c2ec9b96a6de6d84200593b838cecc..b339904e8894774321c322f15842a41ede87ee4e 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -324,7 +324,7 @@ public abstract class Entity
|
||||
@@ -252,7 +252,7 @@ index 66593eb947035bd9489c4d31a0e9156c1c81b464..280d6ff1fcbfb74d194a8ade94c2af02
|
||||
private final VecDeltaCodec packetPositionCodec = new VecDeltaCodec();
|
||||
public boolean needsSync;
|
||||
public boolean syncPosition;
|
||||
@@ -4469,11 +4469,13 @@ public abstract class Entity
|
||||
@@ -4487,11 +4487,13 @@ public abstract class Entity
|
||||
}
|
||||
|
||||
protected Entity transformForAsyncTeleport(ServerLevel destination, Vec3 pos, Float yaw, Float pitch, Vec3 velocity) {
|
||||
@@ -266,7 +266,7 @@ index 66593eb947035bd9489c4d31a0e9156c1c81b464..280d6ff1fcbfb74d194a8ade94c2af02
|
||||
if (copy instanceof net.minecraft.world.entity.boss.enderdragon.EnderDragon dragon) dragon.syncDragonPartsAfterTeleportTransform(); // Shiroha - Fix dragon part desync
|
||||
// vanilla code used to call remove _after_ copying, and some stuff is required to be after copy - so add hook here
|
||||
// for example, clearing of inventory after switching dimensions
|
||||
@@ -6040,8 +6042,29 @@ public abstract class Entity
|
||||
@@ -6058,8 +6060,29 @@ public abstract class Entity
|
||||
this.setBoundingBox(this.makeBoundingBox());
|
||||
}
|
||||
// Paper end - Block invalid positions and bounding box
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ VMP (https://github.com/RelativityMC/VMP-fabric)
|
||||
Licensed under: MIT (https://opensource.org/licenses/MIT)
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 280d6ff1fcbfb74d194a8ade94c2af02fe2cd41b..ccd7cfb1db04628adda7346ee7f1825c15f70afd 100644
|
||||
index b339904e8894774321c322f15842a41ede87ee4e..bf55500a27000b22de7e17bf31993d698945bbef 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -1153,8 +1153,14 @@ public abstract class Entity
|
||||
@@ -28,7 +28,7 @@ index 280d6ff1fcbfb74d194a8ade94c2af02fe2cd41b..ccd7cfb1db04628adda7346ee7f1825c
|
||||
final Vec3 originalMovement = delta; // Paper - Expose pre-collision velocity
|
||||
// Paper start - detailed watchdog information
|
||||
ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread("Cannot move an entity off-main");
|
||||
@@ -5534,6 +5540,11 @@ public abstract class Entity
|
||||
@@ -5552,6 +5558,11 @@ public abstract class Entity
|
||||
}
|
||||
|
||||
public final void setBoundingBox(final AABB bb) {
|
||||
|
||||
+2
-2
@@ -20,10 +20,10 @@ As part of: Akarin (https://github.com/Akarin-project/Akarin)
|
||||
Licensed under: GPL-3.0-only (https://www.gnu.org/licenses/gpl-3.0.html)
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index ccd7cfb1db04628adda7346ee7f1825c15f70afd..8c0f34566f04fdf4d8b595250d7ea52cbd62b7c9 100644
|
||||
index bf55500a27000b22de7e17bf31993d698945bbef..4f863e68fb2323a442f868a2531a9eda816a2555 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -2439,8 +2439,8 @@ public abstract class Entity
|
||||
@@ -2457,8 +2457,8 @@ public abstract class Entity
|
||||
}
|
||||
|
||||
public void push(final Entity entity) {
|
||||
|
||||
+2
-2
@@ -7,10 +7,10 @@ License: GPL-3.0-only (https://www.gnu.org/licenses/gpl-3.0.html)
|
||||
Gale - https://github.com/GaleMC/Gale
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 8c0f34566f04fdf4d8b595250d7ea52cbd62b7c9..18087b6f3f3152c1a9699985e28209a9231e57cd 100644
|
||||
index 4f863e68fb2323a442f868a2531a9eda816a2555..ecd17c6bdf9668842879aa687505afc7c7430dad 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -1300,8 +1300,17 @@ public abstract class Entity
|
||||
@@ -1318,8 +1318,17 @@ public abstract class Entity
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import io.nanachiyo0721.shiroha.api.config.ShirohaConfigsInstance;
|
||||
import io.nanachiyo0721.shiroha.api.config.ConfigDataPair;
|
||||
import io.nanachiyo0721.shiroha.commands.config.ConfigCommand;
|
||||
import io.nanachiyo0721.shiroha.enums.EnumConfigCategory;
|
||||
import io.nanachiyo0721.shiroha.utils.ClassLoadUtil;
|
||||
import io.nanachiyo0721.shiroha.utils.ClassScanUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
@@ -284,7 +284,7 @@ public class ConfigsInstance implements ShirohaConfigsInstance {
|
||||
*/
|
||||
private void instanceAllModule() throws NoSuchMethodException, InvocationTargetException,
|
||||
InstantiationException, IllegalAccessException {
|
||||
for (Class<?> clazz : ClassLoadUtil.getClasses(pack, loader)) {
|
||||
for (Class<?> clazz : ClassScanUtil.scanClassesUnder(pack, loader)) {
|
||||
if (IConfigModule.class.isAssignableFrom(clazz)) {
|
||||
allInstanced.put((IConfigModule) clazz.getConstructor().newInstance(), null);
|
||||
}
|
||||
|
||||
+1
-1
@@ -1417,7 +1417,7 @@ public class BufferedLinearRegionFile implements io.nanachiyo0721.shiroha.data.R
|
||||
}
|
||||
}
|
||||
|
||||
private void markBucketsSynced(long[] syncedBucketEpochs) {
|
||||
private void markBucketsSynced(long @NonNull [] syncedBucketEpochs) {
|
||||
for (int i = 0; i < syncedBucketEpochs.length; i++) {
|
||||
// note: a dirty bucket always has a write epoch >= 1, so 0 = untouched
|
||||
if (syncedBucketEpochs[i] != 0L) {
|
||||
|
||||
+7
-6
@@ -1,6 +1,7 @@
|
||||
package io.nanachiyo0721.shiroha.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -15,10 +16,10 @@ import java.util.Set;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
public class ClassLoadUtil {
|
||||
public static @NotNull Collection<Class<?>> getClasses(String pack, ClassLoader loader) {
|
||||
public class ClassScanUtil {
|
||||
public static @NotNull Collection<Class<?>> scanClassesUnder(String packag3, ClassLoader loader) {
|
||||
Set<Class<?>> classes = new HashSet<>();
|
||||
String packageDirName = pack.replace('.', '/');
|
||||
String packageDirName = packag3.replace('.', '/');
|
||||
Enumeration<URL> dirs;
|
||||
|
||||
try {
|
||||
@@ -28,13 +29,13 @@ public class ClassLoadUtil {
|
||||
String protocol = url.getProtocol();
|
||||
if ("file".equals(protocol)) {
|
||||
String filePath = URLDecoder.decode(url.getFile(), StandardCharsets.UTF_8);
|
||||
findClassesInPackageByFile(pack, filePath, classes);
|
||||
findClassesInPackageByFile(packag3, filePath, classes);
|
||||
} else if ("jar".equals(protocol)) {
|
||||
JarFile jar;
|
||||
try {
|
||||
jar = ((JarURLConnection) url.openConnection()).getJarFile();
|
||||
Enumeration<JarEntry> entries = jar.entries();
|
||||
findClassesInPackageByJar(pack, entries, packageDirName, classes);
|
||||
findClassesInPackageByJar(packag3, entries, packageDirName, classes);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -71,7 +72,7 @@ public class ClassLoadUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static void findClassesInPackageByJar(String packageName, Enumeration<JarEntry> entries, String packageDirName, Set<Class<?>> classes) {
|
||||
private static void findClassesInPackageByJar(String packageName, @NonNull Enumeration<JarEntry> entries, String packageDirName, Set<Class<?>> classes) {
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
String name = entry.getName();
|
||||
@@ -1,296 +0,0 @@
|
||||
package io.nanachiyo0721.shiroha.utils;
|
||||
|
||||
import io.nanachiyo0721.shiroha.config.modules.optimizations.FrustumFilteringTrackerConfig;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
public class Culling {
|
||||
private static final float VERTICAL_FOV_RAD = (float) Math.toRadians(120);
|
||||
private static final float ASPECT = 1.0f;
|
||||
private static final float NEAR = 0.1f;
|
||||
private static final float FAR = 32.0f;
|
||||
|
||||
private float fov;
|
||||
private float aspect;
|
||||
private float near;
|
||||
private float far;
|
||||
|
||||
private final Player player;
|
||||
private float[] planes;
|
||||
|
||||
public static Culling fromConfig(Player player) {
|
||||
return new Builder()
|
||||
.fov((float) Math.toRadians(FrustumFilteringTrackerConfig.camera_fov))
|
||||
.near(NEAR)
|
||||
.aspect((float) FrustumFilteringTrackerConfig.aspect)
|
||||
.far(FAR)
|
||||
.build(player);
|
||||
}
|
||||
|
||||
@Contract(value = "_ -> new", pure = true)
|
||||
public static @NonNull Culling newDefault(Player player) {
|
||||
return fromBuilder(new Builder(), player);
|
||||
}
|
||||
|
||||
@Contract(value = "_, _ -> new", pure = true)
|
||||
public static @NonNull Culling fromBuilder(@NonNull Builder builder, Player player) {
|
||||
return new Culling(builder.fov, builder.aspect, builder.near, builder.far, player);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private float fov;
|
||||
private float aspect;
|
||||
private float near;
|
||||
private float far;
|
||||
|
||||
|
||||
public Builder() {
|
||||
this.fov = VERTICAL_FOV_RAD;
|
||||
this.aspect = ASPECT;
|
||||
this.near = NEAR;
|
||||
this.far = FAR;
|
||||
}
|
||||
|
||||
public Builder fov(float fov) {
|
||||
this.fov = fov;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder aspect(float aspect) {
|
||||
this.aspect = aspect;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder near(float near) {
|
||||
this.near = near;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder far(float far) {
|
||||
this.far = far;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Culling build(Player player) {
|
||||
return fromBuilder(this, player);
|
||||
}
|
||||
}
|
||||
|
||||
public Culling(float fov, float aspect, float near, float far, Player player) {
|
||||
this.fov = fov;
|
||||
this.aspect = aspect;
|
||||
this.near = near;
|
||||
this.far = far;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static float @NonNull [] buildFrustumPlanes(
|
||||
float eyeX, float eyeY, float eyeZ,
|
||||
float forwardX, float forwardY, float forwardZ,
|
||||
float upX, float upY, float upZ,
|
||||
float verticalFovRad, float aspect, float nearDist, float farDist) {
|
||||
float lenF = (float) Math.sqrt(forwardX * forwardX + forwardY * forwardY + forwardZ * forwardZ);
|
||||
float fx = forwardX / lenF;
|
||||
float fy = forwardY / lenF;
|
||||
float fz = forwardZ / lenF;
|
||||
|
||||
float rx = fy * upZ - fz * upY;
|
||||
float ry = fz * upX - fx * upZ;
|
||||
float rz = fx * upY - fy * upX;
|
||||
float lenR = (float) Math.sqrt(rx * rx + ry * ry + rz * rz);
|
||||
|
||||
if (lenR < 1.0e-4f) {
|
||||
float fallbackUpX = 0.0f, fallbackUpY = 0.0f, fallbackUpZ = 1.0f;
|
||||
if (Math.abs(fz) > 0.999f) {
|
||||
fallbackUpX = 1.0f;
|
||||
fallbackUpY = 0.0f;
|
||||
fallbackUpZ = 0.0f;
|
||||
}
|
||||
rx = fy * fallbackUpZ - fz * fallbackUpY;
|
||||
ry = fz * fallbackUpX - fx * fallbackUpZ;
|
||||
rz = fx * fallbackUpY - fy * fallbackUpX;
|
||||
lenR = (float) Math.sqrt(rx * rx + ry * ry + rz * rz);
|
||||
}
|
||||
|
||||
rx /= lenR;
|
||||
ry /= lenR;
|
||||
rz /= lenR;
|
||||
|
||||
float ux = ry * fz - rz * fy;
|
||||
float uy = rz * fx - rx * fz;
|
||||
float uz = rx * fy - ry * fx;
|
||||
float lenU = (float) Math.sqrt(ux * ux + uy * uy + uz * uz);
|
||||
ux /= lenU;
|
||||
uy /= lenU;
|
||||
uz /= lenU;
|
||||
|
||||
float tanHalf = (float) Math.tan(verticalFovRad * 0.5);
|
||||
float halfVNear = tanHalf * nearDist;
|
||||
float halfHNear = halfVNear * aspect;
|
||||
float halfVFar = tanHalf * farDist;
|
||||
float halfHFar = halfVFar * aspect;
|
||||
|
||||
float nearCX = eyeX + fx * nearDist;
|
||||
float nearCY = eyeY + fy * nearDist;
|
||||
float nearCZ = eyeZ + fz * nearDist;
|
||||
|
||||
float farCX = eyeX + fx * farDist;
|
||||
float farCY = eyeY + fy * farDist;
|
||||
float farCZ = eyeZ + fz * farDist;
|
||||
|
||||
float ntlX = nearCX + ux * halfVNear - rx * halfHNear;
|
||||
float ntlY = nearCY + uy * halfVNear - ry * halfHNear;
|
||||
float ntlZ = nearCZ + uz * halfVNear - rz * halfHNear;
|
||||
|
||||
float ntrX = nearCX + ux * halfVNear + rx * halfHNear;
|
||||
float ntrY = nearCY + uy * halfVNear + ry * halfHNear;
|
||||
float ntrZ = nearCZ + uz * halfVNear + rz * halfHNear;
|
||||
|
||||
float nblX = nearCX - ux * halfVNear - rx * halfHNear;
|
||||
float nblY = nearCY - uy * halfVNear - ry * halfHNear;
|
||||
float nblZ = nearCZ - uz * halfVNear - rz * halfHNear;
|
||||
|
||||
float nbrX = nearCX - ux * halfVNear + rx * halfHNear;
|
||||
float nbrY = nearCY - uy * halfVNear + ry * halfHNear;
|
||||
float nbrZ = nearCZ - uz * halfVNear + rz * halfHNear;
|
||||
|
||||
float ftlX = farCX + ux * halfVFar - rx * halfHFar;
|
||||
float ftlY = farCY + uy * halfVFar - ry * halfHFar;
|
||||
float ftlZ = farCZ + uz * halfVFar - rz * halfHFar;
|
||||
|
||||
float ftrX = farCX + ux * halfVFar + rx * halfHFar;
|
||||
float ftrY = farCY + uy * halfVFar + ry * halfHFar;
|
||||
float ftrZ = farCZ + uz * halfVFar + rz * halfHFar;
|
||||
|
||||
float fbrX = farCX - ux * halfVFar + rx * halfHFar;
|
||||
float fbrY = farCY - uy * halfVFar + ry * halfHFar;
|
||||
float fbrZ = farCZ - uz * halfVFar + rz * halfHFar;
|
||||
|
||||
float midDist = (nearDist + farDist) * 0.5f;
|
||||
float refX = eyeX + fx * midDist;
|
||||
float refY = eyeY + fy * midDist;
|
||||
float refZ = eyeZ + fz * midDist;
|
||||
|
||||
float[] planes = new float[24];
|
||||
|
||||
int idx = 0;
|
||||
|
||||
idx = computePlane(planes, idx,
|
||||
eyeX, eyeY, eyeZ,
|
||||
ntlX, ntlY, ntlZ,
|
||||
nblX, nblY, nblZ,
|
||||
refX, refY, refZ);
|
||||
|
||||
idx = computePlane(planes, idx,
|
||||
eyeX, eyeY, eyeZ,
|
||||
nbrX, nbrY, nbrZ,
|
||||
ntrX, ntrY, ntrZ,
|
||||
refX, refY, refZ);
|
||||
|
||||
idx = computePlane(planes, idx,
|
||||
eyeX, eyeY, eyeZ,
|
||||
nblX, nblY, nblZ,
|
||||
nbrX, nbrY, nbrZ,
|
||||
refX, refY, refZ);
|
||||
|
||||
idx = computePlane(planes, idx,
|
||||
eyeX, eyeY, eyeZ,
|
||||
ntrX, ntrY, ntrZ,
|
||||
ntlX, ntlY, ntlZ,
|
||||
refX, refY, refZ);
|
||||
|
||||
idx = computePlane(planes, idx,
|
||||
ntlX, ntlY, ntlZ,
|
||||
ntrX, ntrY, ntrZ,
|
||||
nblX, nblY, nblZ,
|
||||
refX, refY, refZ);
|
||||
|
||||
idx = computePlane(planes, idx,
|
||||
ftrX, ftrY, ftrZ,
|
||||
ftlX, ftlY, ftlZ,
|
||||
fbrX, fbrY, fbrZ,
|
||||
refX, refY, refZ);
|
||||
|
||||
return planes;
|
||||
}
|
||||
|
||||
private static int computePlane(float[] out, int start,
|
||||
float p0x, float p0y, float p0z,
|
||||
float p1x, float p1y, float p1z,
|
||||
float p2x, float p2y, float p2z,
|
||||
float refX, float refY, float refZ) {
|
||||
float e1x = p1x - p0x, e1y = p1y - p0y, e1z = p1z - p0z;
|
||||
float e2x = p2x - p0x, e2y = p2y - p0y, e2z = p2z - p0z;
|
||||
|
||||
float nx = e1y * e2z - e1z * e2y;
|
||||
float ny = e1z * e2x - e1x * e2z;
|
||||
float nz = e1x * e2y - e1y * e2x;
|
||||
|
||||
float d = -(nx * p0x + ny * p0y + nz * p0z);
|
||||
float val = nx * refX + ny * refY + nz * refZ + d;
|
||||
|
||||
if (val < 0.0f) {
|
||||
nx = -nx;
|
||||
ny = -ny;
|
||||
nz = -nz;
|
||||
d = -d;
|
||||
}
|
||||
|
||||
float len = (float) Math.sqrt(nx * nx + ny * ny + nz * nz);
|
||||
nx /= len;
|
||||
ny /= len;
|
||||
nz /= len;
|
||||
|
||||
d = -(nx * p0x + ny * p0y + nz * p0z);
|
||||
|
||||
out[start] = nx;
|
||||
out[start + 1] = ny;
|
||||
out[start + 2] = nz;
|
||||
out[start + 3] = d;
|
||||
|
||||
return start + 4;
|
||||
}
|
||||
|
||||
public void apply(@NonNull Builder builder) {
|
||||
this.fov = builder.fov;
|
||||
this.aspect = builder.aspect;
|
||||
this.near = builder.near;
|
||||
this.far = builder.far;
|
||||
}
|
||||
|
||||
public void updateFrustum() {
|
||||
Vec3 eye = this.player.getEyePosition();
|
||||
Vec3 look = this.player.getLookAngle();
|
||||
this.planes = buildFrustumPlanes(
|
||||
(float) eye.x, (float) eye.y, (float) eye.z,
|
||||
(float) look.x, (float) look.y, (float) look.z,
|
||||
0.0f, 1.0f, 0.0f,
|
||||
this.fov, this.aspect, this.near, this.far
|
||||
);
|
||||
}
|
||||
|
||||
public void far(float far) {
|
||||
this.far = far;
|
||||
}
|
||||
|
||||
public boolean isVisibleFor(@NonNull AABB box) {
|
||||
final float[] planes = this.planes;
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int base = i << 2;
|
||||
float nx = planes[base], ny = planes[base+1], nz = planes[base+2], d = planes[base+3];
|
||||
float px = (nx >= 0) ? (float) box.maxX : (float) box.minX;
|
||||
float py = (ny >= 0) ? (float) box.maxY : (float) box.minY;
|
||||
float pz = (nz >= 0) ? (float) box.maxZ : (float) box.minZ;
|
||||
|
||||
if (nx * px + ny * py + nz * pz + d < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
package io.nanachiyo0721.shiroha.utils;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.generator.BiomeProvider;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.PluginBase;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
import org.bukkit.plugin.PluginLogger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
public class NullPlugin extends PluginBase {
|
||||
private final String pluginName;
|
||||
private boolean enabled = true;
|
||||
private PluginDescriptionFile pdf;
|
||||
|
||||
public NullPlugin() {
|
||||
this.pluginName = "Minecraft";
|
||||
pdf = new PluginDescriptionFile(pluginName, "1.0", "nms");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginDescriptionFile getDescription() {
|
||||
return pdf;
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public io.papermc.paper.plugin.configuration.PluginMeta getPluginMeta() {
|
||||
return pdf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileConfiguration getConfig() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public InputStream getResource(String filename) {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveConfig() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveDefaultConfig() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveResource(String resourcePath, boolean replace) {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginLogger getLogger() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginLoader getPluginLoader() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server getServer() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNaggable() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNaggable(boolean canNag) {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BiomeProvider getDefaultBiomeProvider(@NotNull String worldName, @Nullable String id) {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
// Paper start - lifecycle events
|
||||
@Override
|
||||
public @NotNull io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager<org.bukkit.plugin.Plugin> getLifecycleManager() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
// Paper end - lifecycle events
|
||||
}
|
||||
Reference in New Issue
Block a user