/// <summary> /// Gets a byte representing block direction based on the rotation /// of the entity that placed it. /// </summary> /// <param name="p">The entity whose rotation should be used.</param> /// <param name="Position">The position of the block being placed.</param> /// <param name="invert">If set to <c>true</c>, the direction is inverted.</param> /// <returns></returns> /// <remarks></remarks> public static byte DirectionByRotation(PlayerEntity p, Vector3 Position, bool invert = false) { double d = Math.Asin(((p.Location.Y + 0.5) - Position.Y) / Position.DistanceTo(p.Location + new Vector3(0, 0.5, 0))); if (d > (Math.PI / 4)) return invert ? (byte)1 : (byte)0; if (d < -(Math.PI / 4)) return invert ? (byte)0 : (byte)1; return DirectionByRotationFlat(p, invert); }
public override void PlayerUseItem(World world, PlayerEntity player, Vector3 location, Vector3 targetBlock, byte facing) { if (world.GetBlock(targetBlock) is SoulSandBlock) { NetherWartBlock b = new NetherWartBlock(); if (b.BlockPlaced(world, location, targetBlock, facing, player)) world.SetBlock(location, b); } }
/// <summary> /// DoorBlock placing /// </summary> /// <param name="facing"></param> /// <param name="placer"></param> public DoorBlock(byte facing, PlayerEntity placer) { facing = MathHelper.DirectionByRotationFlat(placer); switch ((Directions)facing) { case Directions.East: facing = (byte)Doors.NorthWest; break; case Directions.West: facing = (byte)Doors.SouthEast; break; case Directions.North: facing = (byte)Doors.SouthWest; break; case Directions.South: facing = (byte)Doors.NorthEast; break; } Metadata = facing; }
public override void PlayerUseItem(World world, PlayerEntity player, Vector3 location, Vector3 targetBlock, byte facing) { FireBlock b = new FireBlock(); if (b.BlockPlaced(world, location, targetBlock, facing, player)) world.SetBlock(location, b); }
public virtual void PlayerUseItem(World world, PlayerEntity player, Vector3 location, Vector3 targetBlock, byte facing) { }
public override void PlayerUseItem(World world, PlayerEntity player, Vector3 location, Vector3 targetBlock, byte facing) { Block b = world.GetBlock(targetBlock); if (b is DirtBlock || b is GrassBlock) world.SetBlock(targetBlock, new FarmlandBlock()); }
/// <summary> /// Doorblock constructor allowing specification of top /// </summary> /// <param name="facing">The direction</param> /// <param name="Top">The top of the door</param> /// <param name="placer">Who placed the block</param> public DoorBlock(byte facing, bool Top, PlayerEntity placer) : this(facing,placer) { Metadata |= Top ? (byte)Doors.TopHalf : (byte)0; }
public IronDoorBlock(byte facing, PlayerEntity placer) : base(facing, placer) { }
/// <summary> /// Sends a login packet /// </summary> /// <param name="user">The user.</param> /// <param name="protocolVersion">The protocol version.</param> /// <remarks></remarks> protected void SendLogin(User user, int protocolVersion) { lock (lockObject) { // Send login packet netStream.WriteByte((byte)PacketID.LoginRequest); WriteInt(netStream, protocolVersion); WriteString(netStream, user.UserName); WriteLong(netStream, 0); WriteString(netStream, ""); WriteInt(netStream, 0); netStream.WriteByte(0); netStream.WriteByte(0); netStream.WriteByte(0); netStream.WriteByte(0); netStream.Flush(); // Receive response PacketID response = (PacketID)netStream.ReadByte(); if (response == PacketID.Disconnect) { ForceDisconnect(); throw new Exception(ReadString(netStream)); } if (response != PacketID.LoginRequest) { string dump = ReadString(netStream); throw new Exception("Unrecognized response from server."); } Player = new PlayerEntity(); //World = new World(); //Player.ID = ReadInt(netStream); //ReadString(netStream); //World.Seed = ReadLong(netStream); //World.WorldGenerator = null; //World.Mode = (GameMode)ReadInt(netStream); //Player.Dimension = (Dimension)((sbyte)netStream.ReadByte()); //CurrentServer.Difficulty = (Difficulty)netStream.ReadByte(); //(byte)netStream.ReadByte(); CurrentServer.MaxPlayers = netStream.ReadByte(); netStream.Flush(); Player.Name = user.UserName; } }