Пример #1
0
    public override void OnUse(PlayerMob mob)
    {
        base.OnUse(mob);

        mob.ignoreMoveInput = true;
        mob.animator.Play(mob.anims.usePotion);
    }
Пример #2
0
        public void ParseGeometryTest()
        {
            string pluginDirectory = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
            string json            = File.ReadAllText(Path.Combine(pluginDirectory, "geometry.json"));

            var settings = new JsonSerializerSettings();

            settings.NullValueHandling     = NullValueHandling.Ignore;
            settings.DefaultValueHandling  = DefaultValueHandling.IgnoreAndPopulate;
            settings.MissingMemberHandling = MissingMemberHandling.Error;
            settings.Formatting            = Formatting.Indented;
            settings.ContractResolver      = new CamelCasePropertyNamesContractResolver();

            var fake = new PlayerMob(string.Empty, null);

            string newName = $"geometry.{DateTime.UtcNow.Ticks}.{new Random().NextDouble()}";

            json = json.Replace("geometry.humanoid.custom", newName);

            fake.Skin.GeometryName = newName;
            fake.Skin.GeometryData = json;

            GeometryModel geometryModel = JsonConvert.DeserializeObject <GeometryModel>(json, settings);

            var state = new Code4FunPlugin.GravityGeometryBehavior(fake, geometryModel);

            state.FakeMeltTicking(fake, new PlayerEventArgs(null));
        }
Пример #3
0
        public override void SpawnEntity()
        {
            NameTag           = string.Empty;
            Block.Coordinates = new BlockCoordinates(KnownPosition);
            TextEntity        = new PlayerMob(NameTag, Level)
            {
                NameTag = Text, KnownPosition = KnownPosition, Width = 0, IsInvisible = true, Gravity = 0, Height = 0, HideNameTag = false
            };

            if (Player != null)
            {
                TextEntity.SpawnToPlayers(new Player[] { Player });
            }

            if (BlockEntity == null)
            {
                if (Block is Air)
                {
                    base.SpawnEntity();
                    //TextEntity.EntityId = (EntityId + 1);
                    Level.EntityManager.AddEntity(null, TextEntity);
                    NpcEvents.Npcs.Add(EntityId, this);
                    return;
                }
                NpcEvents.Npcs.Add(EntityId, this);
                Level.SetBlock(Block);
            }
            Block = BlockEntity.GetBlock();
            NpcEvents.Npcs.Add(EntityId, this);
            BlockEntity.Coordinates = Block.Coordinates;
            Level.SetBlockEntity(BlockEntity);
            Level.SetBlock(Block);
        }
 public override void OnEndUse(PlayerMob mob)
 {
     if (mob.hasShieldUp)
     {
         mob.ignoreMoveInput = false;
         mob.hasShieldUp     = false;
     }
 }
Пример #5
0
    public void OnInteract(PlayerMob mob)
    {
        PlayerState.instance.inventoryStock.AddItem(items.ToArray());
        GameState.inGameMenu.SetItemGet(items.ToArray());

        GameState.player.EquipItem(items[0]);
        GameState.player.EquipItem(GameState.items.shield);

        Destroy(gameObject);
    }
Пример #6
0
        private void PlayerOnTicking(object sender, PlayerEventArgs playerEventArgs)
        {
            {
                var player = (PlayerMob)sender;
                if (player.Level.TickTime % 20 != 0)
                {
                    return;
                }
            }

            using var bmpScreenCapture = new Bitmap(2150, 1519);
            using (var g = Graphics.FromImage(bmpScreenCapture))
            {
                g.CopyFromScreen(1669, 90, 0, 0, bmpScreenCapture.Size, CopyPixelOperation.SourceCopy);
            }

            using var srcBitmap = new Bitmap(bmpScreenCapture, new Size((_width) * 62, (_height) * 62));
            foreach (var mobCoord in mobs)
            {
                Log.Debug($"Updating {mobCoord.Key.Item1}, {mobCoord.Key.Item2}");
                PlayerMob mob = mobCoord.Value;
                mob.AddToPlayerList();

                int offsetx = (mobCoord.Key.Item1) * 62;
                int offsety = (_height - mobCoord.Key.Item2 - 1) * 62;
                using Bitmap croppedImage = VideoCommand.CropImage(srcBitmap, new Rectangle(offsetx, offsety, 62, 62));
                using Bitmap textureImage = new Bitmap(64, 64);
                var gfx = Graphics.FromImage(textureImage);
                gfx.FillRectangle(Brushes.Black, new Rectangle(0, 0, 64, 64));
                gfx.DrawImageUnscaled(croppedImage, new Point(1, 1));
                var bytes = VideoCommand.BitmapToBytes(textureImage, true);
                //var stream = new MemoryStream();
                //textureImage.Save(stream, ImageFormat.MemoryBmp);
                //var bytes = stream.ToArray();

                string oldSkinId = mob.Skin.SkinId;
                var    skin      = (Skin)mob.Skin.Clone();
                //var skin = (Skin) mob.Skin;
                skin.Data   = bytes;
                skin.SkinId = "testing" + new Guid();
                mob.Skin    = skin;

                // Below update doesn't work properly for unknown reasons.

                //var updateSkin = McpePlayerSkin.CreateObject();
                //updateSkin.uuid = mob.ClientUuid;
                //updateSkin.oldSkinName = oldSkinId;
                //updateSkin.skinName = mob.Skin.SkinId;
                //updateSkin.skin = mob.Skin;
                //mob.Level.RelayBroadcast(updateSkin);

                mob.RemoveFromPlayerList();
            }
        }
Пример #7
0
        public void SpawnPlayers(Player player, int numberOfEntities = 100, BlockPos spawnPos = null)
        {
            var coordinates = player.KnownPosition;

            if (spawnPos != null)
            {
                if (spawnPos.XRelative)
                {
                    coordinates.X += spawnPos.X;
                }
                else
                {
                    coordinates.X = spawnPos.X;
                }

                if (spawnPos.YRelative)
                {
                    coordinates.Y += spawnPos.Y;
                }
                else
                {
                    coordinates.Y = spawnPos.Y;
                }

                if (spawnPos.ZRelative)
                {
                    coordinates.Z += spawnPos.Z;
                }
                else
                {
                    coordinates.Z = spawnPos.Z;
                }
            }

            int limit = (int)Math.Sqrt(numberOfEntities);

            for (int x = 0; x < limit; x++)
            {
                for (int z = 0; z < limit; z++)
                {
                    var entity = new PlayerMob($"TheGrey {z + (x * limit)}", player.Level)
                    {
                        NoAi             = true,
                        KnownPosition    = coordinates + new Vector3(x, 0, z),
                        IsAlwaysShowName = false,
                        HideNameTag      = false,
                    };
                    entity.SpawnEntity();
                    //Thread.Sleep(50);
                }
            }
        }
Пример #8
0
            public GravityGeometryBehavior(PlayerMob mob, GeometryModel currentModel)
            {
                Mob          = mob;
                CurrentModel = currentModel;
                var geometry = CurrentModel.CollapseToDerived(CurrentModel.FindGeometry(mob.Skin.GeometryName));

                geometry.Subdivide(true, false);

                SetVelocity(geometry, new Random());

                CurrentModel.Geometry.Clear();
                CurrentModel.Geometry.Add(geometry);
            }
Пример #9
0
        public override void HandleMcpePlayerList(McpePlayerList message)
        {
            if (message.records is PlayerAddRecords addRecords)
            {
                foreach (var r in addRecords)
                {
                    var u = new API.Utils.UUID(r.ClientUuid.GetBytes());
                    if (_players.ContainsKey(u))
                    {
                        continue;
                    }

                    Texture2D skinTexture;
                    if (r.Skin.TryGetBitmap(out Bitmap skinBitmap))
                    {
                        skinTexture =
                            TextureUtils.BitmapToTexture2D(BaseClient.WorldProvider.Alex.GraphicsDevice, skinBitmap);
                    }
                    else
                    {
                        BaseClient.WorldProvider.Alex.Resources.ResourcePack.TryGetBitmap("entity/alex", out Bitmap rawTexture);
                        skinTexture = TextureUtils.BitmapToTexture2D(BaseClient.WorldProvider.Alex.GraphicsDevice, rawTexture);
                    }

                    BaseClient.WorldReceiver?.AddPlayerListItem(new PlayerListItem(u, r.DisplayName, Gamemode.Survival, 0));
                    PlayerMob m = new PlayerMob(r.DisplayName, BaseClient.WorldReceiver as World, BaseClient, skinTexture, true);

                    if (!_players.TryAdd(u, m))
                    {
                        Log.Warn($"Duplicate player record! {r.ClientUuid}");
                    }
                }
            }
            else if (message.records is PlayerRemoveRecords removeRecords)
            {
                foreach (var r in removeRecords)
                {
                    var u = new UUID(r.ClientUuid.GetBytes());
                    if (_players.TryRemove(u, out var player))
                    {
                        BaseClient.WorldReceiver?.RemovePlayerListItem(u);
                        if (BaseClient.WorldReceiver is World w)
                        {
                            w.DespawnEntity(player.EntityId);
                        }
                    }
                }
            }
        }
Пример #10
0
        private void PlayerOnTicking(object sender, PlayerEventArgs playerEventArgs)
        {
            {
                var player = (PlayerMob)sender;
                if (player.Level.TickTime % 4 != 0)
                {
                    return;
                }
            }

            using (Bitmap bmpScreenCapture = new Bitmap(1118, 801))
            {
                using (Graphics g = Graphics.FromImage(bmpScreenCapture))
                {
                    g.CopyFromScreen(620, 101, 0, 0, bmpScreenCapture.Size, CopyPixelOperation.SourceCopy);
                }

                using (Bitmap srcBitmap = new Bitmap(bmpScreenCapture, new Size((_width) * 64, (_height) * 64)))
                {
                    foreach (var mobCoord in mobs)
                    {
                        PlayerMob mob = mobCoord.Value;
                        mob.AddToPlayerList();

                        int offsetx = (mobCoord.Key.Item1) * 64;
                        int offsety = (_height - mobCoord.Key.Item2 - 1) * 64;
                        using (Bitmap bitmap = NiceLobbyPlugin.CropImage(srcBitmap, new Rectangle(offsetx, offsety, 64, 64)))
                        {
                            var bytes = NiceLobbyPlugin.BitmapToBytes(bitmap, true);

                            var skin = mob.Skin;
                            skin.SkinData = bytes;

                            McpePlayerSkin updateSkin = McpePlayerSkin.CreateObject();
                            updateSkin.uuid          = mob.ClientUuid;
                            updateSkin.skinId        = skin.SkinId + new Guid();
                            updateSkin.skinData      = skin.SkinData;
                            updateSkin.capeData      = skin.CapeData;
                            updateSkin.geometryModel = skin.SkinGeometryName;
                            updateSkin.geometryData  = skin.SkinGeometry;
                            mob.Level.RelayBroadcast(updateSkin);
                        }

                        mob.RemoveFromPlayerList();
                    }
                }
            }
        }
Пример #11
0
 public override void OnHoldUse(PlayerMob mob)
 {
     if (CanUse(mob))
     {
         if (!mob.hasShieldUp)
         {
             mob.ignoreMoveInput = true;
             mob.hasShieldUp     = true;
             mob.animator.Play(mob.anims.defend);
         }
     }
     else
     {
         OnEndUse(mob);
     }
 }
Пример #12
0
        public void SpawnPlayer(Player player, string name)
        {
            string pluginDirectory = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            byte[] bytes = Skin.GetTextureFromFile(Path.Combine(pluginDirectory, "IMG_0220.png"));
            //byte[] bytes = Skin.GetTextureFromFile(Path.Combine(pluginDirectory, "Char8.png"));

            PlayerMob fake = new PlayerMob("§6§lBot: " + name + "", player.Level)
            {
                Skin = new Skin {
                    Slim = false, Texture = bytes
                }, KnownPosition = player.KnownPosition, ItemInHand = new ItemDiamondSword(), Helmet = 302, Chest = 303, Leggings = 304, Boots = 305,
            };

            fake.SpawnEntity();
        }
Пример #13
0
        public void SpawnFake(Player player, string name)
        {
            string pluginDirectory = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            //var bytes = Encoding.Default.GetBytes(new string('Z', 8192));
            //byte[] skinData = Skin.GetTextureFromFile(Path.Combine(pluginDirectory, "test_skin.png"));
            byte[] skinData   = Skin.GetTextureFromFile(Path.Combine(pluginDirectory, "IMG_0220.png"));
            string skinString = File.ReadAllText(Path.Combine(pluginDirectory, "geometry.json"));

            var    random  = new Random();
            string newName = $"geometry.{DateTime.UtcNow.Ticks}.{random.NextDouble()}";

            skinString = skinString.Replace("geometry.humanoid.custom", newName);
            GeometryModel geometryModel = Skin.Parse(skinString);

            PlayerLocation coordinates = player.KnownPosition;
            Vector3        direction   = Vector3.Normalize(player.KnownPosition.GetHeadDirection()) * 1.5f;

            var fake = new PlayerMob(string.Empty, player.Level)
            {
                KnownPosition = new PlayerLocation(coordinates.X + direction.X, coordinates.Y, coordinates.Z + direction.Z, 0, 0)
                                //KnownPosition = new PlayerLocation(coordinates.X + direction.X, coordinates.Y, coordinates.Z + direction.Z, coordinates.HeadYaw + 180f, coordinates.Yaw + 180f)
            };

            fake.Skin.Data = skinData;
            fake.Skin.SkinResourcePatch = new SkinResourcePatch()
            {
                Geometry = new GeometryIdentifier()
                {
                    Default = newName
                }
            };
            fake.Skin.GeometryName = newName;
            //fake.Skin.GeometryData = skinString;
            fake.Skin.GeometryData = Skin.ToJson(geometryModel);
            ;

            fake.SpawnEntity();

            fake.SetPosition(new PlayerLocation(coordinates.X + direction.X, coordinates.Y, coordinates.Z + direction.Z, 0, 0), true);

            var state = new GravityGeometryBehavior(fake, geometryModel);

            fake.Ticking += state.FakeMeltTicking;
        }
Пример #14
0
        public void SpawnFake(Player player, string name)
        {
            string pluginDirectory = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            //var bytes = Encoding.Default.GetBytes(new string('Z', 8192));
            byte[] bytes = Skin.GetTextureFromFile(Path.Combine(pluginDirectory, "test_skin.png"));
            //byte[] bytes = Skin.GetTextureFromFile(Path.Combine(pluginDirectory, "IMG_0220.png"));
            string skinString = File.ReadAllText(Path.Combine(pluginDirectory, "geometry.json"));

            var    random  = new Random();
            string newName = $"geometry.{DateTime.UtcNow.Ticks}.{random.NextDouble()}";

            skinString = skinString.Replace("geometry.humanoid", newName);
            GeometryModel geometryModel = Skin.Parse(skinString);

            var coordinates = player.KnownPosition;
            var direction   = Vector3.Normalize(player.KnownPosition.GetHeadDirection()) * 1.5f;

            PlayerMob fake = new PlayerMob(string.Empty, player.Level)
            {
                Skin = new Skin
                {
                    SkinId           = "testing",
                    Slim             = false,
                    SkinData         = bytes,
                    CapeData         = new byte[0],
                    SkinGeometryName = newName,
                    SkinGeometry     = skinString
                },
                KnownPosition = new PlayerLocation(coordinates.X + direction.X, coordinates.Y, coordinates.Z + direction.Z, 0, 0)
                                //KnownPosition = new PlayerLocation(coordinates.X + direction.X, coordinates.Y, coordinates.Z + direction.Z, coordinates.HeadYaw + 180f, coordinates.Yaw + 180f)
            };

            fake.SpawnEntity();

            fake.SetPosition(new PlayerLocation(coordinates.X + direction.X, coordinates.Y, coordinates.Z + direction.Z, 0, 0), true);

            GravityGeometryBehavior state = new GravityGeometryBehavior(fake, geometryModel);

            fake.Ticking += state.FakeMeltTicking;
        }
Пример #15
0
        public SkinEntry(LoadedSkin skin, PooledTexture2D texture2D, Action <SkinEntry> onDoubleClick)
        {
            Skin          = skin;
            OnDoubleClick = onDoubleClick;

            MinWidth  = 92;
            MaxWidth  = 92;
            MinHeight = 128;
            MaxHeight = 128;

            // AutoSizeMode = AutoSizeMode.GrowOnly;

            AddChild(
                new GuiTextElement()
            {
                Text = skin.Name, Margin = Thickness.Zero, Anchor = Alignment.TopCenter, Enabled = false
            });

            Margin = new Thickness(0, 8);
            Anchor = Alignment.FillY;
            // AutoSizeMode = AutoSizeMode.GrowAndShrink;
            // BackgroundOverlay = new GuiTexture2D(GuiTextures.OptionsBackground);

            var mob = new PlayerMob(skin.Name, null, null, texture2D);

            mob.ModelRenderer = new EntityModelRenderer(skin.Model, texture2D);

            ModelView = new GuiEntityModelView(mob) /*"geometry.humanoid.customSlim"*/
            {
                BackgroundOverlay = new Color(Color.Black, 0.15f),
                Background        = null,
                //   Margin = new Thickness(15, 15, 5, 40),

                Width  = 92,
                Height = 128,
                Anchor = Alignment.Fill,
            };

            AddChild(ModelView);
        }
Пример #16
0
        public void CommandSpawnMob(MiNET.Player player, string entityName, string mobName = "", string mobScale = "")
        {
            if (!(player is SkyPlayer skyPlayer) || !skyPlayer.PlayerGroup.IsAtLeast(PlayerGroup.Admin))
            {
                player.SendMessage("§c§l(!)§r §cYou do not have permission for this command.");
                return;
            }

            entityName = entityName.ToLower();
            entityName = entityName.Substring(0, 1).ToUpper() + entityName.Substring(1);

            if (!Enum.TryParse(entityName, out EntityType entityType))
            {
                player.SendMessage($"§c§l(!) §r§cUnknown EntityType '{entityName}'");
                return;
            }

            Level level = player.Level;

            Mob mob = null;

            switch (entityType)
            {
            case EntityType.Chicken:
                mob = new Chicken(level);
                break;

            case EntityType.Cow:
                mob = new Cow(level);
                break;

            case EntityType.Pig:
                mob = new Pig(level);
                break;

            case EntityType.Sheep:
                mob = new Sheep(level);
                break;

            case EntityType.Wolf:
                mob = new Wolf(level)
                {
                    Owner = player
                };
                break;

            case EntityType.Villager:
                mob = new Villager(level);
                break;

            case EntityType.MushroomCow:
                mob = new MushroomCow(level);
                break;

            case EntityType.Squid:
                mob = new Squid(level);
                break;

            case EntityType.Rabbit:
                mob = new Rabbit(level);
                break;

            case EntityType.Bat:
                mob = new Bat(level);
                break;

            case EntityType.IronGolem:
                mob = new IronGolem(level);
                break;

            case EntityType.SnowGolem:
                mob = new SnowGolem(level);
                break;

            case EntityType.Ocelot:
                mob = new Ocelot(level);
                break;

            case EntityType.Zombie:
                mob = new Zombie(level);
                break;

            case EntityType.Creeper:
                mob = new Creeper(level);
                break;

            case EntityType.Skeleton:
                mob = new Skeleton(level);
                break;

            case EntityType.Spider:
                mob = new Spider(level);
                break;

            case EntityType.ZombiePigman:
                mob = new ZombiePigman(level);
                break;

            case EntityType.Slime:
                mob = new MiNET.Entities.Hostile.Slime(level);
                break;

            case EntityType.Enderman:
                mob = new Enderman(level);
                break;

            case EntityType.Silverfish:
                mob = new Silverfish(level);
                break;

            case EntityType.CaveSpider:
                mob = new CaveSpider(level);
                break;

            case EntityType.Ghast:
                mob = new Ghast(level);
                break;

            case EntityType.MagmaCube:
                mob = new MagmaCube(level);
                break;

            case EntityType.Blaze:
                mob = new Blaze(level);
                break;

            case EntityType.ZombieVillager:
                mob = new ZombieVillager(level);
                break;

            case EntityType.Witch:
                mob = new Witch(level);
                break;

            case EntityType.Stray:
                mob = new Stray(level);
                break;

            case EntityType.Husk:
                mob = new Husk(level);
                break;

            case EntityType.WitherSkeleton:
                mob = new WitherSkeleton(level);
                break;

            case EntityType.Guardian:
                mob = new Guardian(level);
                break;

            case EntityType.ElderGuardian:
                mob = new ElderGuardian(level);
                break;

            case EntityType.Horse:
                mob = new Horse(level);
                break;

            case EntityType.PolarBear:
                mob = new PolarBear(level);
                break;

            case EntityType.Shulker:
                mob = new Shulker(level);
                break;

            case EntityType.Dragon:
                mob = new Dragon(level);
                break;

            case EntityType.SkeletonHorse:
                mob = new SkeletonHorse(level);
                break;

            case EntityType.Wither:
                mob = new Wither(level);
                break;

            case EntityType.Evoker:
                mob = new Evoker(level);
                break;

            case EntityType.Vindicator:
                mob = new Vindicator(level);
                break;

            case EntityType.Vex:
                mob = new Vex(level);
                break;

            case EntityType.Npc:
                mob = new PlayerMob("test", level);
                break;
            }

            if (!String.IsNullOrEmpty(mobName))
            {
                mob.NameTag          = mobName.Replace("&", "§");
                mob.HideNameTag      = false;
                mob.IsAlwaysShowName = true;
            }

            if (!String.IsNullOrEmpty(mobScale))
            {
                try
                {
                    mob.Scale = Double.Parse(mobScale);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }

            mob.KnownPosition = (PlayerLocation)player.KnownPosition.Clone();
            mob.SpawnEntity();

            player.SendMessage($"§e§l(!) §r§eSpawned new {entityType}");
        }
Пример #17
0
        public void Screenshot(Player player)
        {
            var coordinates = (BlockCoordinates)player.KnownPosition;

            BlockCoordinates direction = Vector3.Normalize(player.KnownPosition.GetHeadDirection()) * 1.5f;

            string pluginDirectory = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            //byte[] skinBytes = Encoding.ASCII.GetBytes(new string('Z', 64*64*4));
            byte[] skinBytes = Skin.GetTextureFromFile(Path.Combine(pluginDirectory, "test_skin.png"));
            Log.Warn($"Size {skinBytes.Length}");

            for (int x = 0; x < _width; x++)
            {
                for (int y = 0; y < _height; y++)
                {
                    var skinGeometryName = "geometry.flat." + Guid.NewGuid();
                    var model            = new GeometryModel()
                    {
                        FormatVersion = "1.12.0",
                        Geometry      = new List <Geometry>
                        {
                            new Geometry
                            {
                                Description = new Description
                                {
                                    Identifier          = skinGeometryName,
                                    TextureHeight       = 64,
                                    TextureWidth        = 64,
                                    VisibleBoundsHeight = 0,
                                    VisibleBoundsWidth  = 0,
                                    VisibleBoundsOffset = new int[3]
                                },
                                Name  = skinGeometryName,
                                Bones = new List <Bone>
                                {
                                    new Bone
                                    {
                                        Name  = BoneName.Body,
                                        Cubes = new List <Cube>()
                                        {
                                            new Cube
                                            {
                                                Origin = new float[3],
                                                //Size = new float[] {68.4f, 68.4f, 0.1f},
                                                Size = new float[] { 62, 62, 1 },
                                                Uv   = new float[2] {
                                                    0, 0
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        },
                    };


                    //string fileName = Path.GetTempPath() + "Geometry_" + Guid.NewGuid() + ".json";
                    //File.WriteAllText(fileName, Skin.ToJson(model));

                    var fake = new PlayerMob(string.Empty, player.Level)
                    {
                        Scale  = 1.1,
                        Width  = 0.01,
                        Length = 0.01,
                        Height = 0.01,
                        Skin   = new Skin
                        {
                            SkinId            = "testing" + new Guid(),
                            Slim              = false,
                            Height            = 64,
                            Width             = 64,
                            Data              = skinBytes,
                            GeometryName      = skinGeometryName,
                            GeometryData      = Skin.ToJson(model),
                            SkinResourcePatch = new SkinResourcePatch()
                            {
                                Geometry = new GeometryIdentifier()
                                {
                                    Default = skinGeometryName
                                }
                            }
                        },
                        KnownPosition = new PlayerLocation(coordinates.X + direction.X + (x * 4), coordinates.Y + (y * 4), coordinates.Z + direction.Z, 0, 0)
                    };
                    mobs.TryAdd(new Tuple <int, int>(x, y), fake);
                    fake.SpawnEntity();
                    //fake.AddToPlayerList();
                    //Thread.Sleep(500);
                }
            }
            mobs.First().Value.Ticking += PlayerOnTicking;
        }
Пример #18
0
        public GuiPlayerInventoryDialog(Player player, Inventory inventory) : base(inventory, GuiTextures.InventoryPlayerBackground, 176, 166)
        {
            Player = player;

            // Subscribe to events

            if (player != null)
            {
                var modelRenderer = player.ModelRenderer;

                var mob = new PlayerMob(player.Name, player.Level, player.Network, player.ModelRenderer.Texture)
                {
                    ModelRenderer = modelRenderer,
                };

                ContentContainer.AddChild(
                    _playerEntityModelView = new GuiEntityModelView(mob)
                {
                    Margin            = new Thickness(7, 25),
                    Width             = 49,
                    Height            = 70,
                    Anchor            = Alignment.TopLeft,
                    AutoSizeMode      = AutoSizeMode.None,
                    Background        = null,
                    BackgroundOverlay = null
                });
            }

            Color color = Color.Blue;

            foreach (var slot in AddSlots(8, 84, 9, 27, 9, 0x00))
            {
                //   slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(color, 0.5f);
                slot.Item = Inventory[slot.InventoryIndex];
            }

            color = Color.Aqua;
            foreach (var slot in AddSlots(8, 142, 9, 9, 0, 0))
            {
                // slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(color, 0.5f);
                slot.Item = Inventory[slot.InventoryIndex];
            }

            foreach (var slot in AddSlots(8, 8, 1, 4, 0, 120))
            {
                var  inventoryIndex = slot.InventoryIndex;
                Item item           = new ItemAir();

                switch (slot.InventoryIndex)
                {
                case 0:
                    item           = inventory.Helmet;
                    inventoryIndex = inventory.HelmetSlot;
                    break;

                case 1:
                    item           = inventory.Chestplate;
                    inventoryIndex = inventory.ChestSlot;
                    break;

                case 2:
                    item           = inventory.Leggings;
                    inventoryIndex = inventory.LeggingsSlot;
                    break;

                case 3:
                    item           = inventory.Boots;
                    inventoryIndex = inventory.BootsSlot;
                    break;
                }

                //  slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Red, 0.5f);
                slot.Item           = item;
                slot.InventoryIndex = inventoryIndex;
            }

            foreach (var slot in AddSlots(98, 18, 2, 4, 41, 0))
            {
                slot.Item = Inventory[slot.InventoryIndex];
                //  slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Purple, 0.5f);
            }

            CraftingOutput = AddSlot(154, 28, 45, 0);
            //  CraftingOutput.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Purple, 0.5f);

            /*var shieldSlot = new InventoryContainerItem()
             * {
             *  HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Orange, 0.5f),
             *  Anchor = Alignment.TopLeft,
             *  Margin =  new Thickness(61, 76),
             *  AutoSizeMode = AutoSizeMode.None,
             *  Item = Inventory[40],
             *  InventoryIndex = 40
             * };
             *
             * ContentContainer.AddChild(shieldSlot);*/
        }
Пример #19
0
        public override void UseItem(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords)
        {
            Log.WarnFormat("Player {0} trying to spawn Mob #{1}.", player.Username, Metadata);

            var coordinates = GetNewCoordinatesFromFace(blockCoordinates, face);

            Mob mob = null;

            EntityType type = (EntityType)Metadata;

            switch (type)
            {
            case EntityType.Chicken:
                mob = new Chicken(world);
                break;

            case EntityType.Cow:
                mob = new Cow(world);
                break;

            case EntityType.Pig:
                mob = new Pig(world);
                break;

            case EntityType.Sheep:
                mob = new Sheep(world);
                break;

            case EntityType.Wolf:
                mob = new Wolf(world)
                {
                    Owner = player
                };
                break;

            case EntityType.Villager:
                mob = new Villager(world);
                break;

            case EntityType.MushroomCow:
                mob = new MushroomCow(world);
                break;

            case EntityType.Squid:
                mob = new Squid(world);
                break;

            case EntityType.Rabbit:
                mob = new Rabbit(world);
                break;

            case EntityType.Bat:
                mob = new Bat(world);
                break;

            case EntityType.IronGolem:
                mob = new IronGolem(world);
                break;

            case EntityType.SnowGolem:
                mob = new SnowGolem(world);
                break;

            case EntityType.Ocelot:
                mob = new Ocelot(world);
                break;

            case EntityType.Zombie:
                mob = new Zombie(world);
                break;

            case EntityType.Creeper:
                mob = new Creeper(world);
                break;

            case EntityType.Skeleton:
                mob = new Skeleton(world);
                break;

            case EntityType.Spider:
                mob = new Spider(world);
                break;

            case EntityType.ZombiePigman:
                mob = new ZombiePigman(world);
                break;

            case EntityType.Slime:
                mob = new Slime(world);
                break;

            case EntityType.Enderman:
                mob = new Enderman(world);
                break;

            case EntityType.Silverfish:
                mob = new Silverfish(world);
                break;

            case EntityType.CaveSpider:
                mob = new CaveSpider(world);
                break;

            case EntityType.Ghast:
                mob = new Ghast(world);
                break;

            case EntityType.MagmaCube:
                mob = new MagmaCube(world);
                break;

            case EntityType.Blaze:
                mob = new Blaze(world);
                break;

            case EntityType.ZombieVillager:
                mob = new ZombieVillager(world);
                break;

            case EntityType.Witch:
                mob = new Witch(world);
                break;

            case EntityType.Stray:
                mob = new Stray(world);
                break;

            case EntityType.Husk:
                mob = new Husk(world);
                break;

            case EntityType.WitherSkeleton:
                mob = new WitherSkeleton(world);
                break;

            case EntityType.Guardian:
                mob = new Guardian(world);
                break;

            case EntityType.ElderGuardian:
                mob = new ElderGuardian(world);
                break;

            case EntityType.Horse:
                mob = new Horse(world);
                break;

            case EntityType.PolarBear:
                mob = new PolarBear(world);
                break;

            case EntityType.Shulker:
                mob = new Shulker(world);
                break;

            case EntityType.Dragon:
                mob = new Dragon(world);
                break;

            case EntityType.SkeletonHorse:
                mob = new SkeletonHorse(world);
                break;

            case EntityType.Wither:
                mob = new Mob(EntityType.Wither, world);
                break;

            case EntityType.Npc:
                mob = new PlayerMob("test", world);
                break;
            }

            if (mob == null)
            {
                return;
            }

            mob.KnownPosition = new PlayerLocation(coordinates.X, coordinates.Y, coordinates.Z);
            mob.SpawnEntity();

            Log.WarnFormat("Player {0} spawned Mob #{1}.", player.Username, Metadata);
        }
Пример #20
0
 public bool CanInteract(PlayerMob mob)
 {
     return(!mob.ignoreMoveInput && mob.isOnGround);
 }
Пример #21
0
 public override bool CanUse(PlayerMob mob)
 {
     return((mob.ignoreMoveInput == mob.hasShieldUp) && mob.isOnGround);
 }
Пример #22
0
        public void Screenshot(Player player)
        {
            var coordinates = player.KnownPosition;
            var direction   = Vector3.Normalize(player.KnownPosition.GetHeadDirection()) * 1.5f;

            string pluginDirectory = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            byte[] skinBytes = Skin.GetTextureFromFile(Path.Combine(pluginDirectory, "test_skin.png"));

            for (int x = 0; x < _width; x++)
            {
                for (int y = 0; y < _height; y++)
                {
                    var           skinGeometryName = "geometry.flat." + Guid.NewGuid();
                    GeometryModel model            = new GeometryModel()
                    {
                        {
                            skinGeometryName, new Geometry()
                            {
                                Name  = skinGeometryName,
                                Bones = new List <Bone>()
                                {
                                    new Bone()
                                    {
                                        Name  = BoneName.Body,
                                        Pivot = new float[3],
                                        Cubes = new List <Cube>()
                                        {
                                            new Cube()
                                            {
                                                Origin = new float[3],
                                                Size   = new float[] { 64, 64, 1f },
                                                Uv     = new float[] { 0, 0 }
                                            }
                                        }
                                    }
                                }
                            }
                        },
                    };

                    PlayerMob fake = new PlayerMob(string.Empty, player.Level)
                    {
                        Width  = 0.1,
                        Length = 0.1,
                        Height = 0.1,

                        Skin = new Skin
                        {
                            SkinId           = "testing" + new Guid(),
                            Slim             = false,
                            SkinData         = skinBytes,
                            CapeData         = new byte[0],
                            SkinGeometryName = skinGeometryName,
                            SkinGeometry     = Skin.ToJson(model),
                        },
                        KnownPosition = new PlayerLocation(coordinates.X + direction.X + (x * 4), coordinates.Y + (y * 4), coordinates.Z + direction.Z, 0, 0)
                    };
                    mobs.Add(new Tuple <int, int>(x, y), fake);
                    fake.SpawnEntity();
                }
            }
            mobs.First().Value.Ticking += PlayerOnTicking;
        }
Пример #23
0
        protected override void OnLoad(IRenderArgs args)
        {
            Skin skin = _playerProfileService?.CurrentProfile?.Skin;

            if (skin == null)
            {
                Alex.Resources.ResourcePack.TryGetBitmap("entity/alex", out var rawTexture);
                skin = new Skin()
                {
                    Slim    = true,
                    Texture = TextureUtils.BitmapToTexture2D(Alex.GraphicsDevice, rawTexture)
                };
            }

            var entity = new PlayerMob("", null, null, skin.Texture);

            entity.Inventory.IsPeInventory = true;
            entity.ShowItemInHand          = true;

            AddChild(_playerView =
                         new GuiEntityModelView(
                             entity /*new PlayerMob("", null, null, skin.Texture, skin.Slim)*/)                    /*"geometry.humanoid.customSlim"*/
            {
                BackgroundOverlay = new Color(Color.Black, 0.15f),

                Margin = new Thickness(15, 15, 5, 40),

                Width  = 92,
                Height = 128,

                Anchor = Alignment.BottomRight,
            });

            AddChild(new GuiButton("Switch user", LoginBtnPressed)
            {
                Anchor         = Alignment.BottomRight,
                Modern         = false,
                TranslationKey = "",
                Margin         = new Thickness(15, 15, 6, 15),
                Width          = 90,
                Enabled        = false
            });

            AutoResetEvent reset = new AutoResetEvent(false);

            Alex.UIThreadQueue.Enqueue(() =>
            {
                using (MemoryStream ms =
                           new MemoryStream(ResourceManager.ReadResource("Alex.Resources.GradientBlur.png")))
                {
                    BackgroundOverlay = (TextureSlice2D)GpuResourceManager.GetTexture2D(this, args.GraphicsDevice, ms);
                }

                BackgroundOverlay.RepeatMode = TextureRepeatMode.Stretch;
                reset.Set();
            });
            reset.WaitOne();
            reset.Dispose();

            BackgroundOverlay.Mask = new Color(Color.White, 0.5f);

            _splashText.Text    = SplashTexts.GetSplashText();
            Alex.IsMouseVisible = true;

            Alex.GameStateManager.AddState("serverlist", new MultiplayerServerSelectionState(_backgroundSkyBox));
            //Alex.GameStateManager.AddState("profileSelection", new ProfileSelectionState(_backgroundSkyBox));
        }
Пример #24
0
        public GuiPlayerInventoryDialog(Player player, Inventory inventory)
        {
            Player    = player;
            Inventory = inventory;

            // Subscribe to events

            _guiHotBarInventoryItems = new InventoryContainerItem[inventory?.SlotCount ?? 0];

            if (_guiHotBarInventoryItems.Length != 46)
            {
                throw new ArgumentOutOfRangeException(nameof(inventory), inventory?.SlotCount ?? 0, "Expected player inventory containing 46 slots.");
            }

            ContentContainer.Background = GuiTextures.InventoryPlayerBackground;
            ContentContainer.Width      = ContentContainer.MinWidth = ContentContainer.MaxWidth = 176;
            ContentContainer.Height     = ContentContainer.MinHeight = ContentContainer.MaxHeight = 166;

            SetFixedSize(176, 166);

            ContentContainer.AutoSizeMode = AutoSizeMode.None;

            AddChild(_debug = new GuiAutoUpdatingTextElement(() =>
            {
                if (base.GuiRenderer == null)
                {
                    return("");
                }

                var position = Mouse.GetState().Position;

                return($"Cursor: {position}");
            }, true)
            {
                Background = new Color(Color.Black, 0.35f),
                Anchor     = Alignment.TopCenter,
                Margin     = new Thickness(0, 0, 0, 200)
            });

            var texture = player.ModelRenderer.Texture;

            if (texture == null)
            {
            }

            var modelRenderer = player.ModelRenderer;
            var mob           = new PlayerMob(player.Name, player.Level, player.Network,
                                              player.ModelRenderer.Texture, true)
            {
                ModelRenderer = modelRenderer,
            };

            ContentContainer.AddChild(_playerEntityModelView =
                                          new GuiEntityModelView(mob)
            {
                Margin            = new Thickness(7, 25),
                Width             = 49,
                Height            = 70,
                Anchor            = Alignment.TopLeft,
                AutoSizeMode      = AutoSizeMode.None,
                Background        = null,
                BackgroundOverlay = null
            });

            int lx = 7, ly = 83;

            int   idx   = 9;
            Color color = Color.Blue;

            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 9; x++)
                {
                    var item = new InventoryContainerItem()
                    {
                        Item = Inventory[idx],
                        HighlightedBackground = new Microsoft.Xna.Framework.Color(color, 0.5f),
                        Anchor       = Alignment.TopLeft,
                        AutoSizeMode = AutoSizeMode.None,
                        //  Name = idx.ToString(),
                        Margin = new Thickness(lx, ly, 0, 0)
                    };

                    _guiHotBarInventoryItems[idx] = item;

                    ContentContainer.AddChild(item);
                    idx++;

                    lx += item.Width;
                }

                lx = 7;

                if (idx == 36)
                {
                    idx   = 0;
                    ly    = 141;
                    color = Color.GreenYellow;
                }
                else
                {
                    ly += _guiHotBarInventoryItems[idx - 1].Height;
                }
            }

            lx = 7;
            ly = 7;
            for (int i = 0; i < 4; i++)
            {
                var element = new InventoryContainerItem()
                {
                    HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Red, 0.5f),
                    Anchor       = Alignment.TopLeft,
                    Margin       = new Thickness(ly, lx),
                    AutoSizeMode = AutoSizeMode.None,
                    //Item = Inventory[]
                };

                ContentContainer.AddChild(element);

                ly += element.Height;
            }

            var shieldSlot = new InventoryContainerItem()
            {
                HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Orange, 0.5f),
                Anchor       = Alignment.TopLeft,
                Margin       = new Thickness(61, 76),
                AutoSizeMode = AutoSizeMode.None
            };

            ContentContainer.AddChild(shieldSlot);

            AddChild(TextOverlay = new GuiTextElement(true)
            {
                HasShadow    = true,
                Background   = new Color(Color.Black, 0.35f),
                Enabled      = false,
                FontStyle    = FontStyle.DropShadow,
                TextColor    = TextColor.Yellow,
                ClipToBounds = false,
                //BackgroundOverlay = new Color(Color.Black, 0.35f),
            });

            foreach (var child in ContentContainer.ChildElements.Where(x => x is InventoryContainerItem).Cast <InventoryContainerItem>())
            {
                child.CursorPressed += InventoryItemPressed;
                child.CursorEnter   += ChildOnCursorEnter;
                child.CursorLeave   += ChildOnCursorLeave;
            }
        }
Пример #25
0
 public override void OnAnimEvent(PlayerMob mob, int i)
 {
     mob.Heal(mob.maxHP * 0.3f);
     PlayerState.instance.inventoryStock.RemoveItem(this);
 }
Пример #26
0
 public void OnInteract(PlayerMob mob)
 {
     GameState.inGameMenu.onDialogueContinue += OnDialogueContinue;
     OnDialogueContinue(0);
 }
Пример #27
0
        public GuiPlayerInventoryDialog(Player player, Inventory inventory)
        {
            Player    = player;
            Inventory = inventory;

            // Subscribe to events

            _guiHotBarInventoryItems = new InventoryContainerItem[inventory?.SlotCount ?? 0];

            if (_guiHotBarInventoryItems.Length != 46)
            {
                throw new ArgumentOutOfRangeException(nameof(inventory), inventory?.SlotCount ?? 0, "Expected player inventory containing 46 slots.");
            }

            ContentContainer.Background        = GuiTextures.InventoryPlayerBackground;
            ContentContainer.BackgroundOverlay = null;

            ContentContainer.Width  = ContentContainer.MinWidth = ContentContainer.MaxWidth = 176;
            ContentContainer.Height = ContentContainer.MinHeight = ContentContainer.MaxHeight = 166;

            SetFixedSize(176, 166);

            ContentContainer.AutoSizeMode = AutoSizeMode.None;

            var modelRenderer = player.ModelRenderer;
            var mob           = new PlayerMob(player.Name, player.Level, player.Network,
                                              player.ModelRenderer.Texture)
            {
                ModelRenderer = modelRenderer,
            };

            ContentContainer.AddChild(_playerEntityModelView =
                                          new GuiEntityModelView(mob)
            {
                Margin            = new Thickness(7, 25),
                Width             = 49,
                Height            = 70,
                Anchor            = Alignment.TopLeft,
                AutoSizeMode      = AutoSizeMode.None,
                Background        = null,
                BackgroundOverlay = null
            });

            Color color = Color.Blue;

            foreach (var slot in AddSlots(8, 84, 9, 27, 9, 0x00))
            {
                //   slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(color, 0.5f);
                slot.Item = Inventory[slot.InventoryIndex];
            }

            color = Color.Aqua;
            foreach (var slot in AddSlots(8, 142, 9, 9, 0, 0))
            {
                // slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(color, 0.5f);
                slot.Item = Inventory[slot.InventoryIndex];
            }

            foreach (var slot in AddSlots(8, 8, 1, 4, 0, 120))
            {
                var  inventoryIndex = slot.InventoryIndex;
                Item item           = new ItemAir();

                switch (slot.InventoryIndex)
                {
                case 0:
                    item           = Inventory.Helmet;
                    inventoryIndex = Inventory.HelmetSlot;
                    break;

                case 1:
                    item           = Inventory.Chestplate;
                    inventoryIndex = Inventory.ChestSlot;
                    break;

                case 2:
                    item           = Inventory.Leggings;
                    inventoryIndex = Inventory.LeggingsSlot;
                    break;

                case 3:
                    item           = Inventory.Boots;
                    inventoryIndex = Inventory.BootsSlot;
                    break;
                }

                //  slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Red, 0.5f);
                slot.Item           = item;
                slot.InventoryIndex = inventoryIndex;
            }

            foreach (var slot in AddSlots(98, 18, 2, 4, 41, 0))
            {
                slot.Item = Inventory[slot.InventoryIndex];
                //  slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Purple, 0.5f);
            }

            CraftingOutput = AddSlot(154, 28, 45, 0);
            //  CraftingOutput.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Purple, 0.5f);

            /*var shieldSlot = new InventoryContainerItem()
             * {
             *  HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Orange, 0.5f),
             *  Anchor = Alignment.TopLeft,
             *  Margin =  new Thickness(61, 76),
             *  AutoSizeMode = AutoSizeMode.None,
             *  Item = Inventory[40],
             *  InventoryIndex = 40
             * };
             *
             * ContentContainer.AddChild(shieldSlot);*/
        }
Пример #28
0
 public virtual bool CanUse(PlayerMob mob)
 {
     return(!mob.ignoreMoveInput && mob.isOnGround);
 }
Пример #29
0
        public void Summon(Player player, EntityTypeEnum entityType, bool noAi = true, BlockPos spawnPos = null)
        {
            EntityType petType;

            try
            {
                petType = (EntityType)Enum.Parse(typeof(EntityType), entityType.Value, true);
            }
            catch (ArgumentException e)
            {
                return;
            }

            if (!Enum.IsDefined(typeof(EntityType), petType))
            {
                player.SendMessage("No entity found");
                return;
            }

            var coordinates = player.KnownPosition;

            if (spawnPos != null)
            {
                if (spawnPos.XRelative)
                {
                    coordinates.X += spawnPos.X;
                }
                else
                {
                    coordinates.X = spawnPos.X;
                }

                if (spawnPos.YRelative)
                {
                    coordinates.Y += spawnPos.Y;
                }
                else
                {
                    coordinates.Y = spawnPos.Y;
                }

                if (spawnPos.ZRelative)
                {
                    coordinates.Z += spawnPos.Z;
                }
                else
                {
                    coordinates.Z = spawnPos.Z;
                }
            }

            var world = player.Level;

            Mob    mob    = null;
            Entity entity = null;

            EntityType type = (EntityType)(int)petType;

            switch (type)
            {
            case EntityType.Chicken:
                mob = new Chicken(world);
                break;

            case EntityType.Cow:
                mob = new Cow(world);
                break;

            case EntityType.Pig:
                mob = new Pig(world);
                break;

            case EntityType.Sheep:
                mob = new Sheep(world);
                break;

            case EntityType.Wolf:
                mob = new Wolf(world)
                {
                    Owner = player
                };
                break;

            case EntityType.Villager:
                mob = new Villager(world);
                break;

            case EntityType.MushroomCow:
                mob = new MushroomCow(world);
                break;

            case EntityType.Squid:
                mob = new Squid(world);
                break;

            case EntityType.Rabbit:
                mob = new Rabbit(world);
                break;

            case EntityType.Bat:
                mob = new Bat(world);
                break;

            case EntityType.IronGolem:
                mob = new IronGolem(world);
                break;

            case EntityType.SnowGolem:
                mob = new SnowGolem(world);
                break;

            case EntityType.Ocelot:
                mob = new Ocelot(world);
                break;

            case EntityType.Zombie:
                mob = new Zombie(world);
                break;

            case EntityType.Creeper:
                mob = new Creeper(world);
                break;

            case EntityType.Skeleton:
                mob = new Skeleton(world);
                break;

            case EntityType.Spider:
                mob = new Spider(world);
                break;

            case EntityType.ZombiePigman:
                mob = new ZombiePigman(world);
                break;

            case EntityType.Slime:
                mob = new Slime(world);
                break;

            case EntityType.Enderman:
                mob = new Enderman(world);
                break;

            case EntityType.Silverfish:
                mob = new Silverfish(world);
                break;

            case EntityType.CaveSpider:
                mob = new CaveSpider(world);
                break;

            case EntityType.Ghast:
                mob = new Ghast(world);
                break;

            case EntityType.MagmaCube:
                mob = new MagmaCube(world);
                break;

            case EntityType.Blaze:
                mob = new Blaze(world);
                break;

            case EntityType.ZombieVillager:
                mob = new ZombieVillager(world);
                break;

            case EntityType.Witch:
                mob = new Witch(world);
                break;

            case EntityType.Stray:
                mob = new Stray(world);
                break;

            case EntityType.Husk:
                mob = new Husk(world);
                break;

            case EntityType.WitherSkeleton:
                mob = new WitherSkeleton(world);
                break;

            case EntityType.Guardian:
                mob = new Guardian(world);
                break;

            case EntityType.ElderGuardian:
                mob = new ElderGuardian(world);
                break;

            case EntityType.Horse:
                var random = new Random();
                mob = new Horse(world, random.NextDouble() < 0.10, random);
                break;

            case EntityType.PolarBear:
                mob = new PolarBear(world);
                break;

            case EntityType.Shulker:
                mob = new Shulker(world);
                break;

            case EntityType.Dragon:
                mob = new Dragon(world);
                break;

            case EntityType.SkeletonHorse:
                mob = new SkeletonHorse(world);
                break;

            case EntityType.Wither:
                mob = new Wither(world);
                break;

            case EntityType.Evoker:
                mob = new Evoker(world);
                break;

            case EntityType.Vindicator:
                mob = new Vindicator(world);
                break;

            case EntityType.Vex:
                mob = new Vex(world);
                break;

            case EntityType.Npc:
                if (Config.GetProperty("EnableEdu", false))
                {
                    mob = new Npc(world);
                }
                else
                {
                    mob = new PlayerMob("test", world);
                }
                break;

            case EntityType.Boat:
                entity = new Boat(world);
                break;
            }

            if (mob != null)
            {
                mob.NoAi = noAi;
                var direction = Vector3.Normalize(player.KnownPosition.GetHeadDirection()) * 1.5f;
                mob.KnownPosition = new PlayerLocation(coordinates.X + direction.X, coordinates.Y, coordinates.Z + direction.Z, coordinates.HeadYaw, coordinates.Yaw);
                mob.SpawnEntity();
            }
            else if (entity != null)
            {
                entity.NoAi = noAi;
                var direction = Vector3.Normalize(player.KnownPosition.GetHeadDirection()) * 1.5f;
                entity.KnownPosition = new PlayerLocation(coordinates.X + direction.X, coordinates.Y, coordinates.Z + direction.Z, coordinates.HeadYaw, coordinates.Yaw);
                entity.SpawnEntity();
            }
        }
Пример #30
0
            public void FakeMeltTicking(object sender, PlayerEventArgs playerEventArgs)
            {
                Log.Debug("Ticking ... ");

                PlayerMob mob = (PlayerMob)sender;

                //Log.Warn("Done. De-register tick.");
                //mob.Ticking -= FakeMeltTicking;
                //return;

                if (CurrentModel == null)
                {
                    return;
                }

                try
                {
                    bool stillMoving = false;
                    foreach (var geometry in CurrentModel.Values)
                    {
                        foreach (var bone in geometry.Bones)
                        {
                            if (bone.NeverRender)
                            {
                                continue;
                            }
                            if (bone.Cubes == null || bone.Cubes.Count == 0)
                            {
                                continue;
                            }

                            foreach (var cube in bone.Cubes)
                            {
                                if (cube.Origin[1] <= 0.05f && cube.Velocity.Y <= 0.01)
                                {
                                    cube.Origin[1] = 0f;
                                    cube.Velocity  = Vector3.Zero;
                                    continue;
                                }

                                stillMoving = true;

                                float x = cube.Origin[0];
                                float y = cube.Origin[1];
                                float z = cube.Origin[2];

                                cube.Origin    = new[] { x + cube.Velocity.X, Math.Max(0f, y + cube.Velocity.Y), z + cube.Velocity.Z };
                                cube.Velocity -= new Vector3(0, Gravity, 0);
                                cube.Velocity *= 1 - Drag;
                            }
                        }
                    }

                    if (!stillMoving)
                    {
                        Log.Warn("Done. De-register tick.");
                        mob.Ticking -= FakeMeltTicking;

                        // Reset?
                        if (ResetOnEnd)
                        {
                            Skin skin = mob.Skin;

                            McpePlayerSkin updateSkin = McpePlayerSkin.CreateObject();
                            updateSkin.NoBatch = true;
                            updateSkin.uuid    = mob.ClientUuid;
                            updateSkin.skin    = skin;
                            mob.Level.RelayBroadcast(updateSkin);
                        }
                    }
                    else
                    {
                        Skin skin     = mob.Skin;
                        var  geometry = CurrentModel.FindGeometry(skin.GeometryName);
                        geometry.Name = $"geometry.{DateTime.UtcNow.Ticks}.{mob.ClientUuid}";

                        CurrentModel.Clear();
                        CurrentModel.Add(geometry.Name, geometry);

                        skin.GeometryName = geometry.Name;

                        McpePlayerSkin updateSkin = McpePlayerSkin.CreateObject();
                        updateSkin.NoBatch = true;
                        updateSkin.uuid    = mob.ClientUuid;
                        updateSkin.skin    = skin;
                        mob.Level.RelayBroadcast(updateSkin);
                    }
                }
                catch (Exception e)
                {
                    mob.Ticking -= FakeMeltTicking;
                    Log.Error(e);
                }
            }