Beispiel #1
0
 public override void BlockUpdate(World world, Vector3 updatedBlock, Vector3 modifiedBlock)
 {
     if (!(world.GetBlock(updatedBlock + Vector3.Down) is FarmlandBlock))
     {
         var entity = new ItemEntity(updatedBlock + new Vector3(0.5), new ItemStack(new PumpkinSeedsItem()));
         entity.ApplyRandomVelocity();
         world.SetBlock(updatedBlock, new AirBlock());
         world.OnSpawnEntity(entity);
         return;
     }
     if (!world.UpdatePending(updatedBlock))
     {
         var possibleLocations = new List<Vector3>(new[]
         {
             updatedBlock + Vector3.Left, updatedBlock + Vector3.Right,
             updatedBlock + Vector3.Forwards, updatedBlock + Vector3.Backwards
         });
         bool found = false;
         for (int i = 0; i < possibleLocations.Count; i++)
         {
             if (world.GetBlock(possibleLocations[i]) is PumpkinBlock)
                 found = true;
         }
         if (!found)
             ScheduleGrowth(world, updatedBlock);
     }
     base.BlockUpdate(world, updatedBlock, modifiedBlock);
 }
Beispiel #2
0
 public override void BlockUpdate(World world, Vector3 updatedBlock, Vector3 modifiedBlock)
 {
     if (!(world.GetBlock(updatedBlock + Vector3.Down) is FarmlandBlock))
     {
         var entity = new ItemEntity(updatedBlock + new Vector3(0.5), new ItemStack(new PotatoItem()));
         entity.ApplyRandomVelocity();
         world.SetBlock(updatedBlock, new AirBlock());
         world.OnSpawnEntity(entity);
     }
     base.BlockUpdate(world, updatedBlock, modifiedBlock);
 }
Beispiel #3
0
 public override void BlockUpdate(World world, Vector3 updatedBlock, Vector3 modifiedBlock)
 {
     var below = world.GetBlock(updatedBlock + Vector3.Down);
     if (!(below is SandBlock || below is CactusBlock))
     {
         world.SetBlock(updatedBlock, new AirBlock());
         var entity = new ItemEntity(updatedBlock + new Vector3(0.5), new ItemStack(this));
         entity.ApplyRandomVelocity();
         world.OnSpawnEntity(entity);
     }
     base.BlockUpdate(world, updatedBlock, modifiedBlock);
 }
Beispiel #4
0
 public override void BlockUpdate(World world, Vector3 updatedBlock, Vector3 modifiedBlock)
 {
     var block = world.GetBlock(updatedBlock + Vector3.Down);
     if (!(block is SugarCaneBlock || block is DirtBlock || block is GrassBlock || block is SandBlock))
     {
         world.SetBlock(updatedBlock, new AirBlock());
         var entity = new ItemEntity(updatedBlock + new Vector3(0.5), new ItemStack(new SugarCanesItem()));
         entity.ApplyRandomVelocity();
         world.OnSpawnEntity(entity);
     }
     base.BlockUpdate(world, updatedBlock, modifiedBlock);
 }
Beispiel #5
0
        public override void UsedByEntity(World world, bool leftClick, LivingEntity usedBy)
        {
            var player = usedBy as PlayerEntity;

            if (!leftClick)
            {
                if (!Item.Empty)
                {
                    Orientation++;
                    OnPropertyChanged("Metadata");
                }
                else
                {
                    if (!player.SelectedItem.Empty)
                    {
                        var slot = player.SelectedItem;
                        Item = new ItemStack(slot.Id, 1, slot.Metadata, slot.Nbt);
                        if (player.GameMode != GameMode.Creative)
                        {
                            slot.Count--;
                            player.Inventory[player.SelectedSlot] = slot;
                        }
                    }
                }
            }
            else
            {
                world.OnDestroyEntity(this);
                if (player.GameMode != GameMode.Creative)
                {
                    var spawnPosition = Position + new Vector3(0.5);
                    switch (Direction)
                    {
                    case ItemFrameDirection.North: spawnPosition += Vector3.North; break;

                    case ItemFrameDirection.South: spawnPosition += Vector3.South; break;

                    case ItemFrameDirection.East:  spawnPosition += Vector3.East;  break;

                    case ItemFrameDirection.West:  spawnPosition += Vector3.West;  break;
                    }
                    var frame = new ItemEntity(spawnPosition, new ItemStack(new ItemFrameItem()));
                    var item  = new ItemEntity(spawnPosition, Item);
                    frame.ApplyRandomVelocity();
                    item.ApplyRandomVelocity();
                    world.OnSpawnEntity(frame);
                    world.OnSpawnEntity(item);
                }
            }
            base.UsedByEntity(world, leftClick, usedBy);
        }
Beispiel #6
0
        public override void UsedByEntity(World world, bool leftClick, LivingEntity usedBy)
        {
            if (leftClick)
            {
                world.OnDestroyEntity(this);
            }
            var  player = usedBy as PlayerEntity;
            bool drop   = true;

            if (player != null)
            {
                if (player.GameMode == GameMode.Creative)
                {
                    drop = false;
                }
            }
            if (drop)
            {
                var item = new ItemEntity(Center, new ItemStack(new PaintingItem()));
                item.ApplyRandomVelocity();
                world.OnSpawnEntity(item);
            }
        }
Beispiel #7
0
 public virtual void OnBlockMined(World world, Vector3 destroyedBlock, PlayerEntity player)
 {
     if (Hardness != -1)
     {
         var slot = player.Inventory[player.SelectedSlot];
         world.SetBlock(destroyedBlock, new AirBlock());
         if (CanHarvest(slot.AsItem() as ToolItem) && player.GameMode != GameMode.Creative)
         {
             ItemStack[] drops;
             bool spawnEntity = GetDrop(slot.AsItem() as ToolItem, out drops);
             if (spawnEntity)
             {
                 foreach (var drop in drops)
                 {
                     var entity = new ItemEntity(destroyedBlock + new Vector3(0.5), drop);
                     entity.ApplyRandomVelocity();
                     world.OnSpawnEntity(entity);
                 }
             }
         }
     }
 }
 public override void UsedByEntity(World world, bool leftClick, LivingEntity usedBy)
 {
     var player = usedBy as PlayerEntity;
     if (!leftClick)
     {
         if (!Item.Empty)
         {
             Orientation++;
             OnPropertyChanged("Metadata");
         }
         else
         {
             if (!player.SelectedItem.Empty)
             {
                 var slot = player.SelectedItem;
                 Item = new ItemStack(slot.Id, 1, slot.Metadata, slot.Nbt);
                 if (player.GameMode != GameMode.Creative)
                 {
                     slot.Count--;
                     player.Inventory[player.SelectedSlot] = slot;
                 }
             }
         }
     }
     else
     {
         world.OnDestroyEntity(this);
         if (player.GameMode != GameMode.Creative)
         {
             var spawnPosition = Position + new Vector3(0.5);
             switch (Direction)
             {
                 case ItemFrameDirection.North: spawnPosition += Vector3.North; break;
                 case ItemFrameDirection.South: spawnPosition += Vector3.South; break;
                 case ItemFrameDirection.East:  spawnPosition += Vector3.East;  break;
                 case ItemFrameDirection.West:  spawnPosition += Vector3.West;  break;
             }
             var frame = new ItemEntity(spawnPosition, new ItemStack(new ItemFrameItem()));
             var item = new ItemEntity(spawnPosition, Item);
             frame.ApplyRandomVelocity();
             item.ApplyRandomVelocity();
             world.OnSpawnEntity(frame);
             world.OnSpawnEntity(item);
         }
     }
     base.UsedByEntity(world, leftClick, usedBy);
 }
Beispiel #9
0
 public override void UsedByEntity(World world, bool leftClick, LivingEntity usedBy)
 {
     if (leftClick)
         world.OnDestroyEntity(this);
     var player = usedBy as PlayerEntity;
     bool drop = true;
     if (player != null)
     {
         if (player.GameMode == GameMode.Creative)
             drop = false;
     }
     if (drop)
     {
         var item = new ItemEntity(Center, new ItemStack(new PaintingItem()));
         item.ApplyRandomVelocity();
         world.OnSpawnEntity(item);
     }
 }