Fix buckets not working on mobile (#767)

Desktop clients send an extra item use packet for buckets whereas mobile clients dont send the second use packet causing the issue as a ClientPlayerUseItemPacket doesn't get sent to the Java server.

Buckets on mobile may still be glitchy as the player must be directly facing the block they want to place liquid on.
This commit is contained in:
rtm516 2020-07-21 18:17:55 +01:00 committed by GitHub
parent 7bb297dd42
commit 30c007d04b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 9 deletions

View file

@ -36,12 +36,11 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.data.LevelEventType;
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket;
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.ItemFrameEntity;
import org.geysermc.connector.entity.living.merchant.AbstractMerchantEntity;
@ -98,11 +97,11 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
false);
session.sendDownstreamPacket(blockPacket);
// Otherwise boats will not be able to be placed in survival
if (packet.getItemInHand() != null && packet.getItemInHand().getId() == ItemRegistry.BOAT.getBedrockId()) {
// Otherwise boats will not be able to be placed in survival and buckets wont work on mobile
if (packet.getItemInHand() != null && (packet.getItemInHand().getId() == ItemRegistry.BOAT.getBedrockId() || packet.getItemInHand().getId() == ItemRegistry.BUCKET.getBedrockId())) {
ClientPlayerUseItemPacket itemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
session.sendDownstreamPacket(itemPacket);
}
}
Vector3i blockPos = packet.getBlockPosition();
// TODO: Find a better way to do this?
@ -136,9 +135,16 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
break;
case 1:
ItemStack shieldSlot = session.getInventory().getItem(session.getInventory().getHeldItemSlot() + 36);
// Handled in Entity.java
if (shieldSlot != null && shieldSlot.getId() == ItemRegistry.SHIELD.getJavaId()) {
break;
} // Handled in Entity.java
}
// Handled in ITEM_USE
if (packet.getItemInHand() != null && packet.getItemInHand().getId() == ItemRegistry.BUCKET.getJavaId()) {
break;
}
ClientPlayerUseItemPacket useItemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
session.sendDownstreamPacket(useItemPacket);
// Used for sleeping in beds

View file

@ -56,12 +56,14 @@ public class ItemRegistry {
public static final List<StartGamePacket.ItemEntry> ITEMS = new ArrayList<>();
public static final Int2ObjectMap<ItemEntry> ITEM_ENTRIES = new Int2ObjectOpenHashMap<>();
// Shield ID, used in Entity.java
public static ItemEntry SHIELD;
// Boat ID, used in BedrockInventoryTransactionTranslator.java
public static ItemEntry BOAT;
// Gold ID, used in BedrockInventoryTransactionTranslator.java
public static ItemEntry BUCKET;
// Gold ID, used in PiglinEntity.java
public static ItemEntry GOLD;
// Shield ID, used in Entity.java
public static ItemEntry SHIELD;
public static int BARRIER_INDEX = 0;
@ -138,6 +140,9 @@ public class ItemRegistry {
case "minecraft:shield":
SHIELD = ITEM_ENTRIES.get(itemIndex);
break;
case "minecraft:bucket":
BUCKET = ITEM_ENTRIES.get(itemIndex);
break;
default:
break;
}