Fake Player To Interact with Block

Discussion in 'Spigot Plugin Development' started by Rusketh, Jun 10, 2018.

  1. I have spent the day trying to find a way to replicate a user placing/using an itemstack on a block.

    This is how far I have gotten, after trying so many different things today with out sucess.

    Code (Java):
    public class FakePlayer extends EntityPlayer {
       
        public static FakePlayer create(World world, String name) {
            return new FakePlayer( ((CraftWorld) world).getHandle(), new GameProfile(new UUID(0, 0), name));
        }
       
        public FakePlayer(WorldServer world, GameProfile name) {
            super(MinecraftServer.getServer(), world, name, new PlayerInteractManager(world));
        }
       
        public boolean interact(Block block, ItemStack item) {
            net.minecraft.server.v1_12_R1.ItemStack nsItem = CraftItemStack.asNMSCopy(item);
           
            BlockPosition pos = new BlockPosition(block.getX(), block.getY(), block.getZ());
           
            net.minecraft.server.v1_12_R1.Block nsblock = net.minecraft.server.v1_12_R1.Block.asBlock(nsItem.getItem());
           
            a(nsItem, EnumHand.MAIN_HAND);
           
            return nsblock.interact(world, pos, world.getType(pos), this, EnumHand.MAIN_HAND, EnumDirection.DOWN, 0, 0, 0);
        }
    }
    some people have said in other posts, I read this morning that this is kinda how they did it, but I have not found anything solid as of writing this post.

    Anyway, I am yet to get this to work, but my interact method returns true, so maybe i am missing a block update or something?

    Anybody able to advise?