geforkt von Mirrors/Paper
ac554ad46d
Updated Upstream (Bukkit/CraftBukkit) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: fa99e752 PR-1007: Add ItemMeta#getAsComponentString() 94a91782 Fix copy-pasted BlockType.Typed documentation 9b34ac8c Largely restore deprecated PotionData API 51a6449b PR-1008: Deprecate ITEMS_TOOLS, removed in 1.20.5 702d15fe Fix Javadoc reference 42f6cdf4 PR-919: Add internal ItemType and BlockType, delegate Material methods to them 237bb37b SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent 035ea146 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it 8c7880fb PR-1004: Improve field rename handling and centralize conversion between bukkit and string more 87c90e93 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent CraftBukkit Changes: 4af0f22e8 SPIGOT-7664: Item meta should prevail over block states c2ccc46ec SPIGOT-7666: Fix access to llama and horse special slot 124ac66d7 SPIGOT-7665: Fix ThrownPotion#getEffects() implementation only bringing custom effects 66f1f439a Restore null page behaviour of signed books even though not strictly allowed by API 6118e5398 Fix regression listening to minecraft:brand custom payloads c1a26b366 Fix unnecessary and potential not thread-safe chat visibility check 12360a7ec Remove unused imports 147b098b4 PR-1397: Add ItemMeta#getAsComponentString() 428aefe0e Largely restore deprecated PotionData API afe5b5ee9 PR-1275: Add internal ItemType and BlockType, delegate Material methods to them 8afeafa7d SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent 4e7d749d4 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it 441880757 Support both entity_data and bucket_entity_data on axolotl/fish buckets 0e22fdd1e Fix custom direct BlockState being not correctly set in DamageSource f2182ed47 SPIGOT-7659: TropicalFishBucketMeta should use BUCKET_ENTITY_DATA 2a6207fe1 PR-1393: Improve field rename handling and centralize conversion between bukkit and string more c024a5039 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent 741b84480 PR-1390: Improve internal handling of damage sources 0364df4e1 SPIGOT-7657: Error when loading angry entities
117 Zeilen
8.3 KiB
Diff
117 Zeilen
8.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: TonytheMacaroni <tonythemacaroni123@gmail.com>
|
|
Date: Wed, 6 Sep 2023 19:24:16 -0400
|
|
Subject: [PATCH] Add predicate for blocks when raytracing
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/BlockGetter.java b/src/main/java/net/minecraft/world/level/BlockGetter.java
|
|
index c978f3b2d42f512e982f289e76c2422e41b7eec6..bb8e962e63c7a2d931f9bd7f7c002aa35cfa5fd3 100644
|
|
--- a/src/main/java/net/minecraft/world/level/BlockGetter.java
|
|
+++ b/src/main/java/net/minecraft/world/level/BlockGetter.java
|
|
@@ -70,6 +70,12 @@ public interface BlockGetter extends LevelHeightAccessor {
|
|
|
|
// CraftBukkit start - moved block handling into separate method for use by Block#rayTrace
|
|
default BlockHitResult clip(ClipContext raytrace1, BlockPos blockposition) {
|
|
+ // Paper start - Add predicate for blocks when raytracing
|
|
+ return clip(raytrace1, blockposition, null);
|
|
+ }
|
|
+
|
|
+ default BlockHitResult clip(ClipContext raytrace1, BlockPos blockposition, java.util.function.Predicate<? super org.bukkit.block.Block> canCollide) {
|
|
+ // Paper end - Add predicate for blocks when raytracing
|
|
// Paper start - Prevent raytrace from loading chunks
|
|
BlockState iblockdata = this.getBlockStateIfLoaded(blockposition);
|
|
if (iblockdata == null) {
|
|
@@ -79,7 +85,7 @@ public interface BlockGetter extends LevelHeightAccessor {
|
|
return BlockHitResult.miss(raytrace1.getTo(), Direction.getNearest(vec3d.x, vec3d.y, vec3d.z), BlockPos.containing(raytrace1.getTo()));
|
|
}
|
|
// Paper end - Prevent raytrace from loading chunks
|
|
- if (iblockdata.isAir()) return null; // Paper - Perf: optimise air cases
|
|
+ if (iblockdata.isAir() || (canCollide != null && this instanceof LevelAccessor levelAccessor && !canCollide.test(org.bukkit.craftbukkit.block.CraftBlock.at(levelAccessor, blockposition)))) return null; // Paper - Perf: optimise air cases & check canCollide predicate
|
|
FluidState fluid = iblockdata.getFluidState(); // Paper - Perf: don't need to go to world state again
|
|
Vec3 vec3d = raytrace1.getFrom();
|
|
Vec3 vec3d1 = raytrace1.getTo();
|
|
@@ -95,8 +101,14 @@ public interface BlockGetter extends LevelHeightAccessor {
|
|
// CraftBukkit end
|
|
|
|
default BlockHitResult clip(ClipContext context) {
|
|
+ // Paper start - Add predicate for blocks when raytracing
|
|
+ return clip(context, (java.util.function.Predicate<org.bukkit.block.Block>) null);
|
|
+ }
|
|
+
|
|
+ default BlockHitResult clip(ClipContext context, java.util.function.Predicate<? super org.bukkit.block.Block> canCollide) {
|
|
+ // Paper end - Add predicate for blocks when raytracing
|
|
return (BlockHitResult) BlockGetter.traverseBlocks(context.getFrom(), context.getTo(), context, (raytrace1, blockposition) -> {
|
|
- return this.clip(raytrace1, blockposition); // CraftBukkit - moved into separate method
|
|
+ return this.clip(raytrace1, blockposition, canCollide); // CraftBukkit - moved into separate method // Paper - Add predicate for blocks when raytracing
|
|
}, (raytrace1) -> {
|
|
Vec3 vec3d = raytrace1.getFrom().subtract(raytrace1.getTo());
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
index 18c1cceb9e8b2873b24134a9e012633616634aae..3abb776f546edb84307f374943427be02dc4c911 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -1136,9 +1136,15 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
@Override
|
|
public RayTraceResult rayTraceEntities(Location start, Vector direction, double maxDistance, double raySize, Predicate<? super Entity> filter) {
|
|
+ // Paper start - Add predicate for blocks when raytracing
|
|
+ return rayTraceEntities((io.papermc.paper.math.Position) start, direction, maxDistance, raySize, filter);
|
|
+ }
|
|
+
|
|
+ public RayTraceResult rayTraceEntities(io.papermc.paper.math.Position start, Vector direction, double maxDistance, double raySize, Predicate<? super Entity> filter) {
|
|
Preconditions.checkArgument(start != null, "Location start cannot be null");
|
|
- Preconditions.checkArgument(this.equals(start.getWorld()), "Location start cannot be in a different world");
|
|
- start.checkFinite();
|
|
+ Preconditions.checkArgument(!(start instanceof Location location) || this.equals(location.getWorld()), "Location start cannot be in a different world");
|
|
+ Preconditions.checkArgument(start.isFinite(), "Location start is not finite");
|
|
+ // Paper end - Add predicate for blocks when raytracing
|
|
|
|
Preconditions.checkArgument(direction != null, "Vector direction cannot be null");
|
|
direction.checkFinite();
|
|
@@ -1188,9 +1194,16 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
@Override
|
|
public RayTraceResult rayTraceBlocks(Location start, Vector direction, double maxDistance, FluidCollisionMode fluidCollisionMode, boolean ignorePassableBlocks) {
|
|
+ // Paper start - Add predicate for blocks when raytracing
|
|
+ return this.rayTraceBlocks(start, direction, maxDistance, fluidCollisionMode, ignorePassableBlocks, null);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public RayTraceResult rayTraceBlocks(io.papermc.paper.math.Position start, Vector direction, double maxDistance, FluidCollisionMode fluidCollisionMode, boolean ignorePassableBlocks, Predicate<? super Block> canCollide) {
|
|
Preconditions.checkArgument(start != null, "Location start cannot be null");
|
|
- Preconditions.checkArgument(this.equals(start.getWorld()), "Location start cannot be in a different world");
|
|
- start.checkFinite();
|
|
+ Preconditions.checkArgument(!(start instanceof Location location) || this.equals(location.getWorld()), "Location start cannot be in a different world");
|
|
+ Preconditions.checkArgument(start.isFinite(), "Location start is not finite");
|
|
+ // Paper end - Add predicate for blocks when raytracing
|
|
|
|
Preconditions.checkArgument(direction != null, "Vector direction cannot be null");
|
|
direction.checkFinite();
|
|
@@ -1203,16 +1216,23 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
}
|
|
|
|
Vector dir = direction.clone().normalize().multiply(maxDistance);
|
|
- Vec3 startPos = CraftLocation.toVec3D(start);
|
|
+ Vec3 startPos = io.papermc.paper.util.MCUtil.toVec3(start); // Paper - Add predicate for blocks when raytracing
|
|
Vec3 endPos = startPos.add(dir.getX(), dir.getY(), dir.getZ());
|
|
- HitResult nmsHitResult = this.getHandle().clip(new ClipContext(startPos, endPos, ignorePassableBlocks ? ClipContext.Block.COLLIDER : ClipContext.Block.OUTLINE, CraftFluidCollisionMode.toNMS(fluidCollisionMode), CollisionContext.empty()));
|
|
+ HitResult nmsHitResult = this.getHandle().clip(new ClipContext(startPos, endPos, ignorePassableBlocks ? ClipContext.Block.COLLIDER : ClipContext.Block.OUTLINE, CraftFluidCollisionMode.toNMS(fluidCollisionMode), CollisionContext.empty()), canCollide); // Paper - Add predicate for blocks when raytracing
|
|
|
|
return CraftRayTraceResult.fromNMS(this, nmsHitResult);
|
|
}
|
|
|
|
@Override
|
|
public RayTraceResult rayTrace(Location start, Vector direction, double maxDistance, FluidCollisionMode fluidCollisionMode, boolean ignorePassableBlocks, double raySize, Predicate<? super Entity> filter) {
|
|
- RayTraceResult blockHit = this.rayTraceBlocks(start, direction, maxDistance, fluidCollisionMode, ignorePassableBlocks);
|
|
+ // Paper start - Add predicate for blocks when raytracing
|
|
+ return this.rayTrace(start, direction, maxDistance, fluidCollisionMode, ignorePassableBlocks, raySize, filter, null);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public RayTraceResult rayTrace(io.papermc.paper.math.Position start, Vector direction, double maxDistance, FluidCollisionMode fluidCollisionMode, boolean ignorePassableBlocks, double raySize, Predicate<? super Entity> filter, Predicate<? super Block> canCollide) {
|
|
+ RayTraceResult blockHit = this.rayTraceBlocks(start, direction, maxDistance, fluidCollisionMode, ignorePassableBlocks, canCollide);
|
|
+ // Paper end - Add predicate for blocks when raytracing
|
|
Vector startVec = null;
|
|
double blockHitDistance = maxDistance;
|
|
|