1.15.2 Only showing entity when player looks at a certain block

Discussion in 'Spigot Plugin Development' started by Dramatically, Jan 17, 2020.

  1. Title. If this requires packets since I only want the client to see it I can use reflection or have classes per client. The entity is an armorstand that will be seen or be visible to the client if the client looks at the correlating block.
  2. Runnable -> player.getTargetBlock() -> check if block is mapped (fastest lookup would be a long key for the block coordinates) -> send packets for spawning.

    PS you could probably do some fancy stuff with vectors but in most cases the previously statet method should be fine.
    #2 7smile7, Jan 17, 2020
    Last edited: Jan 17, 2020
  3. So I can only do it with packets?
  4. I mean... yes. You cant show only one specific player a certain mob without packets. If it spawns then everyone in range gets send a packet.
  5. Packets are automatically sent, and will tell players any information (Like when a mob spawns, if a mob is invisible or not, etc). You can intercept these packets and modify them. Have a look the wiki.

    I personally would modify EntityMeta to tell a player whether mobs are visible.
    Many people like to use ProtocolLib for making packets compatible across versions.
  6. I have attempted this and coded:

    Code (Text):

    if (player == null) return;

    Class PacketPlayOutEntityMetadata = null;
    try {
        PacketPlayOutEntityMetadata = Class.forName("net.minecraft.server." + server_version + ".PacketPlayOutEntityMetadata");
    } catch (ClassNotFoundException ex) {

    try {
        Method getHandle = null;
        Class nmsEntityClass = null;
        getHandle = entity.getClass().getDeclaredMethod("getHandle");
        Object nmsEntity = getHandle.invoke(entity);
        nmsEntityClass = nmsEntity.getClass();

        Object dataWatcher = locateMethod(nmsEntityClass, "getDataWatcher", null).invoke(nmsEntity);
        Object packet = PacketPlayOutEntityMetadata.getDeclaredConstructor(int.class,
                Class.forName("net.minecraft.server." + server_version + ".DataWatcher"), boolean.class).newInstance(3, dataWatcher, visible);
        sendPacket(player, packet);
    } catch (NoSuchMethodException e) {
    } catch (IllegalAccessException e) {
    } catch (InstantiationException e) {
    } catch (InvocationTargetException e) {
    } catch (ClassNotFoundException e) {
    However it does not do anything, I even tried converting it from reflection into nms and it still does nothing. What have I done wrong?

    There are no errors
  7. Here is the thread when I was learning reflection and how to modify the entity meta data to make entities glow. You'll probably find it useful