コード例 #1
0
        public EntityBlockFalling(Block block, BlockEntity blockEntity, BlockPos initialPos, AssetLocation fallSound, float impactDamageMul, bool canFallSideways, float dustIntensity)
        {
            this.impactDamageMul = impactDamageMul;
            this.fallSound       = fallSound;
            this.canFallSideways = canFallSideways;
            this.dustIntensity   = dustIntensity;

            WatchedAttributes.SetBool("canFallSideways", canFallSideways);
            WatchedAttributes.SetFloat("dustIntensity", dustIntensity);
            if (fallSound != null)
            {
                WatchedAttributes.SetString("fallSound", fallSound.ToShortString());
            }

            this.Code               = new AssetLocation("blockfalling");
            this.blockCode          = block.Code;
            this.removedBlockentity = blockEntity;
            this.initialPos         = initialPos.Copy(); // Must have a Copy() here!

            ServerPos.SetPos(initialPos);
            ServerPos.X += 0.5;
            ServerPos.Z += 0.5;

            Pos.SetFrom(ServerPos);
        }
コード例 #2
0
        public EntityStackedBlockFalling(Block block, BlockEntity blockEntity, BlockPos initialPos)
        {
            this.Code               = new AssetLocation("blockfalling");
            this.blockCode          = block.Code;
            this.removedBlockentity = blockEntity;
            this.initialPos         = initialPos;

            ServerPos.SetPos(initialPos);
            ServerPos.X += 0.5;
            ServerPos.Z += 0.5;

            Pos.SetFrom(ServerPos);
        }
コード例 #3
0
ファイル: EntityPlayer.cs プロジェクト: anegostudios/vsapi
        public override void TeleportToDouble(double x, double y, double z, Action onTeleported = null)
        {
            Teleporting = true;
            ICoreServerAPI sapi = this.World.Api as ICoreServerAPI;

            if (sapi != null)
            {
                sapi.WorldManager.LoadChunkColumnPriority((int)ServerPos.X / World.BlockAccessor.ChunkSize, (int)ServerPos.Z / World.BlockAccessor.ChunkSize, new ChunkLoadOptions()
                {
                    OnLoaded = () =>
                    {
                        Pos.SetPos(x, y, z);
                        ServerPos.SetPos(x, y, z);
                        PreviousServerPos.SetPos(-99, -99, -99);
                        PositionBeforeFalling.Set(x, y, z);
                        Pos.Motion.Set(0, 0, 0);
                        if (this is EntityPlayer)
                        {
                            sapi.Network.BroadcastEntityPacket(EntityId, 1, SerializerUtil.Serialize(ServerPos.XYZ));
                            IServerPlayer player          = this.Player as IServerPlayer;
                            int chunksize                 = World.BlockAccessor.ChunkSize;
                            player.CurrentChunkSentRadius = 0;

                            sapi.Event.RegisterCallback((bla) => {
                                if (player.ConnectionState == EnumClientState.Offline)
                                {
                                    return;
                                }

                                if (!sapi.WorldManager.HasChunk((int)x / chunksize, (int)y / chunksize, (int)z / chunksize, player))
                                {
                                    sapi.WorldManager.SendChunk((int)x / chunksize, (int)y / chunksize, (int)z / chunksize, player, false);
                                }

                                // Oherwise we get an endlessly looping exception spam and break the server
                                player.CurrentChunkSentRadius = 0;
                            }, 50);
                        }

                        WatchedAttributes.SetInt("positionVersionNumber", WatchedAttributes.GetInt("positionVersionNumber", 0) + 1);


                        onTeleported?.Invoke();

                        Teleporting = false;
                    },
                });
            }
        }