|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package org.geysermc.connector.network.translators.bedrock; |
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; |
|
import com.nukkitx.protocol.bedrock.data.entity.EntityData; |
|
import com.nukkitx.protocol.bedrock.packet.EntityPickRequestPacket; |
|
import org.geysermc.connector.entity.Entity; |
|
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.registry.type.ItemMapping; |
|
import org.geysermc.connector.utils.InventoryUtils; |
|
|
|
|
|
|
|
|
|
@Translator(packet = EntityPickRequestPacket.class) |
|
public class BedrockEntityPickRequestTranslator extends PacketTranslator<EntityPickRequestPacket> { |
|
|
|
@Override |
|
|
|
|
|
|
|
public void translate(GeyserSession session, EntityPickRequestPacket packet) { |
|
if (session.getGameMode() != GameMode.CREATIVE) return; |
|
Entity entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId()); |
|
if (entity == null) return; |
|
|
|
|
|
String itemName; |
|
switch (entity.getEntityType()) { |
|
case BOAT: |
|
|
|
int variant = entity.getMetadata().getInt(EntityData.VARIANT); |
|
String typeOfBoat; |
|
switch (variant) { |
|
case 1: |
|
typeOfBoat = "spruce"; |
|
break; |
|
case 2: |
|
typeOfBoat = "birch"; |
|
break; |
|
case 3: |
|
typeOfBoat = "jungle"; |
|
break; |
|
case 4: |
|
typeOfBoat = "acacia"; |
|
break; |
|
case 5: |
|
typeOfBoat = "dark_oak"; |
|
break; |
|
default: |
|
typeOfBoat = "oak"; |
|
break; |
|
} |
|
itemName = typeOfBoat + "_boat"; |
|
break; |
|
case LEASH_KNOT: |
|
itemName = "lead"; |
|
break; |
|
case MINECART_CHEST: |
|
case MINECART_COMMAND_BLOCK: |
|
case MINECART_FURNACE: |
|
case MINECART_HOPPER: |
|
case MINECART_TNT: |
|
|
|
itemName = entity.getEntityType().toString().toLowerCase().replace("minecart_", "") + "_minecart"; |
|
break; |
|
case MINECART_SPAWNER: |
|
|
|
itemName = "minecart"; |
|
break; |
|
case ARMOR_STAND: |
|
case END_CRYSTAL: |
|
|
|
|
|
case MINECART: |
|
case PAINTING: |
|
|
|
itemName = entity.getEntityType().toString().toLowerCase(); |
|
break; |
|
default: |
|
itemName = entity.getEntityType().toString().toLowerCase() + "_spawn_egg"; |
|
break; |
|
} |
|
|
|
String fullItemName = "minecraft:" + itemName; |
|
ItemMapping mapping = session.getItemMappings().getMapping(fullItemName); |
|
|
|
if (mapping == null) return; |
|
|
|
InventoryUtils.findOrCreateItem(session, fullItemName); |
|
} |
|
} |
|
|