2018-09-04 01:59:54 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: BillyGalbreath <Blake.Galbreath@GMail.com>
|
|
|
|
Date: Mon, 3 Sep 2018 18:20:03 -0500
|
|
|
|
Subject: [PATCH] Add ray tracing methods to LivingEntity
|
|
|
|
|
|
|
|
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/EntityLiving.java b/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
2020-05-06 11:48:49 +02:00
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
2021-03-16 08:19:45 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
2018-09-04 01:59:54 +02:00
|
|
|
@@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity {
|
2020-01-22 03:02:07 +01:00
|
|
|
this.broadcastItemBreak(enumhand == EnumHand.MAIN_HAND ? EnumItemSlot.MAINHAND : EnumItemSlot.OFFHAND);
|
2018-09-04 01:59:54 +02:00
|
|
|
}
|
|
|
|
// Paper start
|
|
|
|
+ public MovingObjectPosition getRayTrace(int maxDistance) {
|
2019-05-06 01:24:37 +02:00
|
|
|
+ return getRayTrace(maxDistance, RayTrace.FluidCollisionOption.NONE);
|
2018-09-04 01:59:54 +02:00
|
|
|
+ }
|
|
|
|
+
|
2019-05-06 01:24:37 +02:00
|
|
|
+ public MovingObjectPosition getRayTrace(int maxDistance, RayTrace.FluidCollisionOption fluidCollisionOption) {
|
2018-09-04 01:59:54 +02:00
|
|
|
+ if (maxDistance < 1 || maxDistance > 120) {
|
|
|
|
+ throw new IllegalArgumentException("maxDistance must be between 1-120");
|
|
|
|
+ }
|
|
|
|
+
|
2019-12-12 19:45:00 +01:00
|
|
|
+ Vec3D start = new Vec3D(locX(), locY() + getHeadHeight(), locZ());
|
2018-09-04 01:59:54 +02:00
|
|
|
+ org.bukkit.util.Vector dir = getBukkitEntity().getLocation().getDirection().multiply(maxDistance);
|
|
|
|
+ Vec3D end = new Vec3D(start.x + dir.getX(), start.y + dir.getY(), start.z + dir.getZ());
|
2019-05-13 02:23:21 +02:00
|
|
|
+ RayTrace raytrace = new RayTrace(start, end, RayTrace.BlockCollisionOption.OUTLINE, fluidCollisionOption, this);
|
2018-09-04 01:59:54 +02:00
|
|
|
+
|
2019-05-06 01:24:37 +02:00
|
|
|
+ return world.rayTrace(raytrace);
|
2018-09-04 01:59:54 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
public int shieldBlockingDelay = world.paperConfig.shieldBlockingDelay;
|
|
|
|
|
|
|
|
public int getShieldBlockingDelay() {
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
2020-05-06 11:48:49 +02:00
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
2018-09-04 01:59:54 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
2021-03-16 14:04:28 +01:00
|
|
|
@@ -0,0 +0,0 @@
|
|
|
|
package org.bukkit.craftbukkit.entity;
|
|
|
|
|
|
|
|
+import com.destroystokyo.paper.block.TargetBlockInfo;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
|
|
import com.google.common.collect.Sets;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
@@ -0,0 +0,0 @@ import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.UUID;
|
|
|
|
+import net.minecraft.server.MCUtil;
|
|
|
|
import net.minecraft.server.level.EntityPlayer;
|
|
|
|
import net.minecraft.world.EnumHand;
|
|
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
|
|
@@ -0,0 +0,0 @@ import net.minecraft.world.entity.projectile.EntityThrownExpBottle;
|
|
|
|
import net.minecraft.world.entity.projectile.EntityThrownTrident;
|
|
|
|
import net.minecraft.world.entity.projectile.EntityTippedArrow;
|
|
|
|
import net.minecraft.world.entity.projectile.EntityWitherSkull;
|
|
|
|
+import net.minecraft.world.phys.MovingObjectPosition;
|
|
|
|
+import net.minecraft.world.phys.MovingObjectPositionBlock;
|
|
|
|
import org.apache.commons.lang.Validate;
|
|
|
|
import org.bukkit.FluidCollisionMode;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
@@ -0,0 +0,0 @@ import org.bukkit.attribute.AttributeInstance;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.CraftWorld;
|
|
|
|
+import org.bukkit.craftbukkit.block.CraftBlock;
|
|
|
|
import org.bukkit.craftbukkit.entity.memory.CraftMemoryKey;
|
|
|
|
import org.bukkit.craftbukkit.entity.memory.CraftMemoryMapper;
|
|
|
|
import org.bukkit.craftbukkit.inventory.CraftEntityEquipment;
|
2018-09-04 01:59:54 +02:00
|
|
|
@@ -0,0 +0,0 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
|
|
|
return blocks.get(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
2019-05-06 04:58:04 +02:00
|
|
|
+ @Override
|
2021-03-16 14:04:28 +01:00
|
|
|
+ public Block getTargetBlock(int maxDistance, TargetBlockInfo.FluidMode fluidMode) {
|
|
|
|
+ MovingObjectPosition rayTrace = getHandle().getRayTrace(maxDistance, MCUtil.getNMSFluidCollisionOption(fluidMode));
|
|
|
|
+ return !(rayTrace instanceof MovingObjectPositionBlock) ? null : CraftBlock.at(getHandle().world, ((MovingObjectPositionBlock)rayTrace).getBlockPosition());
|
2018-09-04 01:59:54 +02:00
|
|
|
+ }
|
|
|
|
+
|
2019-05-06 04:58:04 +02:00
|
|
|
+ @Override
|
2021-03-16 14:04:28 +01:00
|
|
|
+ public org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance, TargetBlockInfo.FluidMode fluidMode) {
|
|
|
|
+ MovingObjectPosition rayTrace = getHandle().getRayTrace(maxDistance, MCUtil.getNMSFluidCollisionOption(fluidMode));
|
|
|
|
+ return !(rayTrace instanceof MovingObjectPositionBlock) ? null : MCUtil.toBukkitBlockFace(((MovingObjectPositionBlock)rayTrace).getDirection());
|
2018-09-04 01:59:54 +02:00
|
|
|
+ }
|
|
|
|
+
|
2019-05-06 04:58:04 +02:00
|
|
|
+ @Override
|
2021-03-16 14:04:28 +01:00
|
|
|
+ public TargetBlockInfo getTargetBlockInfo(int maxDistance, TargetBlockInfo.FluidMode fluidMode) {
|
|
|
|
+ MovingObjectPosition rayTrace = getHandle().getRayTrace(maxDistance, MCUtil.getNMSFluidCollisionOption(fluidMode));
|
|
|
|
+ return !(rayTrace instanceof MovingObjectPositionBlock) ? null :
|
|
|
|
+ new TargetBlockInfo(CraftBlock.at(getHandle().world, ((MovingObjectPositionBlock)rayTrace).getBlockPosition()),
|
|
|
|
+ MCUtil.toBukkitBlockFace(((MovingObjectPositionBlock)rayTrace).getDirection()));
|
2018-09-04 01:59:54 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
2019-05-06 04:58:04 +02:00
|
|
|
@Override
|
2018-09-04 01:59:54 +02:00
|
|
|
public List<Block> getLastTwoTargetBlocks(Set<Material> transparent, int maxDistance) {
|
|
|
|
return getLineOfSight(transparent, maxDistance, 2);
|