1.15.1 1.15+ Invisible Shulker

Discussion in 'Spigot Plugin Development' started by abandoncaptian, Jan 14, 2020.

  1. This is a continuation off this thread.
    The following Gif shows the issue I need to resolve.
    How do I make them not spazy and make the head inside not be visible?

    Code (Java):
    WorldServer world = ((CraftWorld) bl.getWorld()).getHandle();
                        EntityShulker entity = new EntityShulker(EntityTypes.SHULKER, world);
                        //entity.setPosition(bl.getLocation().getX() + 0.5D, bl.getLocation().getY(), bl.getLocation().getZ() + 0.5D);
                        entity.setPositionRotation(bl.getLocation().getX() + 0.5D, bl.getLocation().getY(), bl.getLocation().getZ() + 0.5D, 0, 0);
                        entity.setHeadRotation(0);
                        entity.setInvisible(true);
                        entity.setInvulnerable(true);
                        entity.setNoAI(true);
                        entity.setSilent(true);
                        entity.setFlag(6, true); //Glow
                        entity.setFlag(5, true); //Invisibility - probably not needed.
                        PacketPlayOutSpawnEntityLiving spawnEntityLiving = new PacketPlayOutSpawnEntityLiving(entity);
                        ((CraftPlayer)p).getHandle().playerConnection.sendPacket(spawnEntityLiving);
                        PacketPlayOutEntityMetadata entityMetadata = new PacketPlayOutEntityMetadata(entity.getId(),entity.getDataWatcher(),false);
                        ((CraftPlayer)p).getHandle().playerConnection.sendPacket(entityMetadata);
                        Bukkit.getScheduler().runTaskLater(pl, ()->{
                            PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(entity.getId());
                            ((CraftPlayer) p).getHandle().playerConnection.sendPacket(destroy);
                        },5);
     
    #1 abandoncaptian, Jan 14, 2020
    Last edited: Jan 14, 2020
  2. You can’t make the head invisible. The “spaz” is caused by it spawning in and the box going into position. If you just spawn it, and leave it instead of destroying and respawning, it will be fine.
     
  3. Seems how I can't fix the spazzy behavior, I'm spawning the shulker once then going to teleport/move it to the new location every time the player looks at a new block.
    Code (Java):
    if(this.shuls.size() == slot)
                            spawnShulker(bl);
                        else{
                            PacketPlayOutEntity.PacketPlayOutRelEntityMove pack = new PacketPlayOutEntity.PacketPlayOutRelEntityMove(this.shuls.get(slot).getId(),
                                    (byte)(bl.getLocation().getX() + 0.5D), (byte)(bl.getLocation().getY()), (byte)(bl.getLocation().getZ() + 0.5D), true);
                            ((CraftPlayer)p).getHandle().playerConnection.sendPacket(pack);
                            //this.shuls.get(slot).setPositionRotation(bl.getLocation().getX() + 0.5D, bl.getLocation().getY(), bl.getLocation().getZ() + 0.5D, 0, 0);
                        }
     
  4. Qruet

    Qruet Previously Geekles

    Why are you using a Shulker? I think the problem starts with the entity you chose to use. If you're trying to create some kind of "block selection" or visualization of the sort that highlights blocks with a glow effect, use FallingBlock instead?
     
  5. got an example, I haven't messed with falling block entities much
     
  6. Qruet

    Qruet Previously Geekles

    Should be relatively self-explanatory. Similarily to how you're spawning the Shulker I would replace it with a FallingBlock instance, and that's just about it. Here's a short example to get you started if you really need it:
    Code (Java):
            FallingBlock block = world.spawnFallingBlock(location, Material.STONE.createBlockData());
            block.setGravity(false);
            block.setGlowing(true);
     
  7. 1 major issue, how to make it invisble
    The code i'm using now:
    Code (Java):
    IBlockData data = CraftMagicNumbers.getBlock(Material.ORANGE_WOOL).getBlockData();
                        EntityFallingBlock block = new EntityFallingBlock(
                                ((CraftWorld) bl.getWorld()).getHandle(),
                                bl.getX(),
                                bl.getY(),
                                bl.getZ(),
                                data);

                        block.setNoGravity(true);
                        block.getBukkitEntity().setGlowing(true);
                        block.setInvisible(true);
                        block.setFlag(5, true);

                        EntityPlayer ePlayer = ((CraftPlayer) p).getHandle();

                        PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(block, net.minecraft.server.v1_15_R1.Block.getCombinedId(data));
                        PacketPlayOutEntityMetadata metapacket = new PacketPlayOutEntityMetadata(block.getBukkitEntity().getEntityId(), block.getDataWatcher(), true);

                        block.getBukkitEntity().teleport(bl.getLocation().add(0.5, 0, 0.5));
                        PacketPlayOutEntityTeleport packetteleport = new PacketPlayOutEntityTeleport(block);

                        ePlayer.playerConnection.sendPacket(packet);
                        ePlayer.playerConnection.sendPacket(metapacket);
                        ePlayer.playerConnection.sendPacket(packetteleport);
     
    #7 abandoncaptian, Jan 16, 2020 at 7:17 AM
    Last edited: Jan 16, 2020 at 7:36 AM
  8. I found using a MagmaCube to be effective for this. I believe setting size 1 or 2 makes it the same size as a block, and it can be fully invisible and have the glowing effect.

    I have use them before for a project and it works well.
     
  9. yea i'm working with a magma cube now on size 2, but it makes the block not able to be interacted with
    Edit 1: So I'm using size 1 it looks nice too. with the entities with glow, I get this TERRIBLE white flash
     
    #9 abandoncaptian, Jan 16, 2020 at 7:53 AM
    Last edited: Jan 16, 2020 at 7:59 AM
  10. I’m not to sure about the flash, I never ran into that problem but I didn’t use packets when I did mine. Could be to do with your teleporting or a rendering issue. Do they flash when not inside a block?
     
  11. yes, they do. i can try it with actual slimes
     
  12. You could give it a go. I wont be of much use anymore here, so good luck with your endeavours.