9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-26 10:19:15 +00:00

fix ender pearls teleporting players inside blocks

This commit is contained in:
Samsuik
2025-08-24 23:04:32 +01:00
parent 9aaeea7fd8
commit 1ab219495f
5 changed files with 58 additions and 7 deletions

View File

@@ -153,7 +153,7 @@ index e96d4dee14c05f2fa329bfb1588ec795d4e3d730..ba9393e474ae213316c693d73ef2641e
if (this.entity instanceof LivingEntity) {
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 9345d8f00496cc3becb84ab52bde2d5914911b68..d3333cc7b1cb8c63f1bdbf1df5d12935fdeb6a2d 100644
index 706941df21621080b70cc7d8c84d1ec7b7ddc483..4b9a0327251a54d752409021cb7a10f890f1f131 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -3638,7 +3638,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -196,10 +196,10 @@ index 2420999c5399333bed122ee0a1f252ac894adfcb..2e7f6e3941b34323768e43870541c8e4
public int getFuse() {
diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java
index fd841f99213860c310a3c1c9fada12fd871b8a79..653e40d77d88e3ff1ae451c0744e26db9369954e 100644
index 5cacbc07ee0f6ef2f47f7e0e8f6267d82ea94501..6160c684b712742b6ce565afb043c03badb705b2 100644
--- a/net/minecraft/world/entity/player/Player.java
+++ b/net/minecraft/world/entity/player/Player.java
@@ -689,7 +689,7 @@ public abstract class Player extends LivingEntity {
@@ -701,7 +701,7 @@ public abstract class Player extends LivingEntity {
public void increaseScore(int score) {
int score1 = this.getScore();

View File

@@ -8,6 +8,25 @@
// CraftBukkit start
public boolean fauxSleeping;
@@ -229,6 +_,18 @@
return (org.bukkit.craftbukkit.entity.CraftHumanEntity) super.getBukkitEntity();
}
// CraftBukkit end
+ // Sakura start - prevent players glitching through blocks
+ public final boolean isInsideAnyCollision() {
+ return this.insideAnyCollisionAt(this.level(), this.position());
+ }
+
+ public final boolean insideAnyCollisionAt(final Level level, final Vec3 position) {
+ final EntityDimensions entityDimensions = this.getDimensions(Pose.STANDING);
+ final AABB entityBB = entityDimensions.makeBoundingBox(position);
+ return !level.noCollision(this, entityBB.deflate(1.0e-7))
+ || !level.getWorldBorder().isWithinBounds(entityBB);
+ }
+ // Sakura end - prevent players glitching through blocks
public Player(Level level, GameProfile gameProfile) {
super(EntityType.PLAYER, level);
@@ -866,6 +_,10 @@
public boolean isInvulnerableTo(ServerLevel level, DamageSource damageSource) {
if (super.isInvulnerableTo(level, damageSource)) {

View File

@@ -1,16 +1,32 @@
--- a/net/minecraft/world/entity/projectile/ThrownEnderpearl.java
+++ b/net/minecraft/world/entity/projectile/ThrownEnderpearl.java
@@ -182,6 +_,13 @@
@@ -118,6 +_,15 @@
if (owner != null && isAllowedToTeleportOwner(owner, serverLevel)) {
Vec3 vec3 = this.oldPosition();
if (owner instanceof ServerPlayer serverPlayer) {
+ // Sakura start - prevent ender pearls teleporting inside blocks
+ if (this.level().sakuraConfig().entity.enderPearl.preventTeleportingInsideBlocks && serverPlayer.insideAnyCollisionAt(serverLevel, this.position())) {
+ this.setPos(Vec3.atBottomCenterOf(this.blockPosition()));
+ if (serverPlayer.insideAnyCollisionAt(serverLevel, this.position())) {
+ this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.HIT);
+ return;
+ }
+ }
+ // Sakura end - prevent ender pearls teleporting inside blocks
if (serverPlayer.connection.isAcceptingMessages()) {
// CraftBukkit start
// Store pre teleportation position as the teleport has been moved up.
@@ -181,6 +_,13 @@
return entity.canUsePortal(true);
}
}
+
+ // Sakura start - enderpearls use outline for collision
+ @Override
+ protected net.minecraft.world.level.ClipContext.Block getClipType() {
+ return this.level().sakuraConfig().entity.enderPearl.useOutlineForCollision ? net.minecraft.world.level.ClipContext.Block.OUTLINE : super.getClipType();
+ }
+ // Sakura end - enderpearls use outline for collision
+
@Override
public void tick() {
int sectionPosX = SectionPos.blockToSectionCoord(this.position().x());

View File

@@ -0,0 +1,15 @@
--- a/net/minecraft/world/item/EnderpearlItem.java
+++ b/net/minecraft/world/item/EnderpearlItem.java
@@ -26,6 +_,12 @@
// Paper start - PlayerLaunchProjectileEvent
final Projectile.Delayed<ThrownEnderpearl> thrownEnderpearl = Projectile.spawnProjectileFromRotationDelayed(ThrownEnderpearl::new, serverLevel, itemInHand, player, 0.0F, EnderpearlItem.PROJECTILE_SHOOT_POWER, 1.0F);
com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) player.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemInHand), (org.bukkit.entity.Projectile) thrownEnderpearl.projectile().getBukkitEntity());
+ // Sakura start - prevent ender pearls teleporting inside blocks
+ final ThrownEnderpearl pearl = thrownEnderpearl.projectile();
+ if (level.sakuraConfig().entity.enderPearl.preventTeleportingInsideBlocks && player.isInsideAnyCollision()) {
+ event.setCancelled(true);
+ }
+ // Sakura end - prevent ender pearls teleporting inside blocks
if (event.callEvent() && thrownEnderpearl.attemptSpawn()) {
if (event.shouldConsume()) {
itemInHand.consume(1, player);

View File

@@ -229,6 +229,7 @@ public final class WorldConfiguration extends ConfigurationPart {
public EnderPearl enderPearl = new EnderPearl();
public class EnderPearl extends ConfigurationPart {
public boolean useOutlineForCollision = false;
public boolean preventTeleportingInsideBlocks = false;
}
}