Resend damageable item on cancelled block break in 1.11->1.10

The client assumes durability changes, so we have to resend the item
This commit is contained in:
Nassim Jahnke 2024-05-30 15:42:07 +02:00
parent b53c0aeb9b
commit bc3d6b952f
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
3 changed files with 59 additions and 1 deletions

View File

@ -19,6 +19,7 @@
package com.viaversion.viabackwards; package com.viaversion.viabackwards;
import com.viaversion.viabackwards.api.ViaBackwardsPlatform; import com.viaversion.viabackwards.api.ViaBackwardsPlatform;
import com.viaversion.viabackwards.listener.BlockBreakListener;
import com.viaversion.viabackwards.listener.FireDamageListener; import com.viaversion.viabackwards.listener.FireDamageListener;
import com.viaversion.viabackwards.listener.FireExtinguishListener; import com.viaversion.viabackwards.listener.FireExtinguishListener;
import com.viaversion.viabackwards.listener.LecternInteractListener; import com.viaversion.viabackwards.listener.LecternInteractListener;
@ -61,6 +62,9 @@ public class BukkitPlugin extends JavaPlugin implements ViaBackwardsPlatform {
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_12)) { if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_12)) {
new FireDamageListener(this).register(); new FireDamageListener(this).register();
} }
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_11)) {
new BlockBreakListener(this).register();
}
final ViaProviders providers = Via.getManager().getProviders(); final ViaProviders providers = Via.getManager().getProviders();
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_2)) { if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_2)) {

View File

@ -0,0 +1,54 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.listener;
import com.viaversion.viabackwards.BukkitPlugin;
import com.viaversion.viabackwards.protocol.v1_11to1_10.Protocol1_11To1_10;
import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
public class BlockBreakListener extends ViaBukkitListener {
public BlockBreakListener(final BukkitPlugin plugin) {
super(plugin, Protocol1_11To1_10.class);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(final BlockBreakEvent event) {
if (!event.isCancelled()) {
return;
}
final Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE || !isOnPipe(player)) {
return;
}
// Resend the item in the hand to sync durability
final int slot = player.getInventory().getHeldItemSlot();
final ItemStack item = player.getInventory().getItem(slot);
if (item != null && item.getType().getMaxDurability() > 0) {
player.getInventory().setItem(slot, item);
}
}
}

View File

@ -40,7 +40,7 @@ public class PlayerItemDropListener extends ViaBukkitListener {
return; return;
} }
// Resent the item in the hand // Resend the item in the hand
final int slot = player.getInventory().getHeldItemSlot(); final int slot = player.getInventory().getHeldItemSlot();
final ItemStack item = player.getInventory().getItem(slot); final ItemStack item = player.getInventory().getItem(slot);
player.getInventory().setItem(slot, item); player.getInventory().setItem(slot, item);