--- a/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
@@ -1,6 +1,7 @@
 package net.minecraft.world.level.block.entity;
 
 import net.minecraft.core.BlockPos;
+import net.minecraft.core.Direction;
 import net.minecraft.core.HolderLookup;
 import net.minecraft.core.NonNullList;
 import net.minecraft.core.Vec3i;
@@ -19,39 +20,82 @@
 import net.minecraft.world.level.Level;
 import net.minecraft.world.level.block.BarrelBlock;
 import net.minecraft.world.level.block.state.BlockState;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
 
 public class BarrelBlockEntity extends RandomizableContainerBlockEntity {
-    private NonNullList<ItemStack> items = NonNullList.withSize(27, ItemStack.EMPTY);
-    public final ContainerOpenersCounter openersCounter = new ContainerOpenersCounter() {
-        @Override
-        protected void onOpen(Level world, BlockPos pos, BlockState state) {
-            BarrelBlockEntity.this.playSound(state, SoundEvents.BARREL_OPEN);
-            BarrelBlockEntity.this.updateBlockState(state, true);
-        }
 
-        @Override
-        protected void onClose(Level world, BlockPos pos, BlockState state) {
-            BarrelBlockEntity.this.playSound(state, SoundEvents.BARREL_CLOSE);
-            BarrelBlockEntity.this.updateBlockState(state, false);
-        }
+    // CraftBukkit start - add fields and methods
+    public List<HumanEntity> transaction = new ArrayList<>();
+    private int maxStack = MAX_STACK;
 
-        @Override
-        protected void openerCountChanged(Level world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) {
-        }
+    @Override
+    public List<ItemStack> getContents() {
+        return this.items;
+    }
 
-        @Override
-        protected boolean isOwnContainer(Player player) {
-            if (player.containerMenu instanceof ChestMenu) {
-                Container container = ((ChestMenu)player.containerMenu).getContainer();
-                return container == BarrelBlockEntity.this;
-            } else {
-                return false;
-            }
-        }
-    };
+    @Override
+    public void onOpen(CraftHumanEntity who) {
+        this.transaction.add(who);
+    }
+
+    @Override
+    public void onClose(CraftHumanEntity who) {
+        this.transaction.remove(who);
+    }
+
+    @Override
+    public List<HumanEntity> getViewers() {
+        return this.transaction;
+    }
+
+    @Override
+    public int getMaxStackSize() {
+       return this.maxStack;
+    }
+
+    @Override
+    public void setMaxStackSize(int i) {
+        this.maxStack = i;
+    }
+    // CraftBukkit end
+    private NonNullList<ItemStack> items;
+    public final ContainerOpenersCounter openersCounter;
 
     public BarrelBlockEntity(BlockPos pos, BlockState state) {
         super(BlockEntityType.BARREL, pos, state);
+        this.items = NonNullList.withSize(27, ItemStack.EMPTY);
+        this.openersCounter = new ContainerOpenersCounter() {
+            @Override
+            protected void onOpen(Level world, BlockPos pos, BlockState state) {
+                BarrelBlockEntity.this.playSound(state, SoundEvents.BARREL_OPEN);
+                BarrelBlockEntity.this.updateBlockState(state, true);
+            }
+
+            @Override
+            protected void onClose(Level world, BlockPos pos, BlockState state) {
+                BarrelBlockEntity.this.playSound(state, SoundEvents.BARREL_CLOSE);
+                BarrelBlockEntity.this.updateBlockState(state, false);
+            }
+
+            @Override
+            protected void openerCountChanged(Level world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) {}
+
+            @Override
+            protected boolean isOwnContainer(Player player) {
+                if (player.containerMenu instanceof ChestMenu) {
+                    Container iinventory = ((ChestMenu) player.containerMenu).getContainer();
+
+                    return iinventory == BarrelBlockEntity.this;
+                } else {
+                    return false;
+                }
+            }
+        };
     }
 
     @Override
@@ -60,6 +104,7 @@
         if (!this.trySaveLootTable(nbt)) {
             ContainerHelper.saveAllItems(nbt, this.items, registryLookup);
         }
+
     }
 
     @Override
@@ -69,6 +114,7 @@
         if (!this.tryLoadLootTable(nbt)) {
             ContainerHelper.loadAllItems(nbt, this.items, registryLookup);
         }
+
     }
 
     @Override
@@ -101,6 +147,7 @@
         if (!this.remove && !player.isSpectator()) {
             this.openersCounter.incrementOpeners(player, this.getLevel(), this.getBlockPos(), this.getBlockState());
         }
+
     }
 
     @Override
@@ -108,23 +155,26 @@
         if (!this.remove && !player.isSpectator()) {
             this.openersCounter.decrementOpeners(player, this.getLevel(), this.getBlockPos(), this.getBlockState());
         }
+
     }
 
     public void recheckOpen() {
         if (!this.remove) {
             this.openersCounter.recheckOpeners(this.getLevel(), this.getBlockPos(), this.getBlockState());
         }
+
     }
 
     public void updateBlockState(BlockState state, boolean open) {
-        this.level.setBlock(this.getBlockPos(), state.setValue(BarrelBlock.OPEN, Boolean.valueOf(open)), 3);
+        this.level.setBlock(this.getBlockPos(), (BlockState) state.setValue(BarrelBlock.OPEN, open), 3);
     }
 
     public void playSound(BlockState state, SoundEvent soundEvent) {
-        Vec3i vec3i = state.getValue(BarrelBlock.FACING).getNormal();
-        double d = (double)this.worldPosition.getX() + 0.5 + (double)vec3i.getX() / 2.0;
-        double e = (double)this.worldPosition.getY() + 0.5 + (double)vec3i.getY() / 2.0;
-        double f = (double)this.worldPosition.getZ() + 0.5 + (double)vec3i.getZ() / 2.0;
-        this.level.playSound(null, d, e, f, soundEvent, SoundSource.BLOCKS, 0.5F, this.level.random.nextFloat() * 0.1F + 0.9F);
+        Vec3i baseblockposition = ((Direction) state.getValue(BarrelBlock.FACING)).getNormal();
+        double d0 = (double) this.worldPosition.getX() + 0.5D + (double) baseblockposition.getX() / 2.0D;
+        double d1 = (double) this.worldPosition.getY() + 0.5D + (double) baseblockposition.getY() / 2.0D;
+        double d2 = (double) this.worldPosition.getZ() + 0.5D + (double) baseblockposition.getZ() / 2.0D;
+
+        this.level.playSound((Player) null, d0, d1, d2, soundEvent, SoundSource.BLOCKS, 0.5F, this.level.random.nextFloat() * 0.1F + 0.9F);
     }
 }
