From 794a665f209fbaa91a0f429033b5022be80126b8 Mon Sep 17 00:00:00 2001 From: Blast-MC Date: Thu, 25 Jan 2024 20:04:14 -0500 Subject: [PATCH] Fix ProjectEdenGG/Bugs#311 --- ...8-Add-Block-BreakNaturally-Overload.patch} | 104 ++++++++---------- 1 file changed, 43 insertions(+), 61 deletions(-) rename patches/server/{0025-Add-Block-BreakNaturally-Overload.patch => 0028-Add-Block-BreakNaturally-Overload.patch} (58%) diff --git a/patches/server/0025-Add-Block-BreakNaturally-Overload.patch b/patches/server/0028-Add-Block-BreakNaturally-Overload.patch similarity index 58% rename from patches/server/0025-Add-Block-BreakNaturally-Overload.patch rename to patches/server/0028-Add-Block-BreakNaturally-Overload.patch index 581ac5a..ba6b752 100644 --- a/patches/server/0025-Add-Block-BreakNaturally-Overload.patch +++ b/patches/server/0028-Add-Block-BreakNaturally-Overload.patch @@ -1,105 +1,92 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Blast-MC -Date: Fri, 15 Dec 2023 21:59:19 -0500 +Date: Thu, 25 Jan 2024 19:59:13 -0500 Subject: [PATCH] Add Block BreakNaturally Overload diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java -index c4c27fb5b92833eca243e1ba718c8dcaa676a310..74be1111c4ac7fc43ed92c83544b0e7d77764e9a 100644 +index d6e2b9d4bbd3ba9f9461a02b282c26b95861530a..c05a8383c24e5a2b2d0469e66ca2c8853dc2c076 100644 --- a/src/main/java/net/minecraft/world/level/block/Block.java +++ b/src/main/java/net/minecraft/world/level/block/Block.java -@@ -7,6 +7,8 @@ import com.google.common.collect.ImmutableMap; - import com.mojang.logging.LogUtils; - import com.mojang.serialization.MapCodec; - import it.unimi.dsi.fastutil.objects.Object2ByteLinkedOpenHashMap; -+ -+import java.util.ArrayList; - import java.util.Iterator; - import java.util.List; - import java.util.function.Function; -@@ -307,24 +309,28 @@ public class Block extends BlockBehaviour implements ItemLike { +@@ -307,24 +307,28 @@ public class Block extends BlockBehaviour implements ItemLike { return state.getDrops(lootparams_a); } - public static void dropResources(BlockState state, Level world, BlockPos pos) { + public static List dropResources(BlockState state, Level world, BlockPos pos) { if (world instanceof ServerLevel) { -+ List itemEntities = new ArrayList<>(); ++ List itemEntities = new java.util.ArrayList<>(); org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDropResourcesEvent(world, pos, Block.getDrops(state, (ServerLevel) world, pos, (BlockEntity) null)).forEach((itemstack) -> { // Parchment - Block.popResource(world, pos, itemstack); -+ itemEntities.add(Block.popResource(world, pos, itemstack)); ++ itemEntities.add(Block.popResourceWithReturn(world, pos, itemstack)); }); state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY, true); + return itemEntities; } - -+ return new ArrayList<>(); ++ return new java.util.ArrayList<>(); } - public static void dropResources(BlockState state, LevelAccessor world, BlockPos pos, @Nullable BlockEntity blockEntity) { + public static List dropResources(BlockState state, LevelAccessor world, BlockPos pos, @Nullable BlockEntity blockEntity) { if (world instanceof ServerLevel) { -+ List itemEntities = new ArrayList<>(); ++ List itemEntities = new java.util.ArrayList<>(); org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDropResourcesEvent(world, pos, Block.getDrops(state, (ServerLevel) world, pos, blockEntity)).forEach((itemstack) -> { // Parchment - Block.popResource((ServerLevel) world, pos, itemstack); -+ itemEntities.add(Block.popResource((ServerLevel) world, pos, itemstack)); ++ itemEntities.add(Block.popResourceWithReturn((ServerLevel) world, pos, itemstack)); }); state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY, true); + return itemEntities; } - -+ return new ArrayList<>(); ++ return new java.util.ArrayList<>(); } - // Paper start + // Paper start - Add BlockBreakBlockEvent public static boolean dropResources(BlockState state, LevelAccessor world, BlockPos pos, @Nullable BlockEntity blockEntity, BlockPos source) { -@@ -344,25 +350,29 @@ public class Block extends BlockBehaviour implements ItemLike { +@@ -351,15 +355,17 @@ public class Block extends BlockBehaviour implements ItemLike { + // Paper start - Properly handle xp dropping + dropResources(state, world, pos, blockEntity, entity, tool, true); } - // Paper end - -- public static void dropResources(BlockState state, Level world, BlockPos pos, @Nullable BlockEntity blockEntity, @Nullable Entity entity, ItemStack tool) { -+ public static List dropResources(BlockState state, Level world, BlockPos pos, @Nullable BlockEntity blockEntity, @Nullable Entity entity, ItemStack tool) { +- public static void dropResources(BlockState state, Level world, BlockPos pos, @Nullable BlockEntity blockEntity, @Nullable Entity entity, ItemStack tool, boolean dropExperience) { ++ public static List dropResources(BlockState state, Level world, BlockPos pos, @Nullable BlockEntity blockEntity, @Nullable Entity entity, ItemStack tool, boolean dropExperience) { + // Paper end - Properly handle xp dropping if (world instanceof ServerLevel) { -+ List itemEntities = new ArrayList<>(); ++ List itemEntities = new java.util.ArrayList<>(); org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDropResourcesEvent(world, pos, Block.getDrops(state, (ServerLevel) world, pos, blockEntity, entity, tool)).forEach((itemstack1) -> { // Parchment - Block.popResource(world, pos, itemstack1); -+ itemEntities.add(Block.popResource(world, pos, itemstack1)); ++ itemEntities.add(Block.popResourceWithReturn(world, pos, itemstack1)); }); - state.spawnAfterBreak((ServerLevel) world, pos, tool, true); + state.spawnAfterBreak((ServerLevel) world, pos, tool, dropExperience); // Paper - Properly handle xp dropping + return itemEntities; } - -+ return new ArrayList<>(); ++ return new java.util.ArrayList<>(); } -- public static void popResource(Level world, BlockPos pos, ItemStack stack) { -+ public static ItemEntity popResource(Level world, BlockPos pos, ItemStack stack) { - double d0 = (double) EntityType.ITEM.getHeight() / 2.0D; - double d1 = (double) pos.getX() + 0.5D + Mth.nextDouble(world.random, -0.25D, 0.25D); - double d2 = (double) pos.getY() + 0.5D + Mth.nextDouble(world.random, -0.25D, 0.25D) - d0; - double d3 = (double) pos.getZ() + 0.5D + Mth.nextDouble(world.random, -0.25D, 0.25D); - -+ ItemEntity itemEntity = new ItemEntity(world, d1, d2, d3, stack); - Block.popResource(world, () -> { -- return new ItemEntity(world, d1, d2, d3, stack); -+ return itemEntity; + public static void popResource(Level world, BlockPos pos, ItemStack stack) { +@@ -373,6 +379,17 @@ public class Block extends BlockBehaviour implements ItemLike { }, stack); -+ return itemEntity; } ++ public static ItemEntity popResourceWithReturn(Level world, BlockPos pos, ItemStack stack) { ++ double d0 = (double) EntityType.ITEM.getHeight() / 2.0D; ++ double d1 = (double) pos.getX() + 0.5D + Mth.nextDouble(world.random, -0.25D, 0.25D); ++ double d2 = (double) pos.getY() + 0.5D + Mth.nextDouble(world.random, -0.25D, 0.25D) - d0; ++ double d3 = (double) pos.getZ() + 0.5D + Mth.nextDouble(world.random, -0.25D, 0.25D); ++ ++ ItemEntity itemEntity = new ItemEntity(world, d1, d2, d3, stack); ++ Block.popResource(world, () -> itemEntity, stack); ++ return itemEntity; ++ } ++ public static void popResourceFromFace(Level world, BlockPos pos, Direction direction, ItemStack stack) { + int i = direction.getStepX(); + int j = direction.getStepY(); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java -index e5506a7d074a9f89d41f4d5d7549a458779bef20..102b4238ca81b59248c83e9fa0529eb2340485d3 100644 +index 4b42ef2a876ea210d948238e63fd7a2b7035bb5b..8d2ea69c52480b6b2e28fa00ba566b7a07cfd224 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java -@@ -43,6 +43,7 @@ import org.bukkit.craftbukkit.CraftFluidCollisionMode; - import org.bukkit.craftbukkit.CraftWorld; - import org.bukkit.craftbukkit.block.data.CraftBlockData; - import org.bukkit.craftbukkit.entity.CraftEntity; -+import org.bukkit.craftbukkit.entity.CraftItem; - import org.bukkit.craftbukkit.entity.CraftPlayer; - import org.bukkit.craftbukkit.inventory.CraftItemStack; - import org.bukkit.craftbukkit.util.CraftLocation; -@@ -494,16 +495,26 @@ public class CraftBlock implements Block { +@@ -494,6 +494,11 @@ public class CraftBlock implements Block { @Override public boolean breakNaturally(ItemStack item, boolean triggerEffect, boolean dropExperience) { @@ -107,25 +94,20 @@ index e5506a7d074a9f89d41f4d5d7549a458779bef20..102b4238ca81b59248c83e9fa0529eb2 + } + + @Override -+ public boolean breakNaturally(Player player, ItemStack tool, boolean triggerEffect, boolean dropExperience) { ++ public boolean breakNaturally(Player player, ItemStack item, boolean triggerEffect, boolean dropExperience) { // Paper end // Order matters here, need to drop before setting to air so skulls can get their data net.minecraft.world.level.block.state.BlockState iblockdata = this.getNMS(); - net.minecraft.world.level.block.Block block = iblockdata.getBlock(); -- net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); -+ net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(tool); - boolean result = false; +@@ -503,7 +508,11 @@ public class CraftBlock implements Block { // Modelled off EntityHuman#hasBlock -- if (block != Blocks.AIR && (item == null || !iblockdata.requiresCorrectToolForDrops() || nmsItem.isCorrectToolForDrops(iblockdata))) { -- net.minecraft.world.level.block.Block.dropResources(iblockdata, this.world.getMinecraftWorld(), this.position, this.world.getBlockEntity(this.position), null, nmsItem); -+ if (block != Blocks.AIR && (tool == null || !iblockdata.requiresCorrectToolForDrops() || nmsItem.isCorrectToolForDrops(iblockdata))) { -+ List itemEntities = net.minecraft.world.level.block.Block.dropResources(iblockdata, this.world.getMinecraftWorld(), this.position, this.world.getBlockEntity(this.position), null, nmsItem); + if (block != Blocks.AIR && (item == null || !iblockdata.requiresCorrectToolForDrops() || nmsItem.isCorrectToolForDrops(iblockdata))) { +- net.minecraft.world.level.block.Block.dropResources(iblockdata, this.world.getMinecraftWorld(), this.position, this.world.getBlockEntity(this.position), null, nmsItem, false); // Paper - Properly handle xp dropping ++ List itemEntities = net.minecraft.world.level.block.Block.dropResources(iblockdata, this.world.getMinecraftWorld(), this.position, this.world.getBlockEntity(this.position), null, nmsItem, false); + + if (player != null) { -+ new org.bukkit.event.block.BlockDropItemEvent(this, this.getState(), player, itemEntities.stream().map(item -> (org.bukkit.entity.Item) CraftEntity.getEntity((org.bukkit.craftbukkit.CraftServer) Bukkit.getServer(), item)).toList()).callEvent(); ++ new org.bukkit.event.block.BlockDropItemEvent(this, this.getState(), player, itemEntities.stream().map(i -> (org.bukkit.entity.Item) CraftEntity.getEntity((org.bukkit.craftbukkit.CraftServer) Bukkit.getServer(), i)).toList()).callEvent(); + } -+ // Paper start - improve Block#breanNaturally if (triggerEffect) { if (iblockdata.getBlock() instanceof net.minecraft.world.level.block.BaseFireBlock) {