Skip to content

Commit

Permalink
Fix BlockBreakEvent.isDropItems() method is not implemented (Luohuayu…
Browse files Browse the repository at this point in the history
  • Loading branch information
Luohuayu committed May 21, 2023
1 parent fed5681 commit ab5ae25
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@

if (flag)
{
@@ -245,9 +348,13 @@
@@ -245,9 +348,14 @@
return flag;
}

Expand All @@ -247,12 +247,13 @@
public boolean tryHarvestBlock(BlockPos pos)
{
- if (this.gameType.isCreative() && !this.player.getHeldItemMainhand().isEmpty() && this.player.getHeldItemMainhand().getItem() instanceof ItemSword)
+ catserver.server.CatServerEventHandler.bukkitBlockBreakEventCapture.reset(); // CatServer
+ int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, gameType, player, pos);
+ if (exp == -1)
{
return false;
}
@@ -264,53 +371,41 @@
@@ -264,53 +372,41 @@
}
else
{
Expand Down Expand Up @@ -303,8 +304,9 @@
+ if (itemstack1.isEmpty()) net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.player, itemstack2, EnumHand.MAIN_HAND);
}

- if (flag1 && flag)
+ flag1 = this.removeBlock(pos, flag);
if (flag1 && flag)
+ if (flag1 && flag && (!catserver.server.CatServerEventHandler.bukkitBlockBreakEventCapture.hasResult() || catserver.server.CatServerEventHandler.bukkitBlockBreakEventCapture.get().isDropItems())) // CatServer - Implement BlockBreakEvent.isDropItems()
{
iblockstate.getBlock().harvestBlock(this.world, this.player, pos, iblockstate, tileentity, itemstack2);
}
Expand All @@ -318,7 +320,7 @@
return flag1;
}
}
@@ -328,8 +423,11 @@
@@ -328,8 +424,11 @@
}
else
{
Expand All @@ -330,15 +332,15 @@
ActionResult<ItemStack> actionresult = stack.useItemRightClick(worldIn, player, hand);
ItemStack itemstack = actionresult.getResult();

@@ -357,6 +455,7 @@
@@ -357,6 +456,7 @@

if (itemstack.isEmpty())
{
+ net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, copyBeforeUse, hand);
player.setHeldItem(hand, ItemStack.EMPTY);
}

@@ -370,87 +469,156 @@
@@ -370,87 +470,156 @@
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/main/java/catserver/server/CatServerEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.List;

public class CatServerEventHandler {
public static final BukkitEventCapture<BlockBreakEvent> bukkitBlockBreakEventCapture = new BukkitEventCapture<>();

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockEvent.BreakEvent event) {
BlockBreakEvent bukkitEvent = CraftEventFactory.callBlockBreakEvent(event.getWorld(), event.getPos(), event.getState(), (EntityPlayerMP) event.getPlayer());
Expand All @@ -34,6 +36,8 @@ public void onBlockBreak(BlockEvent.BreakEvent event) {
} else {
event.setExpToDrop(bukkitEvent.getExpToDrop());
}

bukkitBlockBreakEventCapture.put(bukkitEvent);
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
Expand Down Expand Up @@ -88,4 +92,28 @@ public void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
public void onPlayerChangedDimension(PlayerEvent.PlayerChangedDimensionEvent event) {
Bukkit.getPluginManager().callEvent(new PlayerChangedWorldEvent((CraftPlayer) event.player.getBukkitEntity(), MinecraftServer.getServerInst().getWorldServer(event.fromDim).getWorld()));
}

public static class BukkitEventCapture<T extends Event> {
private T bukkitEvent;

public boolean hasResult() {
return bukkitEvent != null;
}

public void put(T bukkitEvent) {
if (this.bukkitEvent == null) {
this.bukkitEvent = bukkitEvent;
}
}

public T get() {
T bukkitEvent = this.bukkitEvent;
this.bukkitEvent = null;
return bukkitEvent;
}

public void reset() {
bukkitEvent = null;
}
}
}

0 comments on commit ab5ae25

Please sign in to comment.