|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package org.geysermc.connector.network.translators.bedrock;
|
|
|
|
import com.nukkitx.math.vector.Vector3i;
|
|
import com.nukkitx.protocol.bedrock.packet.BlockPickRequestPacket;
|
|
import org.geysermc.connector.entity.ItemFrameEntity;
|
|
import org.geysermc.connector.entity.type.EntityType;
|
|
import org.geysermc.connector.network.session.GeyserSession;
|
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
|
import org.geysermc.connector.network.translators.Translator;
|
|
import org.geysermc.connector.network.translators.world.block.BlockStateValues;
|
|
import org.geysermc.connector.registry.BlockRegistries;
|
|
import org.geysermc.connector.utils.InventoryUtils;
|
|
|
|
@Translator(packet = BlockPickRequestPacket.class)
|
|
public class BedrockBlockPickRequestTranslator extends PacketTranslator<BlockPickRequestPacket> {
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void translate(GeyserSession session, BlockPickRequestPacket packet) {
|
|
Vector3i vector = packet.getBlockPosition();
|
|
int blockToPick = session.getConnector().getWorldManager().getBlockAt(session, vector.getX(), vector.getY(), vector.getZ());
|
|
|
|
|
|
if (blockToPick == BlockStateValues.JAVA_AIR_ID) {
|
|
|
|
ItemFrameEntity entity = ItemFrameEntity.getItemFrameEntity(session, packet.getBlockPosition());
|
|
if (entity != null) {
|
|
|
|
if (entity.getHeldItem() != null && entity.getHeldItem().getId() != 0) {
|
|
|
|
InventoryUtils.findOrCreateItem(session, entity.getHeldItem());
|
|
} else {
|
|
|
|
InventoryUtils.findOrCreateItem(session, entity.getEntityType() == EntityType.GLOW_ITEM_FRAME ? "minecraft:glow_item_frame" : "minecraft:item_frame");
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
InventoryUtils.findOrCreateItem(session, BlockRegistries.JAVA_BLOCKS.get(blockToPick).getPickItem());
|
|
}
|
|
}
|
|
|