コード例 #1
0
        public override void OnGroundIdle(EntityItem entityItem)
        {
            if (entityItem.World.Side == EnumAppSide.Client)
            {
                return;
            }
            if (entityItem.ShouldDespawn)
            {
                return;
            }

            if (TryPlace(entityItem, 0, 0, 0))
            {
                entityItem.Die(EnumDespawnReason.Removed, null);
                return;
            }
            if (TryPlace(entityItem, 0, 1, 0))
            {
                entityItem.Die(EnumDespawnReason.Removed, null);
                return;
            }
            if (TryPlace(entityItem, 0, -1, 0))
            {
                entityItem.Die(EnumDespawnReason.Removed, null);
                return;
            }

            if (!entityItem.CollidedVertically)
            {
                return;
            }

            List <BlockPos> offsetsList = new List <BlockPos>();

            for (int x = -1; x < 1; x++)
            {
                for (int y = -1; y < 1; y++)
                {
                    for (int z = -1; z < 1; z++)
                    {
                        offsetsList.Add(new BlockPos(x, y, z));
                    }
                }
            }

            BlockPos[] offsets = offsetsList.ToArray();
            offsets.Shuffle(entityItem.World.Rand);

            for (int i = 0; i < offsets.Length; i++)
            {
                if (TryPlace(entityItem, offsets[i].X, offsets[i].Y, offsets[i].Z))
                {
                    entityItem.Die(EnumDespawnReason.Removed, null);
                    return;
                }
            }
        }
コード例 #2
0
        public override void OnGroundIdle(EntityItem entityItem)
        {
            entityItem.Die(EnumDespawnReason.Removed);

            if (entityItem.World.Side == EnumAppSide.Server)
            {
                Vec3d pos = entityItem.ServerPos.XYZ;

                WaterTightContainableProps props = BlockLiquidContainerBase.GetContainableProps(entityItem.Itemstack);
                float litres = (float)entityItem.Itemstack.StackSize / props.ItemsPerLitre;

                entityItem.World.SpawnCubeParticles(pos, entityItem.Itemstack, 0.75f, Math.Min(100, (int)(2 * litres)), 0.45f);
                entityItem.World.PlaySoundAt(new AssetLocation("sounds/environment/smallsplash"), (float)pos.X, (float)pos.Y, (float)pos.Z, null);

                BlockEntityFarmland bef = api.World.BlockAccessor.GetBlockEntity(pos.AsBlockPos) as BlockEntityFarmland;
                if (bef != null)
                {
                    bef.WaterFarmland(Height.ToInt() / 6f, false);
                    bef.MarkDirty(true);
                }
            }



            base.OnGroundIdle(entityItem);
        }
コード例 #3
0
 public float ConsumeOnePortion()
 {
     entity.Itemstack.StackSize--;
     if (entity.Itemstack.StackSize <= 0)
     {
         entity.Die();
     }
     return(1f);
 }
コード例 #4
0
        public bool TryPlace(IBlockAccessor bA, BlockPos pos, EntityItem item)
        {
            Block rBlock = bA.GetBlock(pos);
            Block dBlock = bA.GetBlock(pos.DownCopy());

            if (rBlock.IsReplacableBy(this) && !dBlock.IsReplacableBy(this))
            {
                bA.SetBlock(BlockId, pos);
                item.Die(EnumDespawnReason.Removed, null);
                return(true);
            }
            return(false);
        }
コード例 #5
0
        public override void OnGroundIdle(EntityItem entityItem)
        {
            entityItem.Die(EnumDespawnReason.Removed);

            if (entityItem.World.Side == EnumAppSide.Server)
            {
                entityItem.World.SpawnCubeParticles(entityItem.SidedPos.XYZ, entityItem.Itemstack, 0.75f, 25 * entityItem.Itemstack.StackSize, 0.45f);
                entityItem.World.PlaySoundAt(new AssetLocation("sounds/environment/smallsplash"), (float)entityItem.SidedPos.X, (float)entityItem.SidedPos.Y, (float)entityItem.SidedPos.Z, null);
            }


            base.OnGroundIdle(entityItem);
        }
コード例 #6
0
        public override void OnGroundIdle(EntityItem entityItem)
        {
            entityItem.Die(EnumDespawnReason.Removed);

            if (entityItem.World.Side == EnumAppSide.Server)
            {
                WaterTightContainableProps props = BlockLiquidContainerBase.GetContainableProps(entityItem.Itemstack);
                float litres = (float)entityItem.Itemstack.StackSize / props.ItemsPerLitre;

                entityItem.World.SpawnCubeParticles(entityItem.SidedPos.XYZ, entityItem.Itemstack, 0.75f, (int)(litres * 2), 0.45f);
                entityItem.World.PlaySoundAt(new AssetLocation("sounds/environment/smallsplash"), (float)entityItem.SidedPos.X, (float)entityItem.SidedPos.Y, (float)entityItem.SidedPos.Z, null);
            }


            base.OnGroundIdle(entityItem);
        }