From bc7297fb97df9f56465b99d2b5c58ef6cda48656 Mon Sep 17 00:00:00 2001
From: Giovanni D <37423957+GioSDA@users.noreply.github.com>
Date: Thu, 27 May 2021 09:38:24 -0700
Subject: [PATCH] Add option to fix items merging through blocks (#5334)

Fixes #5204
---
 ...n-to-fix-items-merging-through-walls.patch | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Spigot-Server-Patches/Add-option-to-fix-items-merging-through-walls.patch

diff --git a/Spigot-Server-Patches/Add-option-to-fix-items-merging-through-walls.patch b/Spigot-Server-Patches/Add-option-to-fix-items-merging-through-walls.patch
new file mode 100644
index 0000000000..5886e3653f
--- /dev/null
+++ b/Spigot-Server-Patches/Add-option-to-fix-items-merging-through-walls.patch
@@ -0,0 +1,39 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: GioSDA <gsdambrosio@gmail.com>
+Date: Wed, 10 Mar 2021 10:06:45 -0800
+Subject: [PATCH] Add option to fix items merging through walls
+
+
+diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
++++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+@@ -0,0 +0,0 @@ public class PaperWorldConfig {
+     private void mapItemFrameCursorLimit() {
+         mapItemFrameCursorLimit = getInt("map-item-frame-cursor-limit", mapItemFrameCursorLimit);
+     }
++
++    public boolean fixItemsMergingThroughWalls;
++    private void fixItemsMergingThroughWalls() {
++        fixItemsMergingThroughWalls = getBoolean("fix-items-merging-through-walls", fixItemsMergingThroughWalls);
++    }
+ }
+diff --git a/src/main/java/net/minecraft/world/entity/item/EntityItem.java b/src/main/java/net/minecraft/world/entity/item/EntityItem.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/net/minecraft/world/entity/item/EntityItem.java
++++ b/src/main/java/net/minecraft/world/entity/item/EntityItem.java
+@@ -0,0 +0,0 @@ public class EntityItem extends Entity {
+                 EntityItem entityitem = (EntityItem) iterator.next();
+ 
+                 if (entityitem.z()) {
++                    // Paper Start - Fix items merging through walls
++                        if (this.world.paperConfig.fixItemsMergingThroughWalls) {
++                            net.minecraft.world.level.RayTrace rayTrace = new net.minecraft.world.level.RayTrace(this.getPositionVector(), entityitem.getPositionVector(),
++                                net.minecraft.world.level.RayTrace.BlockCollisionOption.COLLIDER, net.minecraft.world.level.RayTrace.FluidCollisionOption.NONE, this);
++                            net.minecraft.world.phys.MovingObjectPositionBlock rayTraceResult = world.rayTrace(rayTrace);
++                            if (rayTraceResult.getType() == net.minecraft.world.phys.MovingObjectPosition.EnumMovingObjectType.BLOCK) continue;
++                        }
++                    // Paper End
+                     this.a(entityitem);
+                     if (this.dead) {
+                         break;