forked from GeyserMC/Geyser
Entity interact?
This commit is contained in:
parent
91a80f7dee
commit
d99c285676
4 changed files with 51 additions and 14 deletions
|
@ -25,7 +25,6 @@
|
||||||
|
|
||||||
package org.geysermc.connector.network.translators;
|
package org.geysermc.connector.network.translators;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.window.WindowType;
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.*;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.*;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.*;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.*;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerActionAckPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerActionAckPacket;
|
||||||
|
@ -51,17 +50,14 @@ import org.geysermc.connector.network.translators.block.BlockTranslator;
|
||||||
import org.geysermc.connector.network.translators.inventory.GenericInventoryTranslator;
|
import org.geysermc.connector.network.translators.inventory.GenericInventoryTranslator;
|
||||||
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
||||||
import org.geysermc.connector.network.translators.item.ItemTranslator;
|
import org.geysermc.connector.network.translators.item.ItemTranslator;
|
||||||
import org.geysermc.connector.network.translators.java.JavaChatTranslator;
|
import org.geysermc.connector.network.translators.java.*;
|
||||||
import org.geysermc.connector.network.translators.java.JavaDifficultyTranslator;
|
|
||||||
import org.geysermc.connector.network.translators.java.JavaJoinGameTranslator;
|
|
||||||
import org.geysermc.connector.network.translators.java.JavaRespawnTranslator;
|
|
||||||
import org.geysermc.connector.network.translators.java.JavaTitleTranslator;
|
|
||||||
import org.geysermc.connector.network.translators.java.entity.*;
|
import org.geysermc.connector.network.translators.java.entity.*;
|
||||||
import org.geysermc.connector.network.translators.java.entity.player.JavaPlayerActionAckTranslator;
|
import org.geysermc.connector.network.translators.java.entity.player.JavaPlayerActionAckTranslator;
|
||||||
import org.geysermc.connector.network.translators.java.entity.player.JavaPlayerHealthTranslator;
|
import org.geysermc.connector.network.translators.java.entity.player.JavaPlayerHealthTranslator;
|
||||||
import org.geysermc.connector.network.translators.java.entity.player.JavaPlayerPositionRotationTranslator;
|
import org.geysermc.connector.network.translators.java.entity.player.JavaPlayerPositionRotationTranslator;
|
||||||
import org.geysermc.connector.network.translators.java.entity.player.JavaPlayerSetExperienceTranslator;
|
import org.geysermc.connector.network.translators.java.entity.player.JavaPlayerSetExperienceTranslator;
|
||||||
import org.geysermc.connector.network.translators.java.entity.spawn.*;
|
import org.geysermc.connector.network.translators.java.entity.spawn.*;
|
||||||
|
import org.geysermc.connector.network.translators.java.inventory.OpenWindowPacketTranslator;
|
||||||
import org.geysermc.connector.network.translators.java.scoreboard.JavaDisplayScoreboardTranslator;
|
import org.geysermc.connector.network.translators.java.scoreboard.JavaDisplayScoreboardTranslator;
|
||||||
import org.geysermc.connector.network.translators.java.scoreboard.JavaScoreboardObjectiveTranslator;
|
import org.geysermc.connector.network.translators.java.scoreboard.JavaScoreboardObjectiveTranslator;
|
||||||
import org.geysermc.connector.network.translators.java.scoreboard.JavaUpdateScoreTranslator;
|
import org.geysermc.connector.network.translators.java.scoreboard.JavaUpdateScoreTranslator;
|
||||||
|
@ -72,8 +68,6 @@ import org.geysermc.connector.network.translators.java.world.*;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class TranslatorsInit {
|
public class TranslatorsInit {
|
||||||
|
|
||||||
|
@ -84,7 +78,7 @@ public class TranslatorsInit {
|
||||||
private static BlockTranslator blockTranslator;
|
private static BlockTranslator blockTranslator;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private static Map<WindowType, InventoryTranslator> inventoryTranslators = new HashMap<WindowType, InventoryTranslator>();
|
private static InventoryTranslator inventoryTranslator = new GenericInventoryTranslator();
|
||||||
|
|
||||||
private static final CompoundTag EMPTY_TAG = CompoundTagBuilder.builder().buildRootTag();
|
private static final CompoundTag EMPTY_TAG = CompoundTagBuilder.builder().buildRootTag();
|
||||||
public static final byte[] EMPTY_LEVEL_CHUNK_DATA;
|
public static final byte[] EMPTY_LEVEL_CHUNK_DATA;
|
||||||
|
@ -147,6 +141,9 @@ public class TranslatorsInit {
|
||||||
Registry.registerJava(ServerBlockChangePacket.class, new JavaBlockChangeTranslator());
|
Registry.registerJava(ServerBlockChangePacket.class, new JavaBlockChangeTranslator());
|
||||||
Registry.registerJava(ServerMultiBlockChangePacket.class, new JavaMultiBlockChangeTranslator());
|
Registry.registerJava(ServerMultiBlockChangePacket.class, new JavaMultiBlockChangeTranslator());
|
||||||
|
|
||||||
|
|
||||||
|
Registry.registerJava(ServerOpenWindowPacket.class, new OpenWindowPacketTranslator());
|
||||||
|
|
||||||
Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator());
|
Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator());
|
||||||
Registry.registerBedrock(CommandRequestPacket.class, new BedrockCommandRequestTranslator());
|
Registry.registerBedrock(CommandRequestPacket.class, new BedrockCommandRequestTranslator());
|
||||||
Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator());
|
Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator());
|
||||||
|
@ -162,11 +159,11 @@ public class TranslatorsInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerInventoryTranslators() {
|
private static void registerInventoryTranslators() {
|
||||||
inventoryTranslators.put(WindowType.GENERIC_9X1, new GenericInventoryTranslator());
|
/*inventoryTranslators.put(WindowType.GENERIC_9X1, new GenericInventoryTranslator());
|
||||||
inventoryTranslators.put(WindowType.GENERIC_9X2, new GenericInventoryTranslator());
|
inventoryTranslators.put(WindowType.GENERIC_9X2, new GenericInventoryTranslator());
|
||||||
inventoryTranslators.put(WindowType.GENERIC_9X3, new GenericInventoryTranslator());
|
inventoryTranslators.put(WindowType.GENERIC_9X3, new GenericInventoryTranslator());
|
||||||
inventoryTranslators.put(WindowType.GENERIC_9X4, new GenericInventoryTranslator());
|
inventoryTranslators.put(WindowType.GENERIC_9X4, new GenericInventoryTranslator());
|
||||||
inventoryTranslators.put(WindowType.GENERIC_9X5, new GenericInventoryTranslator());
|
inventoryTranslators.put(WindowType.GENERIC_9X5, new GenericInventoryTranslator());
|
||||||
inventoryTranslators.put(WindowType.GENERIC_9X6, new GenericInventoryTranslator());
|
inventoryTranslators.put(WindowType.GENERIC_9X6, new GenericInventoryTranslator());*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,12 +25,16 @@
|
||||||
|
|
||||||
package org.geysermc.connector.network.translators.bedrock;
|
package org.geysermc.connector.network.translators.bedrock;
|
||||||
|
|
||||||
|
import com.flowpowered.math.vector.Vector3f;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
|
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
|
||||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
|
||||||
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.InventoryAction;
|
||||||
import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket;
|
import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
@ -52,6 +56,20 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||||
session.getDownstream().getSession().send(releaseItemPacket);
|
session.getDownstream().getSession().send(releaseItemPacket);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ITEM_USE_ON_ENTITY:
|
||||||
|
Vector3f vector = packet.getClickPosition();
|
||||||
|
InteractAction action;
|
||||||
|
|
||||||
|
if(packet.getActionType() == 1) {
|
||||||
|
action = InteractAction.ATTACK;
|
||||||
|
} else {
|
||||||
|
action = InteractAction.INTERACT;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientPlayerInteractEntityPacket entityPacket = new ClientPlayerInteractEntityPacket((int) packet.getRuntimeEntityId(),
|
||||||
|
action, vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND);
|
||||||
|
|
||||||
|
session.getDownstream().getSession().send(entityPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package org.geysermc.connector.network.translators.java.inventory;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.ContainerId;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.InventoryContentPacket;
|
||||||
|
import org.geysermc.connector.inventory.Inventory;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
import org.geysermc.connector.network.translators.TranslatorsInit;
|
||||||
|
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
||||||
|
|
||||||
|
public class OpenWindowPacketTranslator extends PacketTranslator<ServerOpenWindowPacket> {
|
||||||
|
@Override
|
||||||
|
public void translate(ServerOpenWindowPacket packet, GeyserSession session) {
|
||||||
|
System.out.println("debug: " + packet.getType());
|
||||||
|
InventoryTranslator translator = TranslatorsInit.getInventoryTranslator();
|
||||||
|
|
||||||
|
translator.openInventory(session, new Inventory(packet.getName(), packet.getWindowId(), packet.getType(), 54));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -49,7 +49,7 @@ public class InventoryUtils {
|
||||||
session.getInventoryCache().getInventories().put(packet.getWindowId(), inventory);
|
session.getInventoryCache().getInventories().put(packet.getWindowId(), inventory);
|
||||||
session.getInventoryCache().setOpenInventory(inventory);
|
session.getInventoryCache().setOpenInventory(inventory);
|
||||||
|
|
||||||
InventoryTranslator translator = TranslatorsInit.getInventoryTranslators().get(inventory.getWindowType());
|
InventoryTranslator translator = TranslatorsInit.getInventoryTranslator();
|
||||||
translator.prepareInventory(session, inventory);
|
translator.prepareInventory(session, inventory);
|
||||||
Geyser.getGeneralThreadPool().schedule(() -> {
|
Geyser.getGeneralThreadPool().schedule(() -> {
|
||||||
List<Packet> packets = session.getInventoryCache().getCachedPackets().get(inventory.getId());
|
List<Packet> packets = session.getInventoryCache().getCachedPackets().get(inventory.getId());
|
||||||
|
@ -74,7 +74,7 @@ public class InventoryUtils {
|
||||||
if (packet.getWindowId() != openInventory.getId())
|
if (packet.getWindowId() != openInventory.getId())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
InventoryTranslator translator = TranslatorsInit.getInventoryTranslators().get(openInventory.getWindowType());
|
InventoryTranslator translator = TranslatorsInit.getInventoryTranslator();
|
||||||
if (translator == null) {
|
if (translator == null) {
|
||||||
session.getDownstream().getSession().send(new ClientCloseWindowPacket(packet.getWindowId()));
|
session.getDownstream().getSession().send(new ClientCloseWindowPacket(packet.getWindowId()));
|
||||||
return;
|
return;
|
||||||
|
@ -95,7 +95,7 @@ public class InventoryUtils {
|
||||||
if (packet.getWindowId() != openInventory.getId())
|
if (packet.getWindowId() != openInventory.getId())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
InventoryTranslator translator = TranslatorsInit.getInventoryTranslators().get(openInventory.getWindowType());
|
InventoryTranslator translator = TranslatorsInit.getInventoryTranslator();
|
||||||
if (translator == null) {
|
if (translator == null) {
|
||||||
session.getDownstream().getSession().send(new ClientCloseWindowPacket(packet.getWindowId()));
|
session.getDownstream().getSession().send(new ClientCloseWindowPacket(packet.getWindowId()));
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue